diff --git a/.gitignore b/.gitignore index df918ba7..39575218 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ -composer.phar /laravel/ +/lumen/ + /vendor/ composer.lock + cache/*.stubphp -.DS_Store diff --git a/composer.json b/composer.json index 68b984fa..31291725 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "illuminate/support": "^6.0 || ^8.0", "illuminate/view": "^6.0 || ^8.0", "vimeo/psalm": "^4.8.1", - "orchestra/testbench": "^3.8 || ^4.0 || ^5.0 || ^6.22 || ^7.0", + "orchestra/testbench": "^4.0 || ^6.0", "barryvdh/laravel-ide-helper": ">=2.8.0" }, "require-dev": { @@ -45,9 +45,11 @@ } }, "scripts": { - "analyze": "psalm", + "analyze": "@psalm", "lint": "phpcs -n", "lint-fix": "phpcbf -n", + "psalm": "psalm", + "psalm-set-baseline": "psalm --set-baseline=psalm-baseline.xml", "test": "codecept run --skip-group skip", "check": [ "@analyze", diff --git a/src/Plugin.php b/src/Plugin.php index c28bc1b5..952eac5e 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -24,6 +24,7 @@ use Throwable; use function array_merge; +use function class_exists; use function dirname; use function explode; use function glob; @@ -57,10 +58,14 @@ protected function getStubsForVersion(string $version): array private function registerStubs(RegistrationInterface $registration): void { - $stubs = array_merge( - $this->getCommonStubs(), - $this->getStubsForVersion(Application::VERSION), - ); + $stubs = $this->getCommonStubs(); + + if (class_exists(Application::class)) { // Ensure the class is loaded (for Lumen support + $stubs = array_merge( + $stubs, + $this->getStubsForVersion(Application::VERSION), + ); + } foreach ($stubs as $stubFilePath) { $registration->addStubFile($stubFilePath); diff --git a/tests/laravel-test-baseline.xml b/tests/laravel-test-psalm-baseline.xml similarity index 100% rename from tests/laravel-test-baseline.xml rename to tests/laravel-test-psalm-baseline.xml diff --git a/tests/laravel-test-psalm.xml b/tests/laravel-test-psalm.xml index 952e3289..d11eabe7 100644 --- a/tests/laravel-test-psalm.xml +++ b/tests/laravel-test-psalm.xml @@ -5,7 +5,7 @@ findUnusedCode="true" resolveFromConfigFile="false" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" - errorBaseline="../psalm-plugin-laravel/tests/laravel-test-baseline.xml" + errorBaseline="psalm-baseline.xml" phpVersion="8.0" > @@ -17,6 +17,7 @@ + diff --git a/tests/laravel-test.sh b/tests/laravel-test.sh index 262e87c0..efbc927f 100755 --- a/tests/laravel-test.sh +++ b/tests/laravel-test.sh @@ -3,11 +3,16 @@ set -e echo "Cleaning Up" -rm -rf ../laravel/ +rm -rf ./laravel/ echo "Installing Laravel" -composer create-project laravel/laravel ../laravel 8.6.* --quiet --prefer-dist -cd ../laravel/ +composer create-project laravel/laravel ./laravel 8.6.* --quiet --prefer-dist +cd ./laravel/ + +echo "Adding package from source" +composer config repositories.0 '{"type": "path", "url": "../"}' +composer config minimum-stability 'dev' +COMPOSER_MEMORY_LIMIT=-1 composer require --dev "psalm/plugin-laravel:*" --update-with-all-dependencies echo "Preparing Laravel" ./artisan make:cast ExampleCast @@ -31,10 +36,8 @@ echo "Preparing Laravel" ./artisan make:rule ExampleRule ./artisan make:seeder ExampleSeeder -echo "Adding package from source" -composer config repositories.0 '{"type": "path", "url": "../../"}' -composer config minimum-stability 'dev' -COMPOSER_MEMORY_LIMIT=-1 composer require --dev "psalm/plugin-laravel:*" --update-with-all-dependencies +cp ../tests/laravel-test-psalm.xml ./psalm.xml +cp ../tests/laravel-test-psalm-baseline.xml ./psalm-baseline.xml -echo "Analyzing Laravel" -./vendor/bin/psalm -c ../psalm-plugin-laravel/tests/laravel-test-psalm.xml +echo "Laravel App Analyse" +./vendor/bin/psalm -c diff --git a/tests/lumen-test-baseline.xml b/tests/lumen-test-psalm-baseline.xml similarity index 100% rename from tests/lumen-test-baseline.xml rename to tests/lumen-test-psalm-baseline.xml diff --git a/tests/lumen-test-psalm.xml b/tests/lumen-test-psalm.xml index 2a4d9626..d11eabe7 100644 --- a/tests/lumen-test-psalm.xml +++ b/tests/lumen-test-psalm.xml @@ -5,7 +5,7 @@ findUnusedCode="true" resolveFromConfigFile="false" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" - errorBaseline="../psalm-plugin-laravel/tests/lumen-test-baseline.xml" + errorBaseline="psalm-baseline.xml" phpVersion="8.0" > diff --git a/tests/lumen-test.sh b/tests/lumen-test.sh index 5c2d5444..a52225ac 100755 --- a/tests/lumen-test.sh +++ b/tests/lumen-test.sh @@ -3,16 +3,19 @@ set -e echo "Cleaning Up" -rm -rf ../lumen/ +rm -rf ./lumen/ echo "Installing Lumen" -composer create-project laravel/lumen ../lumen 8.* --quiet --prefer-dist -cd ../lumen/ +composer create-project laravel/lumen ./lumen 8.* --quiet --prefer-dist +cd ./lumen/ echo "Adding package from source" -composer config repositories.0 '{"type": "path", "url": "../../"}' +composer config repositories.0 '{"type": "path", "url": "../"}' composer config minimum-stability 'dev' COMPOSER_MEMORY_LIMIT=-1 composer require --dev "psalm/plugin-laravel:*" --update-with-all-dependencies -echo "Analyzing Lumen" -./vendor/bin/psalm -c ../psalm-plugin-laravel/tests/lumen-test-psalm.xml +cp ../tests/lumen-test-psalm.xml ./psalm.xml +cp ../tests/lumen-test-psalm-baseline.xml ./psalm-baseline.xml + +echo "Lumen App Analyse" +./vendor/bin/psalm -c