Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Psalm #321

Merged
merged 4 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:
- name: "Check cs"
run: make php-cs-check

static-code-analysis:
name: "Static Code Analysis"
static-code-analysis-phpstan:
name: "Static Code Analysis by PHPStan"

runs-on: ubuntu-latest

Expand Down Expand Up @@ -88,6 +88,50 @@ jobs:
- name: PHPStan
run: make phpstan

static-code-analysis-psalm:
name: "Static Code Analysis by Psalm"

runs-on: ubuntu-latest

steps:
- name: "Checkout"
uses: actions/checkout@v2

- name: "Cache tools installed with phive"
uses: actions/cache@v2
with:
path: |
~~/.phive
./tools
key: ${{ runner.os }}-phive-cache-${{ hashFiles('**/.phive/phars.xml') }}
restore-keys: |
phive-cache-

- name: "Cache dependencies installed with composer"
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: composer-cache-${{ hashFiles('**/composer.lock') }}
restore-keys: |
composer-cache-

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
extensions: mbstring, xml, ctype, iconv
coverage: none
tools: phive

- name: "Install tools with phive"
run: make tools-install

- name: "Install dependencies with composer"
run: composer install --no-interaction --no-progress --no-suggest --optimize-autoloader

- name: Psalm
run: make psalm

tests:
name: "PHP ${{ matrix.php-versions }} Test"

Expand Down
1 change: 1 addition & 0 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<phar name="php-cs-fixer" version="^2.16.3" installed="2.16.3" location="./tools/php-cs-fixer" copy="true"/>
<phar name="phpunit" version="^8.5.6" installed="8.5.6" location="./tools/phpunit" copy="true"/>
<phar name="phpstan" version="^0.12.29" installed="0.12.29" location="./tools/phpstan" copy="true"/>
<phar name="psalm" version="^3.12.2" installed="3.12.2" location="./tools/psalm" copy="true"/>
<phar name="humbug/box" version="^3.8.4" installed="3.8.4" location="./tools/box" copy="true"/>
</phive>
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PHP_BIN := php
PHIVE_BIN := phive
PHP_CS_FIXER_BIN := ./tools/php-cs-fixer
PHPSTAN_BIN := ./tools/phpstan
PSALM_BIN := ./tools/psalm
PHPUNIT_BIN := ./tools/phpunit

.PHONY: build tools-install composer-install tests tests-coverage gpg php-cs-check php-cs-fix phpstan
Expand Down Expand Up @@ -34,6 +35,9 @@ php-cs-fix: ## run cs fixer
phpstan:
$(PHPSTAN_BIN) analyse

psalm:
$(PSALM_BIN) analyse

gpg:
gpg --detach-sign --armor --output deptrac.phar.asc deptrac.phar
gpg --verify deptrac.phar.asc deptrac.phar
9 changes: 9 additions & 0 deletions baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="3.12.2@7c7ebd068f8acaba211d4a2c707c4ba90874fa26">
<file src="src/OutputFormatter/GraphVizOutputFormatter.php">
<InvalidScalarArgument occurrences="2">
<code>$layer</code>
<code>$layerDependOn</code>
</InvalidScalarArgument>
</file>
</files>
16 changes: 16 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<psalm
errorLevel="3"
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/vimeo/psalm/config.xsd"
errorBaseline="./baseline.xml"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
8 changes: 4 additions & 4 deletions src/AstRunner/AstParser/NikicPhpParser/NikicPhpParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ public function getAstForClassReference(AstClassReference $classReference): ?Nod
return self::$classAstMap[$classLikeName];
}

if (null === $classReference->getFileReference()) {
$astFileReference = $classReference->getFileReference();

if (null === $astFileReference) {
return null;
}

Expand All @@ -102,9 +104,7 @@ static function (Node $node): bool {
);

$this->traverser->addVisitor($findingVisitor);
$this->traverser->traverse(
$this->fileParser->parse(new \SplFileInfo($classReference->getFileReference()->getFilepath()))
);
$this->traverser->traverse($this->fileParser->parse(new \SplFileInfo($astFileReference->getFilepath())));
$this->traverser->removeVisitor($findingVisitor);

/** @var Node\Stmt\ClassLike[] $classLikeNodes */
Expand Down
13 changes: 8 additions & 5 deletions src/FileResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace SensioLabs\Deptrac;

use Iterator;
use SensioLabs\Deptrac\Configuration\Configuration;
use SplFileInfo;
use Symfony\Component\Finder\Finder;
Expand All @@ -24,11 +25,13 @@ public function resolve(Configuration $configuration): array
->ignoreVCS(true)
->notPath($configuration->getExcludeFiles());

$finder = new PathNameFilterIterator(
$finder->getIterator(),
[],
$configuration->getExcludeFiles()
);
$customFilterIterator = $finder->getIterator();

if (!$customFilterIterator instanceof Iterator) {
throw new \RuntimeException('unable to create an interator for the configured paths');
}

$finder = new PathNameFilterIterator($customFilterIterator, [], $configuration->getExcludeFiles());

return iterator_to_array($finder);
}
Expand Down