Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfox committed Jan 21, 2025
1 parent 1065e75 commit 6ca2aec
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 73 deletions.
8 changes: 4 additions & 4 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
__DIR__ . '/tests',
])
// uncomment to reach your current PHP version
// ->withPhpSets()
->withTypeCoverageLevel(0)
->withDeadCodeLevel(0)
->withCodeQualityLevel(0);
->withPhpSets(php82: true)
->withTypeCoverageLevel(1024)
->withDeadCodeLevel(1024)
->withCodeQualityLevel(1024);
2 changes: 1 addition & 1 deletion src/ActionableFlag.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function isDebuggable(): bool
return (bool) $this->debug;
}

public function storeInspectionInformation(string $pipe, string $reason, ?bool $result = null)
public function storeInspectionInformation(string $pipe, string $reason, ?bool $result = null): void
{
$this->debug->addDecision($pipe, $reason, $result);
}
Expand Down
8 changes: 4 additions & 4 deletions src/FeatureFlagsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FeatureFlagsServiceProvider extends ServiceProvider
/**
* Bootstrap the application services.
*/
public function boot()
public function boot(): void
{
if ($this->app->runningInConsole()) {
$this->publishes([
Expand Down Expand Up @@ -96,7 +96,7 @@ public function register(): void
$this->app->singleton(FeaturesContract::class, Manager::class);
}

$this->app->scoped(MaintenanceRepository::class, fn (Container $app) => new MaintenanceRepository($app->make(FeaturesContract::class), $app));
$this->app->scoped(MaintenanceRepository::class, fn (Container $app): \YlsIdeas\FeatureFlags\Support\MaintenanceRepository => new MaintenanceRepository($app->make(FeaturesContract::class), $app));

$this->app->extend(MaintenanceModeManager::class, fn (MaintenanceModeManager $manager) => $manager->extend('features', fn (): MaintenanceMode => new MaintenanceDriver(
$this->app->make(MaintenanceRepository::class)
Expand All @@ -109,7 +109,7 @@ protected function schedulingMacros()
/** @noRector \Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector */
Event::macro('skipWithoutFeature', fn (string $feature): Event =>
/** @var Event $this */
$this->skip(fn () => ! Features::accessible($feature)));
$this->skip(fn (): bool => ! Features::accessible($feature)));
}

if (! Event::hasMacro('skipWithFeature')) {
Expand Down Expand Up @@ -141,7 +141,7 @@ protected function aboutCommandInfo(): void
{
if (class_exists(AboutCommand::class)) {
AboutCommand::add('Feature Flags', [
'Pipeline' => fn () => implode(', ', config('features.pipeline')),
'Pipeline' => fn (): string => implode(', ', config('features.pipeline')),
]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function pipeline(): Pipeline
*/
public function accessible(string $feature): bool
{
if ($this->expiredFeaturesHandler) {
if ($this->expiredFeaturesHandler instanceof \YlsIdeas\FeatureFlags\Contracts\ExpiredFeaturesHandler) {
$this->expiredFeaturesHandler->isExpired($feature);
}

Expand Down Expand Up @@ -289,7 +289,7 @@ protected function pipes(): array
$pipes = $this->container->make(Repository::class)->get('features.pipeline');

return collect($pipes)
->map(fn (string $pipe) => $this->resolve($pipe))
->map(fn (string $pipe): \YlsIdeas\FeatureFlags\Support\GatewayInspector => $this->resolve($pipe))
->all();
}

Expand Down
6 changes: 3 additions & 3 deletions src/Support/FeatureFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function accessible(string $feature): bool
return $featureValue;
}

public function assertAccessed(string $feature, ?int $count = null, string $message = '')
public function assertAccessed(string $feature, ?int $count = null, string $message = ''): void
{
if ($count === null) {
Assert::assertGreaterThan(0, $this->getCount($feature), $message);
Expand All @@ -59,12 +59,12 @@ public function assertAccessed(string $feature, ?int $count = null, string $mess
}
}

public function assertNotAccessed(string $feature, string $message = '')
public function assertNotAccessed(string $feature, string $message = ''): void
{
Assert::assertLessThan(1, $this->getCount($feature), $message);
}

public function assertAccessedCount(string $feature, int $count = 0, string $message = '')
public function assertAccessedCount(string $feature, int $count = 0, string $message = ''): void
{
$this->assertAccessed($feature, $count, $message);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Support/GatewayCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function delete(string $feature): void
$this->repository->delete($this->generateKey($feature));
}

public function generateKey($feature)
public function generateKey(string $feature): string
{
return $this->namespace . ':' . $this->cacheable->generateKey($feature);
}
Expand Down
11 changes: 4 additions & 7 deletions src/Support/MaintenanceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public function callDeactivation(): void
$this->container->call($this->uponDeactivation, ['features' => $this->features]);
}

public function onEnabled($feature): MaintenanceScenario
public function onEnabled(string $feature): MaintenanceScenario
{
return tap((new MaintenanceScenario())->whenEnabled($feature), function (MaintenanceScenario $scenario): void {
$this->scenarios[] = $scenario;
});
}

public function onDisabled($feature): MaintenanceScenario
public function onDisabled(string $feature): MaintenanceScenario
{
return tap((new MaintenanceScenario())->whenDisabled($feature), function (MaintenanceScenario $scenario): void {
$this->scenarios[] = $scenario;
Expand All @@ -75,15 +75,12 @@ public function parameters(): ?array
protected function findScenario(): ?MaintenanceScenario
{
return $this->foundScenario = collect($this->scenarios)
->first(function (MaintenanceScenario $scenario) {
->first(function (MaintenanceScenario $scenario): bool {
if ($scenario->onEnabled && $this->features->accessible($scenario->feature)) {
return true;
}
if (! $scenario->onEnabled && ! $this->features->accessible($scenario->feature)) {
return true;
}

return false;
return ! $scenario->onEnabled && ! $this->features->accessible($scenario->feature);
});
}
}
4 changes: 2 additions & 2 deletions tests/GatewayDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected function getPackageProviders($app): array
];
}

public function test_throws_exception_creating_a_gateway_driver()
public function test_throws_exception_creating_a_gateway_driver(): void
{
config()->set('features.pipeline', ['gate']);
config()->set('features.gateways', [
Expand All @@ -30,7 +30,7 @@ public function test_throws_exception_creating_a_gateway_driver()
$this->app->make(Manager::class)->pipeline();
}

public function test_create_a_gateway_driver()
public function test_create_a_gateway_driver(): void
{
config()->set('features.pipeline', ['gate']);
config()->set('features.gateways', [
Expand Down
2 changes: 1 addition & 1 deletion tests/Gateways/DatabaseGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function test_it_can_store_the_state_of_features_switched_on(): void
->andReturn($query);

$query->shouldReceive('updateOrInsert')
->withArgs(function ($find, $data) {
->withArgs(function (array $find, array $data): true {
$this->assertArrayHasKey('feature', $find);
$this->assertArrayHasKey('active_at', $data);

Expand Down
22 changes: 11 additions & 11 deletions tests/MaintenanceModeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,35 @@

class MaintenanceModeTest extends TestCase
{
public function test_maintenance_mode_enabled()
public function test_maintenance_mode_enabled(): void
{
Features::fake(['system.down' => true]);
Features::maintenanceMode()
->onEnabled('system.down');

Route::get('/', fn () => 'Foo Bar');
Route::get('/', fn (): string => 'Foo Bar');

$this->get('/')
->assertServiceUnavailable();

Features::assertAccessed('system.down');
}

public function test_maintenance_mode_disabled()
public function test_maintenance_mode_disabled(): void
{
Features::fake(['system.down' => false]);
Features::maintenanceMode()
->onEnabled('system.down');

Route::get('/', fn () => 'Foo Bar');
Route::get('/', fn (): string => 'Foo Bar');

$this->get('/')
->assertOk();

Features::assertAccessed('system.down');
}

public function test_it_handles_the_first_match()
public function test_it_handles_the_first_match(): void
{
Features::fake(['system.api' => true,]);
Features::maintenanceMode()
Expand All @@ -52,7 +52,7 @@ public function test_it_handles_the_first_match()
->onEnabled('system.api')
->statusCode(500);

Route::get('/', fn () => 'Foo Bar');
Route::get('/', fn (): string => 'Foo Bar');

$this->get('/')
->assertStatus(500);
Expand All @@ -61,7 +61,7 @@ public function test_it_handles_the_first_match()
Features::assertAccessed('system.api');
}

public function test_upon_activation()
public function test_upon_activation(): void
{
$called = false;
Features::maintenanceMode()
Expand All @@ -75,15 +75,15 @@ public function test_upon_activation()
}

#[\PHPUnit\Framework\Attributes\DataProvider('exceptsValues')]
public function test_maintenance_mode_respects_excepts_values(string $path, int $status)
public function test_maintenance_mode_respects_excepts_values(string $path, int $status): void
{
Features::fake(['system.down' => true]);
Features::maintenanceMode()
->onEnabled('system.down')
->exceptPaths(['/test']);

Route::get('/', fn () => 'Foo Bar');
Route::get('/test', fn () => 'Foo Bar Foo');
Route::get('/', fn (): string => 'Foo Bar');
Route::get('/test', fn (): string => 'Foo Bar Foo');

$this
->withoutExceptionHandling([\Symfony\Component\HttpKernel\Exception\HttpException::class])
Expand All @@ -103,7 +103,7 @@ public static function exceptsValues(): \Generator
];
}

public function test_upon_deactivation()
public function test_upon_deactivation(): void
{
$called = false;
Features::fake(['system.down' => true]);
Expand Down
2 changes: 1 addition & 1 deletion tests/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function test_it_can_turn_off_features(): void
}

#[\PHPUnit\Framework\Attributes\DataProvider('services')]
public function test_it_can_flag_parts_of_the_package_to_be_turned_off($item): void
public function test_it_can_flag_parts_of_the_package_to_be_turned_off(string $item): void
{
$manager = new Manager($this->container, \Mockery::mock(Dispatcher::class));

Expand Down
2 changes: 1 addition & 1 deletion tests/Middlewares/GuardFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function test_it_continues_the_chain_if_features_are_accessible(): void

$this->assertTrue($middleware->handle(
$expectedRequest,
function ($request) use ($expectedRequest) {
function ($request) use ($expectedRequest): true {
$this->assertSame($expectedRequest, $request);

return true;
Expand Down
4 changes: 2 additions & 2 deletions tests/QueryBuilderMixinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function getPackageProviders($app): array
}

#[\PHPUnit\Framework\Attributes\DataProvider('positiveSqlStatements')]
public function test_modifying_queries_when_the_feature_is_enabled(bool $flag, string $expectedSql)
public function test_modifying_queries_when_the_feature_is_enabled(bool $flag, string $expectedSql): void
{
// Laravel 11 for some reason changed how SQL is generated
if (! InstalledVersions::satisfies(new VersionParser(), 'illuminate/contracts', '^11.0')) {
Expand Down Expand Up @@ -49,7 +49,7 @@ public static function positiveSqlStatements(): \Generator
}

#[\PHPUnit\Framework\Attributes\DataProvider('negativeSqlStatements')]
public function test_modifying_queries_when_the_feature_is_not_enabled(bool $flag, string $expectedSql)
public function test_modifying_queries_when_the_feature_is_not_enabled(bool $flag, string $expectedSql): void
{
// Laravel 11 for some reason changed how SQL is generated
if (! InstalledVersions::satisfies(new VersionParser(), 'illuminate/contracts', '^11.0')) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Support/ActionDebugLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

class ActionDebugLogTest extends TestCase
{
public function test_it_stores_the_file_and_line_location()
public function test_it_stores_the_file_and_line_location(): void
{
$log = new ActionDebugLog('test.php', 10);

$this->assertSame(10, $log->line);
$this->assertSame('test.php', $log->file);
}

public function test_it_stores_the_log_entries()
public function test_it_stores_the_log_entries(): void
{
$log = new ActionDebugLog('test.php', 10);

Expand Down
Loading

0 comments on commit 6ca2aec

Please sign in to comment.