diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4b1dddff..ca07d6bf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -46,7 +46,7 @@ jobs: run: PHP_CS_FIXER_IGNORE_ENV=1 ./bin/php-cs-fixer fix --dry-run -v - name: Static Analysis - run: ./bin/psalm + run: ./bin/psalm.phar - name: Test run: ./bin/phpunit -d memory_limit=-1 --coverage-clover clover.xml diff --git a/.gitignore b/.gitignore index 87a73ec0..4e33d6de 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,9 @@ /web /bin/ !/bin/box.phar +!/bin/psalm.phar phparkitect.phar composer.lock .php-version composer.phar +.phpunit.cache/ \ No newline at end of file diff --git a/Makefile b/Makefile index 4246b65d..30928aea 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ csfix: ## it launches cs fix bin/php-cs-fixer fix -v psalm: ## it launches psalm - bin/psalm + bin/psalm.phar build: ## it launches all the build composer install diff --git a/bin/psalm.phar b/bin/psalm.phar new file mode 100755 index 00000000..24b9ae3e Binary files /dev/null and b/bin/psalm.phar differ diff --git a/composer.json b/composer.json index b449d82a..c4df5fb5 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,6 @@ "require-dev": { "roave/security-advisories": "dev-master", "symfony/var-dumper": "^3.0|^4.0|^5.0|^6.0|^7.0", - "vimeo/psalm": "^4.6", "phpunit/phpunit": "^7.5|^9.0|^10.0", "mikey179/vfsstream": "^1.6", "phpspec/prophecy": "^1.10", @@ -55,7 +54,8 @@ } }, "config": { - "bin-dir": "bin" + "bin-dir": "bin", + "sort-packages": true }, "bin": [ "bin-stub/phparkitect" diff --git a/phpunit.xml b/phpunit.xml index f388db62..f5bde5ef 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,21 +1,27 @@ - tests - - + + src - - + + diff --git a/psalm.xml b/psalm.xml index b6e24917..9c52fffc 100644 --- a/psalm.xml +++ b/psalm.xml @@ -4,7 +4,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" - + findUnusedCode="false" + findUnusedBaselineEntry="false" allowStringToStandInForClass="true" > diff --git a/src/Analyzer/ClassDescription.php b/src/Analyzer/ClassDescription.php index 2f61ff50..e11beeba 100644 --- a/src/Analyzer/ClassDescription.php +++ b/src/Analyzer/ClassDescription.php @@ -1,4 +1,5 @@ $interfaces * @param ?FullyQualifiedClassName $extends * @param list $attributes + * @param list $docBlock */ public function __construct( FullyQualifiedClassName $FQCN, diff --git a/src/Analyzer/FileVisitor.php b/src/Analyzer/FileVisitor.php index 35195586..1d0af495 100644 --- a/src/Analyzer/FileVisitor.php +++ b/src/Analyzer/FileVisitor.php @@ -1,4 +1,5 @@ implements as $interface) { $this->classDescriptionBuilder - ->addInterface($interface->toString(), $interface->getLine()); + ->addInterface($interface->toString(), $interface->getLine()); } if (!$node->isAnonymous() && null !== $node->extends) { @@ -76,7 +77,8 @@ public function enterNode(Node $node): void * * @see FileVisitorTest::test_it_should_return_errors_for_const_outside_namespace */ - if ($node instanceof Node\Expr\ClassConstFetch + if ( + $node instanceof Node\Expr\ClassConstFetch && method_exists($node->class, 'toString') ) { if ($this->isSelfOrStaticOrParent($node->class->toString())) { @@ -93,7 +95,8 @@ public function enterNode(Node $node): void * * @see FileVisitorTest::test_should_returns_all_dependencies */ - if ($node instanceof Node\Expr\StaticCall + if ( + $node instanceof Node\Expr\StaticCall && method_exists($node->class, 'toString') ) { if ($this->isSelfOrStaticOrParent($node->class->toString())) { @@ -104,7 +107,8 @@ public function enterNode(Node $node): void ->addDependency(new ClassDependency($node->class->toString(), $node->getLine())); } - if ($node instanceof Node\Expr\Instanceof_ + if ( + $node instanceof Node\Expr\Instanceof_ && method_exists($node->class, 'toString') ) { if ($this->isSelfOrStaticOrParent($node->class->toString())) { @@ -114,11 +118,13 @@ public function enterNode(Node $node): void ->addDependency(new ClassDependency($node->class->toString(), $node->getLine())); } - if ($node instanceof Node\Expr\New_ + if ( + $node instanceof Node\Expr\New_ && !($node->class instanceof Node\Expr\Variable) ) { - if ((method_exists($node->class, 'isAnonymous') && $node->class->isAnonymous()) - || !method_exists($node->class, 'toString')) { + if ((method_exists($node->class, 'isAnonymous') && true === $node->class->isAnonymous()) + || !method_exists($node->class, 'toString') + ) { return; } @@ -215,7 +221,7 @@ public function enterNode(Node $node): void $returnType = $node->returnType; if ($returnType instanceof Node\Name\FullyQualified) { $this->classDescriptionBuilder - ->addDependency(new ClassDependency($returnType->toString(), $returnType->getLine())); + ->addDependency(new ClassDependency($returnType->toString(), $returnType->getLine())); } } } @@ -271,7 +277,7 @@ private function addParamDependency(Node\Param $node): void $type = $nullableType->type; } - if (method_exists($type, 'isSpecialClassName') && $type->isSpecialClassName()) { + if (method_exists($type, 'isSpecialClassName') && true === $type->isSpecialClassName()) { return; } diff --git a/src/CLI/Command/Check.php b/src/CLI/Command/Check.php index 63534770..468b1808 100644 --- a/src/CLI/Command/Check.php +++ b/src/CLI/Command/Check.php @@ -97,11 +97,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $startTime = microtime(true); try { - $verbose = $input->getOption('verbose'); - $stopOnFailure = $input->getOption(self::STOP_ON_FAILURE_PARAM); - $useBaseline = $input->getOption(self::USE_BASELINE_PARAM); - $skipBaseline = $input->getOption(self::SKIP_BASELINE_PARAM); - $ignoreBaselineLinenumbers = $input->getOption(self::IGNORE_BASELINE_LINENUMBERS_PARAM); + $verbose = (bool) $input->getOption('verbose'); + $stopOnFailure = (bool) $input->getOption(self::STOP_ON_FAILURE_PARAM); + $useBaseline = (string) $input->getOption(self::USE_BASELINE_PARAM); + $skipBaseline = (bool) $input->getOption(self::SKIP_BASELINE_PARAM); + $ignoreBaselineLinenumbers = (bool) $input->getOption(self::IGNORE_BASELINE_LINENUMBERS_PARAM); if (true !== $skipBaseline && !$useBaseline && file_exists(self::DEFAULT_BASELINE_FILENAME)) { $useBaseline = self::DEFAULT_BASELINE_FILENAME; diff --git a/src/ClassSet.php b/src/ClassSet.php index 519a8953..d654c1c5 100644 --- a/src/ClassSet.php +++ b/src/ClassSet.php @@ -1,10 +1,14 @@ + */ class ClassSet implements \IteratorAggregate { /** @var string */ diff --git a/src/PHPUnit/ArchRuleCheckerConstraintAdapter.php b/src/PHPUnit/ArchRuleCheckerConstraintAdapter.php index fd468933..f143c125 100644 --- a/src/PHPUnit/ArchRuleCheckerConstraintAdapter.php +++ b/src/PHPUnit/ArchRuleCheckerConstraintAdapter.php @@ -1,4 +1,5 @@ runner->check( ClassSetRules::create($this->classSet, $other), new VoidProgress(), diff --git a/src/Rules/ParsingErrors.php b/src/Rules/ParsingErrors.php index 007ce001..bc475037 100644 --- a/src/Rules/ParsingErrors.php +++ b/src/Rules/ParsingErrors.php @@ -1,10 +1,14 @@ + */ class ParsingErrors implements \IteratorAggregate, \Countable { /** diff --git a/src/Rules/Violations.php b/src/Rules/Violations.php index 48c24879..add25ad4 100644 --- a/src/Rules/Violations.php +++ b/src/Rules/Violations.php @@ -7,12 +7,16 @@ use Arkitect\Exceptions\FailOnFirstViolationException; use Arkitect\Exceptions\IndexNotFoundException; +/** + * @template-implements \IteratorAggregate + */ class Violations implements \IteratorAggregate, \Countable, \JsonSerializable { /** * @var Violation[] */ private $violations; + /** * @var bool */