diff --git a/composer.json b/composer.json index 7f3b3680..eb84f9b8 100644 --- a/composer.json +++ b/composer.json @@ -1,72 +1,72 @@ { - "name": "bensampo/laravel-enum", - "type": "library", - "description": "Simple, extensible and powerful enumeration implementation for Laravel.", - "keywords": [ - "bensampo", - "enum", - "laravel", - "package", - "validation" - ], - "homepage": "https://github.com/bensampo/laravel-enum", - "license": "MIT", - "authors": [ - { - "name": "Ben Sampson", - "homepage": "https://sampo.co.uk", - "role": "Developer" - } - ], - "require": { - "php": "^7.3|^8.0", - "hanneskod/classtools": "^1.2", - "illuminate/contracts": "^8.0", - "illuminate/support": "^8.0", - "laminas/laminas-code": "^3.4|^4.0", - "nikic/php-parser": "^4.10" + "name": "bensampo/laravel-enum", + "type": "library", + "description": "Simple, extensible and powerful enumeration implementation for Laravel.", + "keywords": [ + "bensampo", + "enum", + "laravel", + "package", + "validation" + ], + "homepage": "https://github.com/bensampo/laravel-enum", + "license": "MIT", + "authors": [ + { + "name": "Ben Sampson", + "homepage": "https://sampo.co.uk", + "role": "Developer" + } + ], + "require": { + "php": "^7.3|^8.0", + "composer/composer": "^2.2", + "illuminate/contracts": "^8.0", + "illuminate/support": "^8.0", + "laminas/laminas-code": "^3.4|^4.0", + "nikic/php-parser": "^4.10" + }, + "require-dev": { + "doctrine/dbal": "^2.9|^3.0", + "orchestra/testbench": "^6.2", + "mockery/mockery": "^1.4", + "phpstan/phpstan": "^0.12.59", + "phpunit/phpunit": "^8.5", + "squizlabs/php_codesniffer": "^3.0" + }, + "autoload": { + "psr-4": { + "BenSampo\\Enum\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "BenSampo\\Enum\\Tests\\": "tests" + } + }, + "scripts": { + "test": "phpunit", + "check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests", + "fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests" + }, + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" }, - "require-dev": { - "doctrine/dbal": "^2.9|^3.0", - "orchestra/testbench": "^6.2", - "mockery/mockery": "^1.4", - "phpstan/phpstan": "^0.12.59", - "phpunit/phpunit": "^8.5", - "squizlabs/php_codesniffer": "^3.0" + "laravel": { + "providers": [ + "BenSampo\\Enum\\EnumServiceProvider" + ] }, - "autoload": { - "psr-4": { - "BenSampo\\Enum\\": "src" - } - }, - "autoload-dev": { - "psr-4": { - "BenSampo\\Enum\\Tests\\": "tests" - } - }, - "scripts": { - "test": "phpunit", - "check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests", - "fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests" - }, - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - }, - "laravel": { - "providers": [ - "BenSampo\\Enum\\EnumServiceProvider" - ] - }, - "phpstan": { - "includes": [ - "extension.neon" - ] - } - }, - "config": { - "sort-packages": true - }, - "minimum-stability": "dev", - "prefer-stable" : true + "phpstan": { + "includes": [ + "extension.neon" + ] + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/src/Commands/AbstractAnnotationCommand.php b/src/Commands/AbstractAnnotationCommand.php index 90a1f592..e79432a4 100644 --- a/src/Commands/AbstractAnnotationCommand.php +++ b/src/Commands/AbstractAnnotationCommand.php @@ -6,17 +6,16 @@ use ReflectionClass; use InvalidArgumentException; use Illuminate\Console\Command; -use Symfony\Component\Finder\Finder; use Illuminate\Filesystem\Filesystem; +use Composer\Autoload\ClassMapGenerator; use Laminas\Code\Generator\DocBlockGenerator; use Laminas\Code\Reflection\DocBlockReflection; -use hanneskod\classtools\Iterator\ClassIterator; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; abstract class AbstractAnnotationCommand extends Command { - public const PARENT_CLASS = null; + public const PARENT_CLASS = ''; /** * @var \Illuminate\Filesystem\Filesystem @@ -73,11 +72,13 @@ public function handle() */ protected function annotateFolder() { - $classes = new ClassIterator($this->getClassFinder()); + $classMap = ClassMapGenerator::createMap($this->searchDirectory()); + + /** @var \ReflectionClass[] $classes */ + $classes = array_map(function ($class) { + return new ReflectionClass($class); + }, array_keys($classMap)); - $classes->enableAutoloading(); - - /** @var \ReflectionClass $reflection */ foreach ($classes as $reflection) { if ($reflection->isSubclassOf(static::PARENT_CLASS)) { $this->annotate($reflection); @@ -180,5 +181,5 @@ abstract protected function getDocblockTags(array $originalTags, ReflectionClass abstract protected function annotate(ReflectionClass $reflectionClass); - abstract protected function getClassFinder(): Finder; + abstract protected function searchDirectory(): string; } diff --git a/src/Commands/EnumAnnotateCommand.php b/src/Commands/EnumAnnotateCommand.php index bed46267..04bc9021 100644 --- a/src/Commands/EnumAnnotateCommand.php +++ b/src/Commands/EnumAnnotateCommand.php @@ -4,7 +4,6 @@ use ReflectionClass; use BenSampo\Enum\Enum; -use Symfony\Component\Finder\Finder; use Laminas\Code\Generator\DocBlockGenerator; use Laminas\Code\Reflection\DocBlockReflection; use Laminas\Code\Generator\DocBlock\Tag\MethodTag; @@ -64,11 +63,8 @@ protected function getDocblockTags(array $originalTags, ReflectionClass $reflect ->toArray(); } - protected function getClassFinder(): Finder + protected function searchDirectory(): string { - $finder = new Finder(); - $scanPath = $this->option('folder') ?? app_path(self::DEFAULT_SCAN_FOLDER); - - return $finder->files()->in($scanPath)->name('*.php'); + return $this->option('folder') ?? app_path(self::DEFAULT_SCAN_FOLDER); } }