Skip to content

Commit

Permalink
Merge pull request #422 from bearsunday/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
koriym authored Aug 31, 2023
2 parents 0f2e277 + 935490b commit 4bee375
Show file tree
Hide file tree
Showing 39 changed files with 181 additions and 110 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@
# Configure diff output for .php and .phar files.
*.php diff=php
*.phar -diff

# No show diffs
/vendor-bin/**/composer.lock binary
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor/
/vendor-bin/**/vendor/
/build/
/composer.lock
/.phpunit.result.cache
Expand All @@ -14,4 +15,4 @@
/demo/vendor
demo/.phpunit.result.cache
/.phpunit-cache/
/coverage.xml
/coverage.xml
34 changes: 16 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,7 @@
},
"require-dev": {
"phpunit/phpunit": "^9.5.10",
"doctrine/coding-standard": "^11.1",
"phpmd/phpmd": "^2.13",
"phpmetrics/phpmetrics": "^2.7",
"phpstan/phpstan": "^1.9",
"psalm/plugin-phpunit": "^0.18.4",
"squizlabs/php_codesniffer": "^3.5",
"vimeo/psalm": "^5.4",
"ray/rector-ray": "^1.0",
"rector/rector": "^0.14.8"
"bamarni/composer-bin-plugin": "^1.8"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -75,16 +67,16 @@
"bin/bear.compile.php"
],
"scripts": {
"test": ["./vendor/bin/phpunit -c ./phpunit.xml.dist"],
"test": ["phpunit"],
"tests": ["@cs", "@sa", "@test"],
"coverage": ["php -dzend_extension=xdebug.so -dxdebug.mode=coverage ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"],
"pcov": ["php -dextension=pcov.so -d pcov.enabled=1 ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage --coverage-clover=coverage.xml"],
"cs": ["./vendor/bin/phpcs"],
"cs-fix": ["./vendor/bin/phpcbf src tests"],
"clean": ["./vendor/bin/phpstan clear-result-cache", "./vendor/bin/psalm --clear-cache", "rm -rf tests/tmp/*.php"],
"sa": ["psalm --show-info=true", "./vendor/bin/phpstan analyse --no-ansi --no-progress -c phpstan.neon --memory-limit=-1"],
"metrics": ["./vendor/bin/phpmetrics --report-html=build/metrics --exclude=Exception --junit=build/junit.xml src"],
"phpmd": ["./vendor/bin/phpmd --exclude src/Annotation src text ./phpmd.xml"],
"coverage": ["php -dzend_extension=xdebug.so -dxdebug.mode=coverage phpunit --coverage-text --coverage-html=build/coverage"],
"pcov": ["php -dextension=pcov.so -d pcov.enabled=1 phpunit --coverage-text --coverage-html=build/coverage --coverage-clover=coverage.xml"],
"cs": ["phpcs"],
"cs-fix": ["phpcbf src tests"],
"clean": ["phpstan clear-result-cache", "psalm --clear-cache", "rm -rf tests/tmp/*.php"],
"sa": ["psalm --show-info=true", "phpstan analyse --no-ansi --no-progress -c phpstan.neon --memory-limit=-1"],
"metrics": ["phpmetrics --report-html=build/metrics --exclude=Exception --junit=build/junit.xml src"],
"phpmd": ["phpmd --exclude src/Annotation src text ./phpmd.xml"],
"build": ["@cs", "@sa", "@pcov", "@metrics"],
"compile": "./bin/bear.compile FakeVendor\\\\HelloWorld prod-app ./tests/Fake/fake-app",
"baseline": "phpstan analyse -configuration -c phpstan.neon --generate-baseline --memory-limit=-1 ;psalm --set-baseline=psalm-baseline.xml"
Expand All @@ -94,5 +86,11 @@
"bamarni/composer-bin-plugin": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": true
}
}
}
17 changes: 9 additions & 8 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor-bin/tools/vendor/vimeo/psalm/config.xsd
https://getpsalm.org/schema/config "
errorLevel="1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor-bin/tools/vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="src"/>
<directory name="src" />
<ignoreFiles>
<directory name="vendor"/>
<directory name="vendor" />
<file name="src/Compiler/Bootstrap.php"/>
</ignoreFiles>
</projectFiles>
Expand Down
2 changes: 1 addition & 1 deletion src-deprecated/Unlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function once(string $path) : bool
return true;
}
self::$unlinkedPath[] = $path;
$this->__invoke($path);
($this)($path);

return false;
}
Expand Down
14 changes: 6 additions & 8 deletions src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use BEAR\Package\Compiler\NewInstance;
use BEAR\Package\Provide\Error\NullPage;
use Composer\Autoload\ClassLoader;
use Ray\Di\InjectorInterface;
use RuntimeException;

use function assert;
Expand All @@ -40,7 +39,6 @@ final class Compiler
{
/** @var ArrayObject<int, string> */
private ArrayObject $classes;
private InjectorInterface $injector;
private Meta $appMeta;
private CompileDiScripts $compilerDiScripts;
private NewInstance $newInstance;
Expand All @@ -65,13 +63,13 @@ public function __construct(string $appName, private string $context, string $ap
$this->hookNullObjectClass($appDir);
$this->appMeta = new Meta($appName, $context, $appDir);
/** @psalm-suppress MixedAssignment (?) */
$this->injector = Injector::getInstance($appName, $context, $appDir);
$this->compilerDiScripts = new CompileDiScripts(new CompileClassMetaInfo(), $this->injector);
$this->newInstance = new NewInstance($this->injector);
$injector = Injector::getInstance($appName, $context, $appDir);
$this->compilerDiScripts = new CompileDiScripts(new CompileClassMetaInfo(), $injector);
$this->newInstance = new NewInstance($injector);
/** @var ArrayObject<int, string> $overWritten */
$overWritten = new ArrayObject();
$filePutContents = new FilePutContents($overWritten);
$fakeRun = new FakeRun($this->injector, $context, $this->appMeta);
$fakeRun = new FakeRun($injector, $context, $this->appMeta);
$this->dumpAutoload = new CompileAutoload($fakeRun, $filePutContents, $this->appMeta, $overWritten, $this->classes, $appDir, $context);
$this->compilePreload = new CompilePreload($fakeRun, $this->newInstance, $this->dumpAutoload, $filePutContents, $classes, $context);
$this->compilerObjectGraph = new CompileObjectGraph($filePutContents, $this->appMeta->logDir);
Expand Down Expand Up @@ -100,8 +98,8 @@ public function compile(): int
printf("Success: %d Failed: %d\n", $this->newInstance->getCompiled(), count($this->newInstance->getFailed()));
printf("Preload compile: %s\n", $this->dumpAutoload->getFileInfo($preload));
printf("Object graph diagram: %s\n", realpath($dot));
foreach ($this->newInstance->getFailed() as $depedencyIndex => $error) {
printf("UNBOUND: %s for %s \n", $error, $depedencyIndex);
foreach ($this->newInstance->getFailed() as $dependencyIndex => $error) {
printf("UNBOUND: %s for %s \n", $error, $dependencyIndex);
}

return $failed ? 1 : 0;
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/CompileAutoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ public function __invoke(): int
/** @var list<string> $classes */
$classes = (array) $this->classes;
$paths = $this->getPaths($classes);
$autolaod = $this->saveAutoloadFile($this->appMeta->appDir, $paths);
$autoload = $this->saveAutoloadFile($this->appMeta->appDir, $paths);
$start = $_SERVER['REQUEST_TIME_FLOAT'] ?? 0;
assert(is_float($start));
$time = number_format(microtime(true) - $start, 2);
$memory = number_format(memory_get_peak_usage() / (1024 * 1024), 3);
printf("Compilation (2/2) took %f seconds and used %fMB of memory\n", $time, $memory);
printf("autoload.php: %s\n", $this->getFileInfo($autolaod));
printf("autoload.php: %s\n", $this->getFileInfo($autoload));

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Context/ApiModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class ApiModule extends AbstractModule
{
/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected function configure(): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Context/CliModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class CliModule extends AbstractModule
{
/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected function configure(): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Context/HalModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class HalModule extends AbstractModule
{
/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected function configure(): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Context/ProdModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class ProdModule extends AbstractModule
{
/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected function configure(): void
{
Expand Down
6 changes: 3 additions & 3 deletions src/Injector/PackageInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ public static function getInstance(AbstractAppMeta $meta, string $context, Cache
return $injector;
}

public static function factory(AbstractAppMeta $meta, string $context, AbstractModule|null $overideModule = null): InjectorInterface
public static function factory(AbstractAppMeta $meta, string $context, AbstractModule|null $overrideModule = null): InjectorInterface
{
$scriptDir = $meta->tmpDir . '/di';
! is_dir($scriptDir) && ! @mkdir($scriptDir) && ! is_dir($scriptDir);
$module = (new Module())($meta, $context);

if ($overideModule instanceof AbstractModule) {
$module->override($overideModule);
if ($overrideModule instanceof AbstractModule) {
$module->override($overrideModule);
}

$injector = new RayInjector($module, $scriptDir);
Expand Down
4 changes: 2 additions & 2 deletions src/LazyModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use BEAR\AppMeta\AbstractAppMeta;
use BEAR\Package\Module\ResourceObjectModule;
use BEAR\Package\Module\ScriptinjectorModule;
use BEAR\Package\Module\ScriptInjectorModule;
use Ray\Compiler\LazyModuleInterface;
use Ray\Di\AbstractModule;

Expand All @@ -21,7 +21,7 @@ public function __construct(

public function __invoke(): AbstractModule
{
$module = new ScriptinjectorModule($this->scriptDir, (new Module())($this->appMeta, $this->context));
$module = new ScriptInjectorModule($this->scriptDir, (new Module())($this->appMeta, $this->context));
$module->install(new ResourceObjectModule($this->appMeta->getResourceListGenerator()));

return $module;
Expand Down
2 changes: 1 addition & 1 deletion src/Module/AppMetaModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(private AbstractAppMeta $appMeta, AbstractModule|nul
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected function configure(): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Module/ImportAppModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(array $importApps)
}

/**
* {@inheritdoc}
* {@inheritDoc}
*
* @throws NotFound
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Module/ImportSchemeCollectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function get(): SchemeCollectionInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Provides InjectorInterface
*/
class ScriptinjectorModule extends AbstractModule
class ScriptInjectorModule extends AbstractModule
{
public function __construct(
private string $scriptDir,
Expand All @@ -21,7 +21,7 @@ public function __construct(
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected function configure(): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/PackageModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class PackageModule extends AbstractModule
{
/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected function configure(): void
{
Expand Down
8 changes: 4 additions & 4 deletions src/Provide/Error/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ public function __construct(
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function handle(Exception $e, Request $request) // phpcs:ignore SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly.ReferencedGeneralException
{
$this->logger->__invoke($e, $request);
($this->logger)($e, $request);
$this->errorPage = $this->factory->newInstance($e, $request);

return $this;
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function transfer(): void
{
$this->responder->__invoke($this->errorPage ?? new NullPage(), []);
($this->responder)($this->errorPage ?? new NullPage(), []);
}
}
2 changes: 1 addition & 1 deletion src/Provide/Logger/MonologProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function get(): Logger
{
Expand Down
2 changes: 1 addition & 1 deletion src/Provide/Logger/PsrLoggerModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class PsrLoggerModule extends AbstractModule
{
/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected function configure(): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Provide/Representation/CreatedResourceInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function invoke(MethodInvocation $invocation)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Provide/Representation/CreatedResourceModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class CreatedResourceModule extends AbstractModule
{
/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected function configure(): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Provide/Representation/CreatedResourceRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function render(ResourceObject $ro)
{
Expand Down
Loading

0 comments on commit 4bee375

Please sign in to comment.