Skip to content

Commit

Permalink
Merge pull request #382 from alies-dev/autoload-common-stubs
Browse files Browse the repository at this point in the history
Use symfony/finder to find all stubs
  • Loading branch information
alies-dev authored Mar 17, 2024
2 parents 11c10b2 + ce4bbe2 commit 5409fbc
Show file tree
Hide file tree
Showing 40 changed files with 27 additions and 21 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
40 changes: 19 additions & 21 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,38 +51,34 @@ public function __invoke(RegistrationInterface $registration, ?SimpleXMLElement
$this->registerStubs($registration);
}

/** @return array<array-key, string> */
/** @return list<string> */
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<array-key, string> */
/** @return list<string> */
protected function getTaintAnalysisStubs(): array
{
return array_merge(
glob(dirname(__DIR__) . '/stubs/TaintAnalysis/Http/*.stubphp'),
);
}

/** @return array<array-key, string> */
/** @return list<string> */
protected function getStubsForVersion(string $version): array
{
[$majorVersion] = explode('.', $version);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions tests/Type/README.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 5409fbc

Please sign in to comment.