Skip to content

Commit

Permalink
Improve static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Sep 29, 2024
1 parent 5316030 commit 9e2323e
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 63 deletions.
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^3.0",
"larastan/larastan": "^2.9",
"orchestra/testbench": "^9.0",
"phpstan/phpstan-mockery": "^1.1",
"phpstan/phpstan-phpunit": "^1.4",
"phpstan/phpstan": "^1.12",
"phpunit/phpunit": "^11.0"
},
"autoload": {
Expand Down
8 changes: 1 addition & 7 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
includes:
- ./vendor/larastan/larastan/extension.neon
- ./vendor/phpstan/phpstan-mockery/extension.neon
- ./vendor/phpstan/phpstan-phpunit/extension.neon
- ./vendor/phpstan/phpstan-phpunit/rules.neon
parameters:
level: max
level: 9
paths:
- src
- tests
2 changes: 1 addition & 1 deletion src/IdeHelper/BelongsToThroughRelationsHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function run(ModelsCommand $command, Model $model): void
}

/**
* @param \Illuminate\Database\Eloquent\Relations\Relation<\Illuminate\Database\Eloquent\Model> $relationship
* @param \Illuminate\Database\Eloquent\Relations\Relation<*,*, *> $relationship
*/
protected function addRelationship(ModelsCommand $command, ReflectionMethod $method, Relation $relationship): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/IdeHelperServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class IdeHelperServiceProvider extends ServiceProvider implements DeferrableProv
{
public function register(): void
{
/** @var \Illuminate\Contracts\Config\Repository $config */
/** @var \Illuminate\Config\Repository $config */
$config = $this->app->get('config');

$config->set(
Expand All @@ -24,7 +24,7 @@ public function register(): void
}

/**
* @return class-string<\Illuminate\Console\Command>[]
* @return list<class-string<\Illuminate\Console\Command>>
*/
public function provides(): array
{
Expand Down
12 changes: 8 additions & 4 deletions src/Relations/BelongsToThrough.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Query\Expression;
use Illuminate\Support\Str;
use RuntimeException;

/**
* @template TRelatedModel of \Illuminate\Database\Eloquent\Model
* @template TDeclaringModel of \Illuminate\Database\Eloquent\Model
*
* @extends \Illuminate\Database\Eloquent\Relations\Relation<TRelatedModel>
* @extends \Illuminate\Database\Eloquent\Relations\Relation<TRelatedModel, TDeclaringModel, ?TRelatedModel>
*/
class BelongsToThrough extends Relation
{
Expand Down Expand Up @@ -253,7 +252,12 @@ public function first($columns = ['*'])
return $this->query->first($columns);
}

/** @inheritDoc */
/**
* Execute the query as a "select" statement.
*
* @param list<string> $columns
* @return \Illuminate\Database\Eloquent\Collection<int, TRelatedModel>
*/
public function get($columns = ['*'])
{
$columns = $this->query->getQuery()->columns ? [] : $columns;
Expand Down
3 changes: 0 additions & 3 deletions tests/IdeHelper/Models/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ class Comment extends Model
{
use BelongsToThroughTrait;

/**
* @return \Znck\Eloquent\Relations\BelongsToThrough<\Tests\IdeHelper\Models\Country, $this>
*/
public function country(): BelongsToThroughRelation
{
return $this->belongsToThrough(Country::class, [User::class, Post::class]);
Expand Down
25 changes: 0 additions & 25 deletions tests/Models/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,15 @@
use Znck\Eloquent\Relations\BelongsToThrough;
use Znck\Eloquent\Traits\HasTableAlias;

/**
* @property int $id
*
* @property-read \Tests\Models\Country|null $country
*/
class Comment extends Model
{
use HasTableAlias;

/**
* @return \Znck\Eloquent\Relations\BelongsToThrough<\Tests\Models\Country, $this>
*/
public function country(): BelongsToThrough
{
return $this->belongsToThrough(Country::class, [User::class, Post::class])->withDefault();
}

/**
* @return \Znck\Eloquent\Relations\BelongsToThrough<\Tests\Models\Country, $this>
*/
public function countryWithCustomForeignKeys(): BelongsToThrough
{
return $this->belongsToThrough(
Expand All @@ -36,35 +25,21 @@ public function countryWithCustomForeignKeys(): BelongsToThrough
);
}

/**
* @return \Znck\Eloquent\Relations\BelongsToThrough<\Tests\Models\Country, $this>
*/
public function countryWithTrashedUser(): BelongsToThrough
{
/* @phpstan-ignore return.type */
return $this->country()->withTrashed(['users.deleted_at']);
}

/**
* @return \Znck\Eloquent\Relations\BelongsToThrough<\Tests\Models\Country, $this>
*/
public function countryWithPrefix(): BelongsToThrough
{
return $this->belongsToThrough(Country::class, [User::class, Post::class], null, 'custom_');
}

/**
* @return \Znck\Eloquent\Relations\BelongsToThrough<self, $this>
*/
public function grandparent(): BelongsToThrough
{
/* @phpstan-ignore argument.type */
return $this->belongsToThrough(self::class, self::class.' as alias', null, '', [self::class => 'parent_id']);
}

/**
* @return \Znck\Eloquent\Relations\BelongsToThrough<\Tests\Models\User, $this>
*/
public function user(): BelongsToThrough
{
return $this->belongsToThrough(User::class, Post::class);
Expand Down
3 changes: 0 additions & 3 deletions tests/Models/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace Tests\Models;

/**
* @property int $id
*/
class Country extends Model
{
//
Expand Down
3 changes: 0 additions & 3 deletions tests/Models/CustomerAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

class CustomerAddress extends Model
{
/**
* @return \Znck\Eloquent\Relations\BelongsToThrough<\Tests\Models\VendorCustomer, $this>
*/
public function vendorCustomer(): BelongsToThrough
{
return $this->belongsToThrough(
Expand Down
14 changes: 2 additions & 12 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ protected function setUp(): void
$this->seed();
}

/**
* Migrate the database.
*
* @return void
*/
protected function migrate()
protected function migrate(): void
{
DB::schema()->create('countries', function (Blueprint $table) {
$table->increments('id');
Expand Down Expand Up @@ -80,12 +75,7 @@ protected function migrate()
});
}

/**
* Seed the database.
*
* @return void
*/
protected function seed()
protected function seed(): void
{
Model::unguard();

Expand Down

0 comments on commit 9e2323e

Please sign in to comment.