diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..0f00b56 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,31 @@ +name: PHPStan + +on: + push: + paths: + - '**.php' + - 'phpstan.neon.dist' + pull_request: + paths: + - '**.php' + - 'phpstan.neon.dist' + + +jobs: + phpstan: + name: phpstan + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + coverage: none + + - name: Install composer dependencies + uses: ramsey/composer-install@v2 + + - name: Run PHPStan + run: ./vendor/bin/phpstan --error-format=github diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml deleted file mode 100644 index a2c9a01..0000000 --- a/.github/workflows/psalm.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Psalm - -on: - push: - paths: - - '**.php' - - 'psalm.xml' - -jobs: - psalm: - name: psalm - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '8.2' - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick - coverage: none - - - name: Cache composer dependencies - uses: actions/cache@v3 - with: - path: vendor - key: composer-${{ hashFiles('composer.lock') }} - - - name: Run composer install - run: composer install -n --prefer-dist - - - name: Run psalm - run: ./vendor/bin/psalm -c psalm.xml diff --git a/composer.json b/composer.json index 390cb00..e147788 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,13 @@ ], "require": { "php": "^8.0", - "nikic/php-parser": "^4.13", + "nikic/php-parser": "^4.13|^5.0", "phpdocumentor/type-resolver": "^1.6.2", "symfony/process": "^5.2|^6.0|^7.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.40", + "phpstan/extension-installer": "^1.1", "larapack/dd": "^1.1", "myclabs/php-enum": "^1.7", "pestphp/pest": "^1.22", @@ -30,8 +31,7 @@ "spatie/data-transfer-object": "^2.0", "spatie/enum": "^3.0", "spatie/pest-plugin-snapshots": "^1.1", - "spatie/temporary-directory": "^1.2|^2.0", - "vimeo/psalm": "^4.2" + "spatie/temporary-directory": "^1.2|^2.0" }, "autoload": { "psr-4": { @@ -44,6 +44,7 @@ } }, "scripts": { + "analyse" : "vendor/bin/phpstan analyse", "test": "vendor/bin/pest", "test-coverage": "vendor/bin/pest --coverage", "psalm": "./vendor/bin/psalm -c psalm.xml", @@ -52,7 +53,8 @@ "config": { "sort-packages": true, "allow-plugins": { - "pestphp/pest-plugin": true + "pestphp/pest-plugin": true, + "phpstan/extension-installer": false } }, "minimum-stability": "dev", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..8eab4d3 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,46 @@ +parameters: + ignoreErrors: + - + message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(PhpParser\\\\Node\\)\\: mixed\\)\\|null, Closure\\(PhpParser\\\\Node\\\\Stmt\\\\Class_\\|PhpParser\\\\Node\\\\Stmt\\\\Enum_\\|PhpParser\\\\Node\\\\Stmt\\\\Interface_\\|PhpParser\\\\Node\\\\Stmt\\\\Trait_\\)\\: \\(string\\|null\\) given\\.$#" + count: 1 + path: src/Actions/ResolveClassesInPhpFileAction.php + + - + message: "#^Instanceof between phpDocumentor\\\\Reflection\\\\Type and phpDocumentor\\\\Reflection\\\\Types\\\\ClassString will always evaluate to false\\.$#" + count: 1 + path: src/Actions/TranspileTypeToTypeScriptAction.php + + - + message: "#^If condition is always true\\.$#" + count: 1 + path: src/Attributes/TypeScriptType.php + + - + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 1 + path: src/Attributes/TypeScriptType.php + + - + message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(ReflectionEnumUnitCase\\)\\: mixed\\)\\|null, Closure\\(ReflectionEnumBackedCase\\)\\: non\\-falsy\\-string given\\.$#" + count: 1 + path: src/Transformers/EnumTransformer.php + + - + message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(ReflectionEnumUnitCase\\)\\: mixed\\)\\|null, Closure\\(ReflectionEnumBackedCase\\)\\: string given\\.$#" + count: 1 + path: src/Transformers/EnumTransformer.php + + - + message: "#^Method Spatie\\\\TypeScriptTransformer\\\\TypeReflectors\\\\TypeReflector\\:\\:new\\(\\) should return static\\(Spatie\\\\TypeScriptTransformer\\\\TypeReflectors\\\\TypeReflector\\) but returns Spatie\\\\TypeScriptTransformer\\\\TypeReflectors\\\\MethodParameterTypeReflector\\.$#" + count: 1 + path: src/TypeReflectors/TypeReflector.php + + - + message: "#^Method Spatie\\\\TypeScriptTransformer\\\\TypeReflectors\\\\TypeReflector\\:\\:new\\(\\) should return static\\(Spatie\\\\TypeScriptTransformer\\\\TypeReflectors\\\\TypeReflector\\) but returns Spatie\\\\TypeScriptTransformer\\\\TypeReflectors\\\\MethodReturnTypeReflector\\.$#" + count: 1 + path: src/TypeReflectors/TypeReflector.php + + - + message: "#^Method Spatie\\\\TypeScriptTransformer\\\\TypeReflectors\\\\TypeReflector\\:\\:new\\(\\) should return static\\(Spatie\\\\TypeScriptTransformer\\\\TypeReflectors\\\\TypeReflector\\) but returns Spatie\\\\TypeScriptTransformer\\\\TypeReflectors\\\\PropertyTypeReflector\\.$#" + count: 1 + path: src/TypeReflectors/TypeReflector.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..3c8273f --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,7 @@ +parameters: + level: 5 + paths: + - src + tmpDir: build/phpstan + reportUnmatchedIgnoredErrors: true + checkMissingIterableValueType: true diff --git a/psalm.xml b/psalm.xml deleted file mode 100644 index 3e4e3d0..0000000 --- a/psalm.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - diff --git a/src/Actions/ResolveClassesInPhpFileAction.php b/src/Actions/ResolveClassesInPhpFileAction.php index 7dd7ef4..5cbd6fd 100644 --- a/src/Actions/ResolveClassesInPhpFileAction.php +++ b/src/Actions/ResolveClassesInPhpFileAction.php @@ -18,7 +18,7 @@ class ResolveClassesInPhpFileAction public function __construct() { - $this->parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7); + $this->parser = (new ParserFactory())->createForHostVersion(); } public function execute(SplFileInfo $file): array