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..957ae52b 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -22,12 +22,14 @@ use Psalm\Plugin\PluginEntryPointInterface; use Psalm\Plugin\RegistrationInterface; use SimpleXMLElement; +use Symfony\Component\Finder\Finder; use function array_merge; use function dirname; use function fwrite; use function explode; use function glob; +use function is_string; /** * @psalm-suppress UnusedClass @@ -49,30 +51,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 +78,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 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.