Skip to content

Commit

Permalink
Remove classtools in favour of composer
Browse files Browse the repository at this point in the history
  • Loading branch information
BenSampo committed Jan 31, 2022
1 parent 185f244 commit e36641c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 82 deletions.
136 changes: 68 additions & 68 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 9 additions & 8 deletions src/Commands/AbstractAnnotationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
8 changes: 2 additions & 6 deletions src/Commands/EnumAnnotateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit e36641c

Please sign in to comment.