Skip to content

Commit

Permalink
Use symfony/finder to find all stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
alies-dev committed Mar 17, 2024
1 parent 5967ab7 commit 2cdaf0f
Show file tree
Hide file tree
Showing 39 changed files with 19 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
39 changes: 18 additions & 21 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,38 +50,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.

0 comments on commit 2cdaf0f

Please sign in to comment.