From 2cdaf0f096c01165b1c305afff296e324e8da079 Mon Sep 17 00:00:00 2001 From: Alies Lapatsin Date: Sun, 17 Mar 2024 23:42:12 +0100 Subject: [PATCH 1/3] Use symfony/finder to find all stubs --- composer.json | 1 + src/Plugin.php | 39 +++++++++---------- .../{ => common}/Collections/helpers.stubphp | 0 .../{ => common}/Contracts/Container.stubphp | 0 .../{ => common}/Contracts/Pagination.stubphp | 0 .../Database/Eloquent/Builder.stubphp | 0 .../Database/Eloquent/Collection.stubphp | 0 .../Concerns/HasRelationships.stubphp | 0 .../Concerns/ManagesTransactions.stubphp | 0 .../Database/Eloquent/Model.stubphp | 0 .../Eloquent/Relations/BelongsTo.stubphp | 0 .../Eloquent/Relations/BelongsToMany.stubphp | 0 .../Eloquent/Relations/HasMany.stubphp | 0 .../Eloquent/Relations/HasManyThrough.stubphp | 0 .../Eloquent/Relations/HasOne.stubphp | 0 .../Eloquent/Relations/HasOneOrMany.stubphp | 0 .../Eloquent/Relations/HasOneThrough.stubphp | 0 .../Eloquent/Relations/MorphMany.stubphp | 0 .../Eloquent/Relations/MorphOne.stubphp | 0 .../Eloquent/Relations/MorphOneOrMany.stubphp | 0 .../Eloquent/Relations/MorphToMany.stubphp | 0 .../Eloquent/Relations/Relation.stubphp | 0 .../Database/Migrations/Migrator.stubphp | 0 .../Database/Query/Builder.stubphp | 0 .../Foundation/Application.stubphp | 0 stubs/{ => common}/Foundation/helpers.stubphp | 0 .../Http/InteractsWithInput.stubphp | 0 stubs/{ => common}/Http/Request.stubphp | 0 .../Messages/MailMessage.stubphp | 0 .../Pagination/Pagination.stubphp | 0 stubs/{ => common}/Routing/Route.stubphp | 0 stubs/{ => common}/Support/Collection.stubphp | 0 stubs/{ => common}/Support/Enumerable.stubphp | 0 stubs/{ => common}/Support/Facades/DB.stubphp | 0 stubs/{ => common}/Support/Optional.stubphp | 0 stubs/{ => common}/Support/helpers.stubphp | 0 .../TaintAnalysis/Http/Response.stubphp | 0 .../legacy-factories/FactoryBuilder.stubphp | 0 .../legacy-factories/helpers.stubphp | 0 39 files changed, 19 insertions(+), 21 deletions(-) rename stubs/{ => common}/Collections/helpers.stubphp (100%) rename stubs/{ => common}/Contracts/Container.stubphp (100%) rename stubs/{ => common}/Contracts/Pagination.stubphp (100%) rename stubs/{ => common}/Database/Eloquent/Builder.stubphp (100%) rename stubs/{ => common}/Database/Eloquent/Collection.stubphp (100%) rename stubs/{ => common}/Database/Eloquent/Concerns/HasRelationships.stubphp (100%) rename stubs/{ => common}/Database/Eloquent/Concerns/ManagesTransactions.stubphp (100%) rename stubs/{ => common}/Database/Eloquent/Model.stubphp (100%) rename stubs/{ => common}/Database/Eloquent/Relations/BelongsTo.stubphp (100%) rename stubs/{ => common}/Database/Eloquent/Relations/BelongsToMany.stubphp (100%) rename stubs/{ => common}/Database/Eloquent/Relations/HasMany.stubphp (100%) rename stubs/{ => common}/Database/Eloquent/Relations/HasManyThrough.stubphp (100%) rename stubs/{ => common}/Database/Eloquent/Relations/HasOne.stubphp (100%) rename stubs/{ => common}/Database/Eloquent/Relations/HasOneOrMany.stubphp (100%) rename stubs/{ => common}/Database/Eloquent/Relations/HasOneThrough.stubphp (100%) rename stubs/{ => common}/Database/Eloquent/Relations/MorphMany.stubphp (100%) rename stubs/{ => common}/Database/Eloquent/Relations/MorphOne.stubphp (100%) rename stubs/{ => common}/Database/Eloquent/Relations/MorphOneOrMany.stubphp (100%) rename stubs/{ => common}/Database/Eloquent/Relations/MorphToMany.stubphp (100%) rename stubs/{ => common}/Database/Eloquent/Relations/Relation.stubphp (100%) rename stubs/{ => common}/Database/Migrations/Migrator.stubphp (100%) rename stubs/{ => common}/Database/Query/Builder.stubphp (100%) rename stubs/{ => common}/Foundation/Application.stubphp (100%) rename stubs/{ => common}/Foundation/helpers.stubphp (100%) rename stubs/{ => common}/Http/InteractsWithInput.stubphp (100%) rename stubs/{ => common}/Http/Request.stubphp (100%) rename stubs/{ => common}/Notifications/Messages/MailMessage.stubphp (100%) rename stubs/{ => common}/Pagination/Pagination.stubphp (100%) rename stubs/{ => common}/Routing/Route.stubphp (100%) rename stubs/{ => common}/Support/Collection.stubphp (100%) rename stubs/{ => common}/Support/Enumerable.stubphp (100%) rename stubs/{ => common}/Support/Facades/DB.stubphp (100%) rename stubs/{ => common}/Support/Optional.stubphp (100%) rename stubs/{ => common}/Support/helpers.stubphp (100%) rename stubs/{ => common}/TaintAnalysis/Http/Response.stubphp (100%) rename stubs/{ => common}/legacy-factories/FactoryBuilder.stubphp (100%) rename stubs/{ => common}/legacy-factories/helpers.stubphp (100%) diff --git a/composer.json b/composer.json index b86fa16f..e56649fc 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,7 @@ "nikic/php-parser": "^4.18 || ^5.0", "orchestra/testbench-core": "^8.22 || ^9.0", "symfony/console": "^6.0 || ^7.0", + "symfony/finder": "^6.0 || ^7.0", "vimeo/psalm": "^5.20" }, "require-dev": { diff --git a/src/Plugin.php b/src/Plugin.php index 3bcf6d66..a3e46404 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -22,6 +22,7 @@ use Psalm\Plugin\PluginEntryPointInterface; use Psalm\Plugin\RegistrationInterface; use SimpleXMLElement; +use Symfony\Component\Finder\Finder; use function array_merge; use function dirname; @@ -49,30 +50,26 @@ public function __invoke(RegistrationInterface $registration, ?SimpleXMLElement $this->registerStubs($registration); } - /** @return array */ + /** @return list */ protected function getCommonStubs(): array { - return array_merge( - glob(dirname(__DIR__) . '/stubs/Collections/*.stubphp'), - glob(dirname(__DIR__) . '/stubs/Contracts/*.stubphp'), - glob(dirname(__DIR__) . '/stubs/Database/Eloquent/Concerns/*.stubphp'), - glob(dirname(__DIR__) . '/stubs/Database/Eloquent/Relations/*.stubphp'), - glob(dirname(__DIR__) . '/stubs/Database/Eloquent/*.stubphp'), - glob(dirname(__DIR__) . '/stubs/Database/Migrations/*.stubphp'), - glob(dirname(__DIR__) . '/stubs/Database/Query/*.stubphp'), - glob(dirname(__DIR__) . '/stubs/Database/*.stubphp'), - glob(dirname(__DIR__) . '/stubs/Foundation/*.stubphp'), - glob(dirname(__DIR__) . '/stubs/Http/*.stubphp'), - glob(dirname(__DIR__) . '/stubs/legacy-factories/*.stubphp'), - glob(dirname(__DIR__) . '/stubs/Pagination/*.stubphp'), - glob(dirname(__DIR__) . '/stubs/Notifications/**/*.stubphp'), - glob(dirname(__DIR__) . '/stubs/Routing/*.stubphp'), - glob(dirname(__DIR__) . '/stubs/Support/*.stubphp'), - glob(dirname(__DIR__) . '/stubs/Support/**/*.stubphp'), - ); + $stubFilepaths = []; + + $basePath = dirname(__DIR__) . \DIRECTORY_SEPARATOR . 'stubs' . \DIRECTORY_SEPARATOR . 'common'; + + $stubFiles = Finder::create()->files()->name('*.stubphp')->in($basePath); + + foreach ($stubFiles as $stubFile) { + $stubFilepath = $stubFile->getRealPath(); + if (is_string($stubFilepath)) { + $stubFilepaths[] = $stubFilepath; + } + } + + return $stubFilepaths; } - /** @return array */ + /** @return list */ protected function getTaintAnalysisStubs(): array { return array_merge( @@ -80,7 +77,7 @@ protected function getTaintAnalysisStubs(): array ); } - /** @return array */ + /** @return list */ protected function getStubsForVersion(string $version): array { [$majorVersion] = explode('.', $version); diff --git a/stubs/Collections/helpers.stubphp b/stubs/common/Collections/helpers.stubphp similarity index 100% rename from stubs/Collections/helpers.stubphp rename to stubs/common/Collections/helpers.stubphp diff --git a/stubs/Contracts/Container.stubphp b/stubs/common/Contracts/Container.stubphp similarity index 100% rename from stubs/Contracts/Container.stubphp rename to stubs/common/Contracts/Container.stubphp diff --git a/stubs/Contracts/Pagination.stubphp b/stubs/common/Contracts/Pagination.stubphp similarity index 100% rename from stubs/Contracts/Pagination.stubphp rename to stubs/common/Contracts/Pagination.stubphp diff --git a/stubs/Database/Eloquent/Builder.stubphp b/stubs/common/Database/Eloquent/Builder.stubphp similarity index 100% rename from stubs/Database/Eloquent/Builder.stubphp rename to stubs/common/Database/Eloquent/Builder.stubphp diff --git a/stubs/Database/Eloquent/Collection.stubphp b/stubs/common/Database/Eloquent/Collection.stubphp similarity index 100% rename from stubs/Database/Eloquent/Collection.stubphp rename to stubs/common/Database/Eloquent/Collection.stubphp diff --git a/stubs/Database/Eloquent/Concerns/HasRelationships.stubphp b/stubs/common/Database/Eloquent/Concerns/HasRelationships.stubphp similarity index 100% rename from stubs/Database/Eloquent/Concerns/HasRelationships.stubphp rename to stubs/common/Database/Eloquent/Concerns/HasRelationships.stubphp diff --git a/stubs/Database/Eloquent/Concerns/ManagesTransactions.stubphp b/stubs/common/Database/Eloquent/Concerns/ManagesTransactions.stubphp similarity index 100% rename from stubs/Database/Eloquent/Concerns/ManagesTransactions.stubphp rename to stubs/common/Database/Eloquent/Concerns/ManagesTransactions.stubphp diff --git a/stubs/Database/Eloquent/Model.stubphp b/stubs/common/Database/Eloquent/Model.stubphp similarity index 100% rename from stubs/Database/Eloquent/Model.stubphp rename to stubs/common/Database/Eloquent/Model.stubphp diff --git a/stubs/Database/Eloquent/Relations/BelongsTo.stubphp b/stubs/common/Database/Eloquent/Relations/BelongsTo.stubphp similarity index 100% rename from stubs/Database/Eloquent/Relations/BelongsTo.stubphp rename to stubs/common/Database/Eloquent/Relations/BelongsTo.stubphp diff --git a/stubs/Database/Eloquent/Relations/BelongsToMany.stubphp b/stubs/common/Database/Eloquent/Relations/BelongsToMany.stubphp similarity index 100% rename from stubs/Database/Eloquent/Relations/BelongsToMany.stubphp rename to stubs/common/Database/Eloquent/Relations/BelongsToMany.stubphp diff --git a/stubs/Database/Eloquent/Relations/HasMany.stubphp b/stubs/common/Database/Eloquent/Relations/HasMany.stubphp similarity index 100% rename from stubs/Database/Eloquent/Relations/HasMany.stubphp rename to stubs/common/Database/Eloquent/Relations/HasMany.stubphp diff --git a/stubs/Database/Eloquent/Relations/HasManyThrough.stubphp b/stubs/common/Database/Eloquent/Relations/HasManyThrough.stubphp similarity index 100% rename from stubs/Database/Eloquent/Relations/HasManyThrough.stubphp rename to stubs/common/Database/Eloquent/Relations/HasManyThrough.stubphp diff --git a/stubs/Database/Eloquent/Relations/HasOne.stubphp b/stubs/common/Database/Eloquent/Relations/HasOne.stubphp similarity index 100% rename from stubs/Database/Eloquent/Relations/HasOne.stubphp rename to stubs/common/Database/Eloquent/Relations/HasOne.stubphp diff --git a/stubs/Database/Eloquent/Relations/HasOneOrMany.stubphp b/stubs/common/Database/Eloquent/Relations/HasOneOrMany.stubphp similarity index 100% rename from stubs/Database/Eloquent/Relations/HasOneOrMany.stubphp rename to stubs/common/Database/Eloquent/Relations/HasOneOrMany.stubphp diff --git a/stubs/Database/Eloquent/Relations/HasOneThrough.stubphp b/stubs/common/Database/Eloquent/Relations/HasOneThrough.stubphp similarity index 100% rename from stubs/Database/Eloquent/Relations/HasOneThrough.stubphp rename to stubs/common/Database/Eloquent/Relations/HasOneThrough.stubphp diff --git a/stubs/Database/Eloquent/Relations/MorphMany.stubphp b/stubs/common/Database/Eloquent/Relations/MorphMany.stubphp similarity index 100% rename from stubs/Database/Eloquent/Relations/MorphMany.stubphp rename to stubs/common/Database/Eloquent/Relations/MorphMany.stubphp diff --git a/stubs/Database/Eloquent/Relations/MorphOne.stubphp b/stubs/common/Database/Eloquent/Relations/MorphOne.stubphp similarity index 100% rename from stubs/Database/Eloquent/Relations/MorphOne.stubphp rename to stubs/common/Database/Eloquent/Relations/MorphOne.stubphp diff --git a/stubs/Database/Eloquent/Relations/MorphOneOrMany.stubphp b/stubs/common/Database/Eloquent/Relations/MorphOneOrMany.stubphp similarity index 100% rename from stubs/Database/Eloquent/Relations/MorphOneOrMany.stubphp rename to stubs/common/Database/Eloquent/Relations/MorphOneOrMany.stubphp diff --git a/stubs/Database/Eloquent/Relations/MorphToMany.stubphp b/stubs/common/Database/Eloquent/Relations/MorphToMany.stubphp similarity index 100% rename from stubs/Database/Eloquent/Relations/MorphToMany.stubphp rename to stubs/common/Database/Eloquent/Relations/MorphToMany.stubphp diff --git a/stubs/Database/Eloquent/Relations/Relation.stubphp b/stubs/common/Database/Eloquent/Relations/Relation.stubphp similarity index 100% rename from stubs/Database/Eloquent/Relations/Relation.stubphp rename to stubs/common/Database/Eloquent/Relations/Relation.stubphp diff --git a/stubs/Database/Migrations/Migrator.stubphp b/stubs/common/Database/Migrations/Migrator.stubphp similarity index 100% rename from stubs/Database/Migrations/Migrator.stubphp rename to stubs/common/Database/Migrations/Migrator.stubphp diff --git a/stubs/Database/Query/Builder.stubphp b/stubs/common/Database/Query/Builder.stubphp similarity index 100% rename from stubs/Database/Query/Builder.stubphp rename to stubs/common/Database/Query/Builder.stubphp diff --git a/stubs/Foundation/Application.stubphp b/stubs/common/Foundation/Application.stubphp similarity index 100% rename from stubs/Foundation/Application.stubphp rename to stubs/common/Foundation/Application.stubphp diff --git a/stubs/Foundation/helpers.stubphp b/stubs/common/Foundation/helpers.stubphp similarity index 100% rename from stubs/Foundation/helpers.stubphp rename to stubs/common/Foundation/helpers.stubphp diff --git a/stubs/Http/InteractsWithInput.stubphp b/stubs/common/Http/InteractsWithInput.stubphp similarity index 100% rename from stubs/Http/InteractsWithInput.stubphp rename to stubs/common/Http/InteractsWithInput.stubphp diff --git a/stubs/Http/Request.stubphp b/stubs/common/Http/Request.stubphp similarity index 100% rename from stubs/Http/Request.stubphp rename to stubs/common/Http/Request.stubphp diff --git a/stubs/Notifications/Messages/MailMessage.stubphp b/stubs/common/Notifications/Messages/MailMessage.stubphp similarity index 100% rename from stubs/Notifications/Messages/MailMessage.stubphp rename to stubs/common/Notifications/Messages/MailMessage.stubphp diff --git a/stubs/Pagination/Pagination.stubphp b/stubs/common/Pagination/Pagination.stubphp similarity index 100% rename from stubs/Pagination/Pagination.stubphp rename to stubs/common/Pagination/Pagination.stubphp diff --git a/stubs/Routing/Route.stubphp b/stubs/common/Routing/Route.stubphp similarity index 100% rename from stubs/Routing/Route.stubphp rename to stubs/common/Routing/Route.stubphp diff --git a/stubs/Support/Collection.stubphp b/stubs/common/Support/Collection.stubphp similarity index 100% rename from stubs/Support/Collection.stubphp rename to stubs/common/Support/Collection.stubphp diff --git a/stubs/Support/Enumerable.stubphp b/stubs/common/Support/Enumerable.stubphp similarity index 100% rename from stubs/Support/Enumerable.stubphp rename to stubs/common/Support/Enumerable.stubphp diff --git a/stubs/Support/Facades/DB.stubphp b/stubs/common/Support/Facades/DB.stubphp similarity index 100% rename from stubs/Support/Facades/DB.stubphp rename to stubs/common/Support/Facades/DB.stubphp diff --git a/stubs/Support/Optional.stubphp b/stubs/common/Support/Optional.stubphp similarity index 100% rename from stubs/Support/Optional.stubphp rename to stubs/common/Support/Optional.stubphp diff --git a/stubs/Support/helpers.stubphp b/stubs/common/Support/helpers.stubphp similarity index 100% rename from stubs/Support/helpers.stubphp rename to stubs/common/Support/helpers.stubphp diff --git a/stubs/TaintAnalysis/Http/Response.stubphp b/stubs/common/TaintAnalysis/Http/Response.stubphp similarity index 100% rename from stubs/TaintAnalysis/Http/Response.stubphp rename to stubs/common/TaintAnalysis/Http/Response.stubphp diff --git a/stubs/legacy-factories/FactoryBuilder.stubphp b/stubs/common/legacy-factories/FactoryBuilder.stubphp similarity index 100% rename from stubs/legacy-factories/FactoryBuilder.stubphp rename to stubs/common/legacy-factories/FactoryBuilder.stubphp diff --git a/stubs/legacy-factories/helpers.stubphp b/stubs/common/legacy-factories/helpers.stubphp similarity index 100% rename from stubs/legacy-factories/helpers.stubphp rename to stubs/common/legacy-factories/helpers.stubphp From c38de44278227edcfd3e9acd986d85bc684b06ad Mon Sep 17 00:00:00 2001 From: Alies Lapatsin Date: Sun, 17 Mar 2024 23:46:27 +0100 Subject: [PATCH 2/3] Add a simple readme for PHPT tests --- tests/Type/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/Type/README.md diff --git a/tests/Type/README.md b/tests/Type/README.md new file mode 100644 index 00000000..436fd106 --- /dev/null +++ b/tests/Type/README.md @@ -0,0 +1,7 @@ +# PHPT tests + +These tests are written using PHPT: syntax, originally created to test PHP interpreter itself. + +For the basic usage, please check [phpyh/psalm-tester](https://github.com/phpyh/psalm-tester). + +To go deeper with PHPT syntax, please check [PHPT](https://qa.php.net/phpt_details.php) official guide. From ce4bbe2f15659c0331513efcc51cc00107622552 Mon Sep 17 00:00:00 2001 From: Alies Lapatsin Date: Sun, 17 Mar 2024 23:46:57 +0100 Subject: [PATCH 3/3] Fix cs --- src/Plugin.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Plugin.php b/src/Plugin.php index a3e46404..957ae52b 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -29,6 +29,7 @@ use function fwrite; use function explode; use function glob; +use function is_string; /** * @psalm-suppress UnusedClass