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

Phpstan parser #12

Open
wants to merge 19 commits into
base: 2.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
229283b
Very early version of using PHPStan for parsing.
patrickkusebauch Mar 15, 2024
a25bf86
Refactor NikicPhpParser's FileReferenceVisitor to only deal with scop…
patrickkusebauch Mar 15, 2024
a66b325
One extractor per node type.
patrickkusebauch Mar 15, 2024
d43f98a
Refactoring tests to enable testing PHPStan implementation.
patrickkusebauch Mar 15, 2024
9495d3f
After repo-change reconciliation
patrickkusebauch Mar 15, 2024
70e9ec7
composer-dependency-analyser: improve config, update (#22)
janedbal Mar 20, 2024
ea83b1e
ClassLikeExtractor.php implementation and better scoping for test res…
patrickkusebauch Mar 28, 2024
b348387
Resolved all failing tests. Resolved proper static reflection for dis…
patrickkusebauch Mar 29, 2024
a67e92b
Tests for AstMapGeneratorTest
patrickkusebauch Mar 29, 2024
a312ba3
Refactor shared parser behavior.
patrickkusebauch Mar 29, 2024
1fc5686
Added feature flags and enabled phpstan parser for dog-food of deptrac.
patrickkusebauch Mar 29, 2024
dffb975
cs fixes
patrickkusebauch Mar 30, 2024
1a76dab
Configure GitHub action to e2e test both Nikic and PHPStan parsers.
patrickkusebauch Mar 30, 2024
79d2a70
Documentation
patrickkusebauch Mar 30, 2024
3684a49
An attempt at re-scoping PHPStan
patrickkusebauch Mar 30, 2024
017edfa
An attempt at re-scoping PHPStan
patrickkusebauch Mar 30, 2024
f7f8550
An attempt at re-scoping PHPStan
patrickkusebauch Mar 30, 2024
5c14482
Declaring PHPStan as a dependency of the resulting package.
patrickkusebauch Apr 5, 2024
f54deda
Declaring PHPStan as a dependency of the resulting package.
patrickkusebauch Apr 5, 2024
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
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ jobs:
matrix:
os: [ubuntu-22.04]
php-version: [8.1, 8.2, 8.3]
phpstan_parser: [true, false]

steps:
- name: "Checkout"
Expand Down Expand Up @@ -108,5 +109,15 @@ jobs:
- name: "Install dependencies with composer"
run: make composer-install

- name: Configure PhpStan Parser in 'deptrac.yaml'
if: matrix.phpstan_parser == 'false'
run: |
sed -i 's/phpstan_parser: true/phpstan_parser: false/' deptrac.yaml

- name: Configure PhpStan Parser in 'deptrac.config.php'
if: matrix.phpstan_parser == 'false'
run: |
sed -i 's/phpstanParser: true/phpstanParser: false/' deptrac.config.php

- name: "Run deptrac"
run: make deptrac
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ help: ## Displays list of available targets with their descriptions


.PHONY: build
build: tests ## Runs tests and creates the phar-binary
$(BOX_BIN) compile
build: composer-install ## Creates the phar-binary
$(BOX_BIN) compile --no-parallel

.PHONY: composer-install
composer-install: ## Installs dependencies
Expand Down
37 changes: 25 additions & 12 deletions baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.20.0@3f284e96c9d9be6fe6b15c79416e1d1903dcfef4">
<files psalm-version="5.23.0@005e3184fb6de4350a873b9b8c4dc3cede9db762">
<file src="src/Contract/Result/OutputResult.php">
<InvalidReturnStatement>
<code><![CDATA[array_key_exists($type, $this->rules) ? array_values($this->rules[$type]) : []]]></code>
Expand All @@ -10,19 +10,32 @@
</file>
<file src="src/Core/Ast/AstMap/ClassLike/ClassLikeToken.php">
<ArgumentTypeCoercion>
<code>$pattern</code>
<code><![CDATA[$pattern]]></code>
</ArgumentTypeCoercion>
</file>
<file src="src/Core/Ast/AstMap/Function/FunctionToken.php">
<ArgumentTypeCoercion>
<code>$pattern</code>
<code><![CDATA[$pattern]]></code>
</ArgumentTypeCoercion>
</file>
<file src="src/Core/Ast/Parser/TypeScope.php">
<file src="src/Core/Ast/Parser/Extractors/ClassMethodExtractor.php">
<RedundantCondition>
<code><![CDATA[$resolvedPhpDoc->getThrowsTag()?->getType()->getReferencedClasses()]]></code>
</RedundantCondition>
<TypeDoesNotContainNull>
<code><![CDATA[[]]]></code>
</TypeDoesNotContainNull>
</file>
<file src="src/Core/Ast/Parser/NikicPhpParser/TypeScope.php">
<RiskyTruthyFalsyComparison>
<code>$alias</code>
<code><![CDATA[$alias]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Core/Ast/Parser/PhpStanParser/PhpStanTypeResolver.php">
<NamedArgumentNotAllowed>
<code><![CDATA[array_map(static fn ($type): array => self::resolveType($type, $scope), $type->types)]]></code>
</NamedArgumentNotAllowed>
</file>
<file src="src/Core/Layer/Collector/BoolCollector.php">
<RiskyTruthyFalsyComparison>
<code><![CDATA[!$configuration['must']]]></code>
Expand All @@ -31,7 +44,7 @@
</file>
<file src="src/Core/Layer/Collector/ComposerFilesParser.php">
<InvalidReturnStatement>
<code>$lockedPackages</code>
<code><![CDATA[$lockedPackages]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[array<string, array{
Expand All @@ -42,32 +55,32 @@
</file>
<file src="src/Core/Layer/Collector/DirectoryCollector.php">
<ArgumentTypeCoercion>
<code>$validatedPattern</code>
<code><![CDATA[$validatedPattern]]></code>
</ArgumentTypeCoercion>
</file>
<file src="src/Core/Layer/Collector/GlobCollector.php">
<ArgumentTypeCoercion>
<code>$validatedPattern</code>
<code><![CDATA[$validatedPattern]]></code>
</ArgumentTypeCoercion>
</file>
<file src="src/Core/Layer/Collector/MethodCollector.php">
<ArgumentTypeCoercion>
<code>$pattern</code>
<code><![CDATA[$pattern]]></code>
</ArgumentTypeCoercion>
</file>
<file src="src/Core/Layer/Collector/RegexCollector.php">
<ArgumentTypeCoercion>
<code>$pattern</code>
<code><![CDATA[$pattern]]></code>
</ArgumentTypeCoercion>
</file>
<file src="src/Core/Layer/Collector/TagValueRegexCollector.php">
<ArgumentTypeCoercion>
<code>$pattern</code>
<code><![CDATA[$pattern]]></code>
</ArgumentTypeCoercion>
</file>
<file src="src/Supportive/Console/Command/DebugLayerRunner.php">
<RiskyTruthyFalsyComparison>
<code>$layer</code>
<code><![CDATA[$layer]]></code>
</RiskyTruthyFalsyComparison>
</file>
</files>
17 changes: 13 additions & 4 deletions bin/deptrac
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ if (PHP_VERSION_ID < 80100) {
include_once $autoload;
}
})();
(static function (): void {
if (\file_exists($autoload = __DIR__.'/../build/deptrac-build/phpstan/preload.php')) {
require_once $autoload;
}
})();
(static function (): void {
if (\file_exists($autoload = __DIR__.'/../build/deptrac-build/phpstan/vendor/autoload.php')) {
require_once $autoload;
}
})();

$xdebug = new XdebugHandler('DEPTRAC');
$xdebug->check();
unset($xdebug);
//$xdebug = new XdebugHandler('DEPTRAC');
//$xdebug->check();
//unset($xdebug);

(new Application())->run();

5 changes: 3 additions & 2 deletions box.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
],
"finder": [
{
"in": ["src", "vendor"],
"in": ["src", "vendor", "build"],
"notPath": "#jetbrains/phpstorm-stubs/.*/.*\\.php#",
"exclude": [
"examples",
"test",
"tests"
"tests",
"phpstan/phpstan"
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion build-deptrac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ info "Copy package templates"
cp -R $BUILD_DIR/template/* *.md mkdocs.yml docs -t $BUILD_TMP

info "Copy build into deptrac distrubtion repository"
cp -a $BUILD_TMP/. $DEPTRAC_DIR
cp -a $BUILD_TMP/. $DEPTRAC_DIR

# info "Git commit changes"
# echo "Update $(date)" > git_commit_message.txt
Expand Down
Empty file modified build/template/.gitignore
100644 → 100755
Empty file.
Empty file modified build/template/bootstrap.php
100644 → 100755
Empty file.
4 changes: 3 additions & 1 deletion build/template/composer.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"license": "MIT",
"require": {
"php": "^8.1",
"phpstan/phpstan": "^1.6.8",
"ext-json": "*"
},
"bin": [
Expand All @@ -18,7 +19,8 @@
"Qossmic\\Deptrac\\": "src/"
},
"files": [
"bootstrap.php"
"bootstrap.php",
"deptrac-build/phpstan/preload.php"
]
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"phpdocumentor/graphviz": "^2.1",
"phpdocumentor/type-resolver": "^1.6",
"phpstan/phpdoc-parser": "^1.5",
"phpstan/phpstan": "^1.6.8",
"psr/container": "^2.0",
"psr/event-dispatcher": "^1.0",
"symfony/config": "^6.0",
Expand Down Expand Up @@ -66,7 +67,6 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.4",
"infection/infection": "^0.26.16",
"phpstan/phpstan": "^1.6.8",
"phpstan/phpstan-symfony": "^1.1",
"phpunit/phpunit": "^10.2",
"rector/rector": "^0.15.17",
Expand Down
Loading
Loading