mirror of
https://github.com/danog/psalm-plugin-laravel.git
synced 2024-11-26 20:34:48 +01:00
Merge branch 'master' into laravel-9-test-fixes
This commit is contained in:
commit
813874b655
@ -21,9 +21,15 @@
|
|||||||
<PropertyNotSetInConstructor>
|
<PropertyNotSetInConstructor>
|
||||||
<errorLevel type="suppress">
|
<errorLevel type="suppress">
|
||||||
<file name="src/Fakes/FakeMetaCommand.php" />
|
<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>
|
</errorLevel>
|
||||||
</PropertyNotSetInConstructor>
|
</PropertyNotSetInConstructor>
|
||||||
|
<OverriddenMethodAccess>
|
||||||
|
<errorLevel type="suppress">
|
||||||
|
<file name="src/Fakes/FakeModelsCommand291.php" />
|
||||||
|
</errorLevel>
|
||||||
|
</OverriddenMethodAccess>
|
||||||
</issueHandlers>
|
</issueHandlers>
|
||||||
|
|
||||||
<stubs>
|
<stubs>
|
||||||
|
@ -6,6 +6,9 @@ use Barryvdh\LaravelIdeHelper\Console\MetaCommand;
|
|||||||
|
|
||||||
class FakeMetaCommand extends MetaCommand
|
class FakeMetaCommand extends MetaCommand
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @return callable
|
||||||
|
*/
|
||||||
protected function registerClassAutoloadExceptions(): callable
|
protected function registerClassAutoloadExceptions(): callable
|
||||||
{
|
{
|
||||||
// by default, the ide-helper throws exceptions when it cannot find a class. However it does not unregister that
|
// 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;
|
namespace Psalm\LaravelPlugin\Fakes;
|
||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Psalm\LaravelPlugin\Handlers\Eloquent\Schema\SchemaAggregator;
|
|
||||||
|
|
||||||
use function config;
|
use function config;
|
||||||
use function get_class;
|
use function get_class;
|
||||||
use function implode;
|
|
||||||
use function in_array;
|
use function in_array;
|
||||||
|
use function implode;
|
||||||
|
|
||||||
class FakeModelsCommand extends ModelsCommand
|
trait FakeModelsCommandLogic
|
||||||
{
|
{
|
||||||
/** @var SchemaAggregator */
|
|
||||||
private $schema;
|
|
||||||
|
|
||||||
/** @var array<class-string> */
|
/** @var array<class-string> */
|
||||||
private $model_classes = [];
|
private $model_classes = [];
|
||||||
|
|
||||||
public function __construct(Filesystem $files, SchemaAggregator $schema)
|
|
||||||
{
|
|
||||||
parent::__construct($files);
|
|
||||||
$this->schema = $schema;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return array<class-string> */
|
/** @return array<class-string> */
|
||||||
public function getModels()
|
public function getModels(): array
|
||||||
{
|
{
|
||||||
return $this->model_classes + $this->loadModels();
|
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\Internal\Analyzer\ProjectAnalyzer;
|
||||||
use Psalm\LaravelPlugin\Fakes\FakeFilesystem;
|
use Psalm\LaravelPlugin\Fakes\FakeFilesystem;
|
||||||
use Psalm\LaravelPlugin\Fakes\FakeModelsCommand;
|
|
||||||
use Psalm\LaravelPlugin\Handlers\Eloquent\Schema\SchemaAggregator;
|
use Psalm\LaravelPlugin\Handlers\Eloquent\Schema\SchemaAggregator;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
use Symfony\Component\Console\Output\NullOutput;
|
use Symfony\Component\Console\Output\NullOutput;
|
||||||
|
|
||||||
use function dirname;
|
|
||||||
use function glob;
|
use function glob;
|
||||||
use function unlink;
|
use function unlink;
|
||||||
|
|
||||||
@ -37,7 +35,7 @@ final class ModelStubProvider implements GeneratesStubs
|
|||||||
|
|
||||||
$fake_filesystem = new FakeFilesystem();
|
$fake_filesystem = new FakeFilesystem();
|
||||||
|
|
||||||
$models_generator_command = new FakeModelsCommand(
|
$models_generator_command = FakeModelsCommandProvider::getCommand(
|
||||||
$fake_filesystem,
|
$fake_filesystem,
|
||||||
$schema_aggregator
|
$schema_aggregator
|
||||||
);
|
);
|
||||||
|
@ -89,6 +89,11 @@
|
|||||||
<code>ExampleListener</code>
|
<code>ExampleListener</code>
|
||||||
</UnusedClass>
|
</UnusedClass>
|
||||||
</file>
|
</file>
|
||||||
|
<file src="app/Models/Example.php">
|
||||||
|
<UnusedClass occurrences="1">
|
||||||
|
<code>Example</code>
|
||||||
|
</UnusedClass>
|
||||||
|
</file>
|
||||||
<file src="app/Models/User.php">
|
<file src="app/Models/User.php">
|
||||||
<NonInvariantDocblockPropertyType occurrences="3">
|
<NonInvariantDocblockPropertyType occurrences="3">
|
||||||
<code>$casts</code>
|
<code>$casts</code>
|
||||||
|
Loading…
Reference in New Issue
Block a user