Skip to content

Commit

Permalink
Increase PHPStan level
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Aug 28, 2024
1 parent eeb9916 commit 46c24fa
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 17 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^3.0",
"larastan/larastan": "^2.9",
"orchestra/testbench": "^9.0",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^11.0",
Expand Down
6 changes: 5 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
includes:
- ./vendor/larastan/larastan/extension.neon
parameters:
level: 0
level: 1
paths:
- src
- tests
ignoreErrors:
- "#Called 'first' on Laravel collection, but could have been retrieved as a query.#"
- '#Call to private method take\(\) of parent class Illuminate\\Database\\Eloquent\\Relations\\BelongsTo#'
- '#Unsafe usage of new static\(\).#'
4 changes: 2 additions & 2 deletions src/HasJsonRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ protected function addHasManyThroughJsonPivotRelationship(
/** @var \Staudenmeir\EloquentJsonRelations\Relations\HasManyJson $hasManyJson */
$hasManyJson = $relationships[0];

$postGetCallback = function (Collection $models) use ($hasManyJson, $relationships) {
$postGetCallback = function (Collection $models) use ($hasManyJson) {
if (isset($models[0]->laravel_through_key)) {
$hasManyJson->hydratePivotRelation(
$models,
Expand All @@ -440,7 +440,7 @@ protected function addHasManyThroughJsonPivotRelationship(
}

$hasManyThroughJson->withCustomEagerMatchingCallback(
function (array $models, Collection $results, string $relation) use ($hasManyJson, $hasManyThroughJson) {
function (array $models, Collection $results, string $relation) use ($hasManyJson) {
foreach ($models as $model) {
$hasManyJson->hydratePivotRelation(
$model->$relation,
Expand Down
4 changes: 2 additions & 2 deletions tests/BelongsToJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public function testLazyLoadingWithObjects(string $relation)

public function testEmptyLazyLoading()
{
DB::enableQueryLog();
DB::connection()->enableQueryLog();

$roles = (new User())->roles;

$this->assertInstanceOf(Collection::class, $roles);
$this->assertEmpty(DB::getQueryLog());
$this->assertEmpty(DB::connection()->getQueryLog());
}

public function testFirst()
Expand Down
4 changes: 2 additions & 2 deletions tests/CompositeKeys/BelongsToJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function testLazyLoadingWithObjects()

public function testEmptyLazyLoading()
{
DB::enableQueryLog();
DB::connection()->enableQueryLog();

$tasks = (new Employee())->tasks;

$this->assertInstanceOf(Collection::class, $tasks);
$this->assertEmpty(DB::getQueryLog());
$this->assertEmpty(DB::connection()->getQueryLog());
}

public function testEagerLoading()
Expand Down
4 changes: 2 additions & 2 deletions tests/CompositeKeys/HasManyJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public function testLazyLoadingWithObjects()

public function testEmptyLazyLoading()
{
DB::enableQueryLog();
DB::connection()->enableQueryLog();

$employees = (new Task())->employees;

$this->assertInstanceOf(Collection::class, $employees);
$this->assertEmpty(DB::getQueryLog());
$this->assertEmpty(DB::connection()->getQueryLog());
}

public function testEagerLoading()
Expand Down
4 changes: 2 additions & 2 deletions tests/CompositeKeys/HasOneJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public function testLazyLoadingWithObjects()

public function testEmptyLazyLoading()
{
DB::enableQueryLog();
DB::connection()->enableQueryLog();

$employee = (new Task())->employee;

$this->assertNull($employee);
$this->assertEmpty(DB::getQueryLog());
$this->assertEmpty(DB::connection()->getQueryLog());
}

public function testEagerLoading()
Expand Down
4 changes: 2 additions & 2 deletions tests/Concatenation/HasManyThroughJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ public function testEmptyLazyLoading()

public function testEmptyLazyLoadingWithReverseRelationship()
{
DB::enableQueryLog();
DB::connection()->enableQueryLog();

$roles = (new Project())->roles;

$this->assertInstanceOf(Collection::class, $roles);
$this->assertEmpty(DB::getQueryLog());
$this->assertEmpty(DB::connection()->getQueryLog());
}

public function testEagerLoading()
Expand Down
4 changes: 2 additions & 2 deletions tests/HasManyJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public function testLazyLoadingWithObjects(string $relation)

public function testEmptyLazyLoading()
{
DB::enableQueryLog();
DB::connection()->enableQueryLog();

$users = (new Role())->users;

$this->assertInstanceOf(Collection::class, $users);
$this->assertEmpty(DB::getQueryLog());
$this->assertEmpty(DB::connection()->getQueryLog());
}

public function testFirst()
Expand Down
4 changes: 2 additions & 2 deletions tests/HasOneJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public function testLazyLoadingWithObjects(string $relation)

public function testEmptyLazyLoading()
{
DB::enableQueryLog();
DB::connection()->enableQueryLog();

$user = (new Role())->user;

$this->assertNull($user);
$this->assertEmpty(DB::getQueryLog());
$this->assertEmpty(DB::connection()->getQueryLog());
}

public function testLazyLoadingWithDefault()
Expand Down

0 comments on commit 46c24fa

Please sign in to comment.