Skip to content

Commit

Permalink
Update src/Execution/ModelsLoader/CountModelsLoader.php
Browse files Browse the repository at this point in the history
Co-authored-by: Benedikt Franke <benedikt@franke.tech>
  • Loading branch information
robsontenorio and spawnia authored Jan 3, 2025
1 parent 94d1350 commit 260c1c1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Execution/ModelsLoader/CountModelsLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ public static function extractCount(Model $model, string $relationName): int
*/
$countAttributeName = Str::snake("{$relationName}_count");

$count = (int) $model->getAttribute($countAttributeName);
assert(is_int($count), 'avoid runtime check in production since the return type validates this anyway');
$count = $model->getAttribute($countAttributeName);
if (! is_numeric($count)) {
$nonNumericCount = Utils::printSafe($count);
throw new \Exception('Expected numeric count, got: {$nonNumericCount}.");

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.0 with Laravel ^9 and highest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^10 and highest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^11 and lowest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^10 and highest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^11 and highest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^9 and highest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.3 with Laravel ^10 and highest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^9 and highest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^10 and lowest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^9 and lowest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.0 with Laravel ^9 and lowest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.3 with Laravel ^11 and lowest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^9 and lowest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.3 with Laravel ^11 and highest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.3 with Laravel ^9 and highest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.3 with Laravel ^10 and lowest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^10 and lowest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38

Check failure on line 38 in src/Execution/ModelsLoader/CountModelsLoader.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.3 with Laravel ^9 and lowest dependencies

Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 38
}

return $count;
return (int) $count;
}
}

0 comments on commit 260c1c1

Please sign in to comment.