Skip to content

Commit

Permalink
Merge pull request #378 from alies-dev/backport-critical-fixes-for-la…
Browse files Browse the repository at this point in the history
…ravel7

Backport critical fixes for laravel7
  • Loading branch information
alies-dev authored Mar 17, 2024
2 parents 7f15023 + c9b7b70 commit 018c576
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
32 changes: 18 additions & 14 deletions src/Fakes/FakeModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,14 @@
namespace Psalm\LaravelPlugin\Fakes;

use Composer\Autoload\ClassMapGenerator;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use Psalm\LaravelPlugin\Handlers\Eloquent\Schema\SchemaAggregator;
use ReflectionClass;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Barryvdh\Reflection\DocBlock;
use Barryvdh\Reflection\DocBlock\Context;
use Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
use function get_class;
use function in_array;
use function config;
use function get_class;
use function implode;
use function in_array;

class FakeModelsCommand extends \Barryvdh\LaravelIdeHelper\Console\ModelsCommand
{
Expand All @@ -41,7 +32,20 @@ public function __construct(Filesystem $files, SchemaAggregator $schema)
/** @return array<class-string> */
public function getModels()
{
return $this->model_classes + $this->loadModels();
if ($this->dirs === []) {
throw new \LogicException('Directories to scan models are not set.');
}

$models = [];

// Bypass an issue https://github.com/barryvdh/laravel-ide-helper/issues/1414
foreach ($this->loadModels() as $probably_model_fqcn) {
if (is_string($probably_model_fqcn) && is_a($probably_model_fqcn, Model::class, true)) {
$models[] = $probably_model_fqcn;
}
}

return array_merge($this->model_classes, $models);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Util/ContainerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace Psalm\LaravelPlugin\Util;

use Illuminate\Contracts\Container\BindingResolutionException;
use Psalm\LaravelPlugin\Providers\ApplicationProvider;
use Psalm\NodeTypeProvider;
use Psalm\Type\Atomic\TLiteralString;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Union;
use ReflectionException;
use function array_key_exists;
use function get_class;
use function count;
Expand Down Expand Up @@ -38,7 +36,7 @@ private static function resolveFromApplicationContainer(string $abstract): ?stri
// dynamic analysis to resolve the actual type from the container
try {
$concrete = ApplicationProvider::getApp()->make($abstract);
} catch (BindingResolutionException | ReflectionException $e) {
} catch (\Throwable $e) {
return null;
}

Expand Down

0 comments on commit 018c576

Please sign in to comment.