Skip to content

Commit

Permalink
[1.x] Improve typing checks (#126)
Browse files Browse the repository at this point in the history
* Allow control over feature serialization

* Remove driver from contract

* Improve typing

* Fix types

* Coding style

* Fix CI
  • Loading branch information
timacdonald authored Nov 9, 2024
1 parent 42f96b6 commit 457cc52
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ on: [push]
jobs:
lint:
uses: laravel/.github/.github/workflows/coding-standards.yml@main
with:
php: "8.3"
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ parameters:
- database
- src

level: 0
level: 5
4 changes: 2 additions & 2 deletions src/Drivers/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function getAll($features): array
return false;
}

$inserts[] = [
$inserts[] = [ // @phpstan-ignore offsetAssign.valueType
'name' => $feature,
'scope' => $scope,
'value' => $value,
Expand All @@ -176,7 +176,7 @@ public function getAll($features): array
});
})->all())->all();

if ($inserts->isNotEmpty()) {
if ($inserts->isNotEmpty()) { // @phpstan-ignore method.impossibleType
try {
$this->insertMany($inserts->all());
} catch (UniqueConstraintViolationException $e) {
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Decorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function define($feature, $resolver = null): void
$this->driver->define($feature, function ($scope) use ($feature, $resolver) {
if ($resolver instanceof LazilyResolvedFeature) {
$resolver = with($this->container[$resolver->feature], fn ($instance) => method_exists($instance, 'resolve')
? $instance->resolve(...)
? $instance->resolve(...) // @phpstan-ignore callable.nonNativeMethod
: $instance(...));
}

Expand Down
1 change: 0 additions & 1 deletion src/Events/FeatureUpdatedForAllScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class FeatureUpdatedForAllScopes
* Create a new event instance.
*
* @param string $feature
* @param mixed $scope
* @param mixed $value
*/
public function __construct($feature, $value)
Expand Down
4 changes: 2 additions & 2 deletions src/PendingScopedFeatureInteraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function loadMissing($features)
public function loadAll()
{
return $this->load(
$this->driver->definedFeaturesForScope($this->scope()[0])
$this->driver->definedFeaturesForScope($this->scope()[0])->all()
);
}

Expand Down Expand Up @@ -122,7 +122,7 @@ public function values($features)
public function all()
{
return $this->values(
$this->driver->definedFeaturesForScope($this->scope()[0])
$this->driver->definedFeaturesForScope($this->scope()[0])->all()
);
}

Expand Down
4 changes: 0 additions & 4 deletions tests/Feature/DatabaseDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace Tests\Feature;

use Exception;
use Illuminate\Contracts\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Database\UniqueConstraintViolationException;
Expand All @@ -22,13 +20,11 @@
use Laravel\Pennant\Events\FeatureDeleted;
use Laravel\Pennant\Events\FeatureResolved;
use Laravel\Pennant\Events\FeaturesPurged;
use Laravel\Pennant\Events\FeatureUnavailableForScope;
use Laravel\Pennant\Events\FeatureUpdated;
use Laravel\Pennant\Events\FeatureUpdatedForAllScopes;
use Laravel\Pennant\Events\UnexpectedNullScopeEncountered;
use Laravel\Pennant\Events\UnknownFeatureResolved;
use Laravel\Pennant\Feature;
use Laravel\Pennant\FeatureDoesNotMatchScope;
use RuntimeException;
use Tests\TestCase;
use Workbench\App\Models\Team;
Expand Down

0 comments on commit 457cc52

Please sign in to comment.