mirror of
https://github.com/danog/psalm-plugin-laravel.git
synced 2024-11-30 04:39:01 +01:00
Merge branch 'master' into laravel-9-test-fixes
This commit is contained in:
commit
813874b655
@ -21,9 +21,15 @@
|
||||
<PropertyNotSetInConstructor>
|
||||
<errorLevel type="suppress">
|
||||
<file name="src/Fakes/FakeMetaCommand.php" />
|
||||
<file name="src/Fakes/FakeModelsCommand.php" />
|
||||
<file name="src/Fakes/FakeModelsCommand291.php" />
|
||||
<file name="src/Fakes/FakeModelsCommand210.php" />
|
||||
</errorLevel>
|
||||
</PropertyNotSetInConstructor>
|
||||
<OverriddenMethodAccess>
|
||||
<errorLevel type="suppress">
|
||||
<file name="src/Fakes/FakeModelsCommand291.php" />
|
||||
</errorLevel>
|
||||
</OverriddenMethodAccess>
|
||||
</issueHandlers>
|
||||
|
||||
<stubs>
|
||||
|
@ -6,6 +6,9 @@ use Barryvdh\LaravelIdeHelper\Console\MetaCommand;
|
||||
|
||||
class FakeMetaCommand extends MetaCommand
|
||||
{
|
||||
/**
|
||||
* @return callable
|
||||
*/
|
||||
protected function registerClassAutoloadExceptions(): callable
|
||||
{
|
||||
// by default, the ide-helper throws exceptions when it cannot find a class. However it does not unregister that
|
||||
|
32
src/Fakes/FakeModelsCommand210.php
Normal file
32
src/Fakes/FakeModelsCommand210.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Psalm\LaravelPlugin\Fakes;
|
||||
|
||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Psalm\LaravelPlugin\Handlers\Eloquent\Schema\SchemaAggregator;
|
||||
|
||||
class FakeModelsCommand210 extends ModelsCommand
|
||||
{
|
||||
use FakeModelsCommandLogic;
|
||||
|
||||
/** @var SchemaAggregator */
|
||||
private $schema;
|
||||
|
||||
public function __construct(Filesystem $files, SchemaAggregator $schema)
|
||||
{
|
||||
parent::__construct($files);
|
||||
$this->schema = $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the properties from the database table.
|
||||
*
|
||||
* @param Model $model
|
||||
*/
|
||||
public function getPropertiesFromTable($model): void
|
||||
{
|
||||
$this->getProperties($model);
|
||||
}
|
||||
}
|
35
src/Fakes/FakeModelsCommand291.php
Normal file
35
src/Fakes/FakeModelsCommand291.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Psalm\LaravelPlugin\Fakes;
|
||||
|
||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Psalm\LaravelPlugin\Handlers\Eloquent\Schema\SchemaAggregator;
|
||||
|
||||
class FakeModelsCommand291 extends ModelsCommand
|
||||
{
|
||||
use FakeModelsCommandLogic;
|
||||
|
||||
/** @var SchemaAggregator */
|
||||
private $schema;
|
||||
|
||||
/** @var array<class-string> */
|
||||
private $model_classes = [];
|
||||
|
||||
public function __construct(Filesystem $files, SchemaAggregator $schema)
|
||||
{
|
||||
parent::__construct($files);
|
||||
$this->schema = $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the properties from the database table.
|
||||
*
|
||||
* @param Model $model
|
||||
*/
|
||||
protected function getPropertiesFromTable($model): void
|
||||
{
|
||||
$this->getProperties($model);
|
||||
}
|
||||
}
|
@ -2,33 +2,21 @@
|
||||
|
||||
namespace Psalm\LaravelPlugin\Fakes;
|
||||
|
||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Str;
|
||||
use Psalm\LaravelPlugin\Handlers\Eloquent\Schema\SchemaAggregator;
|
||||
|
||||
use function config;
|
||||
use function get_class;
|
||||
use function implode;
|
||||
use function in_array;
|
||||
use function implode;
|
||||
|
||||
class FakeModelsCommand extends ModelsCommand
|
||||
trait FakeModelsCommandLogic
|
||||
{
|
||||
/** @var SchemaAggregator */
|
||||
private $schema;
|
||||
|
||||
/** @var array<class-string> */
|
||||
private $model_classes = [];
|
||||
|
||||
public function __construct(Filesystem $files, SchemaAggregator $schema)
|
||||
{
|
||||
parent::__construct($files);
|
||||
$this->schema = $schema;
|
||||
}
|
||||
|
||||
/** @return array<class-string> */
|
||||
public function getModels()
|
||||
public function getModels(): array
|
||||
{
|
||||
return $this->model_classes + $this->loadModels();
|
||||
}
|
37
src/Providers/FakeModelsCommandProvider.php
Normal file
37
src/Providers/FakeModelsCommandProvider.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Psalm\LaravelPlugin\Providers;
|
||||
|
||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||
use Composer\InstalledVersions;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Psalm\LaravelPlugin\Fakes\FakeModelsCommand210;
|
||||
use Psalm\LaravelPlugin\Fakes\FakeModelsCommand291;
|
||||
use Psalm\LaravelPlugin\Handlers\Eloquent\Schema\SchemaAggregator;
|
||||
|
||||
use function version_compare;
|
||||
use function assert;
|
||||
use function is_string;
|
||||
|
||||
class FakeModelsCommandProvider
|
||||
{
|
||||
public static function getCommand(Filesystem $filesystem, SchemaAggregator $schemaAggregator): ModelsCommand
|
||||
{
|
||||
$ideHelperVersion = InstalledVersions::getVersion('barryvdh/laravel-ide-helper');
|
||||
|
||||
assert(is_string($ideHelperVersion));
|
||||
|
||||
// ide-helper released a breaking change in a non-major version. As a result, we need to monkey patch our code
|
||||
if (version_compare($ideHelperVersion, '2.9.2', '<')) {
|
||||
return new FakeModelsCommand291(
|
||||
$filesystem,
|
||||
$schemaAggregator
|
||||
);
|
||||
}
|
||||
|
||||
return new FakeModelsCommand210(
|
||||
$filesystem,
|
||||
$schemaAggregator
|
||||
);
|
||||
}
|
||||
}
|
@ -4,12 +4,10 @@ namespace Psalm\LaravelPlugin\Providers;
|
||||
|
||||
use Psalm\Internal\Analyzer\ProjectAnalyzer;
|
||||
use Psalm\LaravelPlugin\Fakes\FakeFilesystem;
|
||||
use Psalm\LaravelPlugin\Fakes\FakeModelsCommand;
|
||||
use Psalm\LaravelPlugin\Handlers\Eloquent\Schema\SchemaAggregator;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
|
||||
use function dirname;
|
||||
use function glob;
|
||||
use function unlink;
|
||||
|
||||
@ -37,7 +35,7 @@ final class ModelStubProvider implements GeneratesStubs
|
||||
|
||||
$fake_filesystem = new FakeFilesystem();
|
||||
|
||||
$models_generator_command = new FakeModelsCommand(
|
||||
$models_generator_command = FakeModelsCommandProvider::getCommand(
|
||||
$fake_filesystem,
|
||||
$schema_aggregator
|
||||
);
|
||||
|
@ -89,6 +89,11 @@
|
||||
<code>ExampleListener</code>
|
||||
</UnusedClass>
|
||||
</file>
|
||||
<file src="app/Models/Example.php">
|
||||
<UnusedClass occurrences="1">
|
||||
<code>Example</code>
|
||||
</UnusedClass>
|
||||
</file>
|
||||
<file src="app/Models/User.php">
|
||||
<NonInvariantDocblockPropertyType occurrences="3">
|
||||
<code>$casts</code>
|
||||
|
Loading…
Reference in New Issue
Block a user