Skip to content

Commit d2593a3

Browse files
committed
Rector upgrade
1 parent 974fc59 commit d2593a3

13 files changed

+37
-63
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
"illuminate/contracts": "11.*|10.*|^9.6"
2121
},
2222
"require-dev": {
23+
"larastan/larastan": "^2.0|^1.0",
2324
"laravel/pint": "^1.0",
2425
"nunomaduro/collision": "^8.0|^7.8|^6.0",
25-
"larastan/larastan": "^2.0|^1.0",
2626
"orchestra/testbench": "9.*|^8.0|^7.0",
2727
"pestphp/pest": "^2.20",
2828
"pestphp/pest-plugin-arch": "^2.6",
@@ -47,7 +47,7 @@
4747
"lint": "vendor/bin/pint",
4848
"test": "vendor/bin/pest",
4949
"test-coverage": "vendor/bin/pest coverage",
50-
"mod": "vendor/bin/rector"
50+
"fix": "vendor/bin/rector"
5151
},
5252
"config": {
5353
"sort-packages": true,

rector.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
// register a single rule
1616
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
1717
$rectorConfig->rules([
18-
\Rector\PHPUnit\Rector\Class_\AddSeeTestAnnotationRector::class,
19-
\Rector\PHPUnit\Rector\ClassMethod\ReplaceTestAnnotationWithPrefixedFunctionRector::class,
18+
\Rector\PHPUnit\PHPUnit100\Rector\Class_\PublicDataProviderClassMethodRector::class,
19+
\Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector::class,
20+
\Rector\PHPUnit\CodeQuality\Rector\Class_\AddSeeTestAnnotationRector::class,
21+
\Rector\PHPUnit\CodeQuality\Rector\ClassMethod\ReplaceTestAnnotationWithPrefixedFunctionRector::class,
2022
]);
2123

2224
// define sets of rules
2325
$rectorConfig->sets([
2426
LevelSetList::UP_TO_PHP_80,
2527
\Rector\Set\ValueObject\SetList::PHP_80,
26-
\Rector\PHPUnit\Set\PHPUnitLevelSetList::UP_TO_PHPUNIT_90,
27-
\Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_90,
28+
\Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_100,
2829

2930
]);
3031
};

src/FeatureFlagsServiceProvider.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,35 +96,27 @@ public function register(): void
9696
$this->app->singleton(FeaturesContract::class, Manager::class);
9797
}
9898

99-
$this->app->scoped(MaintenanceRepository::class, function (Container $app) {
100-
return new MaintenanceRepository($app->make(FeaturesContract::class), $app);
101-
});
102-
103-
$this->app->extend(MaintenanceModeManager::class, function (MaintenanceModeManager $manager) {
104-
return $manager->extend('features', function (): MaintenanceMode {
105-
return new MaintenanceDriver(
106-
$this->app->make(MaintenanceRepository::class)
107-
);
108-
});
109-
});
99+
$this->app->scoped(MaintenanceRepository::class, fn(Container $app) => new MaintenanceRepository($app->make(FeaturesContract::class), $app));
100+
101+
$this->app->extend(MaintenanceModeManager::class, fn(MaintenanceModeManager $manager) => $manager->extend('features', fn(): MaintenanceMode => new MaintenanceDriver(
102+
$this->app->make(MaintenanceRepository::class)
103+
)));
110104
}
111105

112106
protected function schedulingMacros()
113107
{
114108
if (! Event::hasMacro('skipWithoutFeature')) {
115109
/** @noRector \Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector */
116-
Event::macro('skipWithoutFeature', function (string $feature): Event {
110+
Event::macro('skipWithoutFeature', fn(string $feature): Event =>
117111
/** @var Event $this */
118-
return $this->skip(fn () => ! Features::accessible($feature));
119-
});
112+
$this->skip(fn () => ! Features::accessible($feature)));
120113
}
121114

122115
if (! Event::hasMacro('skipWithFeature')) {
123116
/** @noRector \Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector */
124-
Event::macro('skipWithFeature', function ($feature): Event {
117+
Event::macro('skipWithFeature', fn($feature): Event =>
125118
/** @var Event $this */
126-
return $this->skip(fn () => Features::accessible($feature));
127-
});
119+
$this->skip(fn () => Features::accessible($feature)));
128120
}
129121
}
130122

src/Gateways/GateGateway.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public function generateKey(string $feature): string
3434
return md5($feature);
3535
}
3636

37-
return implode(':', [md5($feature), get_class($model), $model->getKey()]);
37+
return implode(':', [md5($feature), $model::class, $model->getKey()]);
3838
}
3939
}

src/Support/MaintenanceScenario.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Illuminate\Contracts\Support\Arrayable;
66

7+
/**
8+
* @see \YlsIdeas\FeatureFlags\Tests\Support\MaintenanceScenarioTest
9+
*/
710
class MaintenanceScenario implements Arrayable
811
{
912
public string $feature;

tests/FeatureFlagsServiceProviderTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ protected function getPackageProviders($app): array
1818
];
1919
}
2020

21-
/**
22-
* @before
23-
*/
21+
#[\PHPUnit\Framework\Attributes\Before]
2422
protected function cleanUp(): void
2523
{
2624
$this->afterApplicationCreated(function () {

tests/MaintenanceModeTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ public function test_upon_activation()
7070
$this->assertTrue($called);
7171
}
7272

73-
/**
74-
* @dataProvider exceptsValues
75-
*/
73+
#[\PHPUnit\Framework\Attributes\DataProvider('exceptsValues')]
7674
public function test_maintenance_mode_respects_excepts_values(string $path, int $status)
7775
{
7876
Features::fake(['system.down' => true]);

tests/ManagerTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
use YlsIdeas\FeatureFlags\Events\FeatureSwitchedOn;
1616
use YlsIdeas\FeatureFlags\Manager;
1717

18-
/**
19-
* @covers \YlsIdeas\FeatureFlags\Manager
20-
*/
18+
#[\PHPUnit\Framework\Attributes\CoversClass(\YlsIdeas\FeatureFlags\Manager::class)]
2119
class ManagerTest extends TestCase
2220
{
2321
use MockeryPHPUnitIntegration;
@@ -141,9 +139,7 @@ public function test_it_can_turn_off_features(): void
141139
$manager->turnOff('test', 'my-feature');
142140
}
143141

144-
/**
145-
* @dataProvider services
146-
*/
142+
#[\PHPUnit\Framework\Attributes\DataProvider('services')]
147143
public function test_it_can_flag_parts_of_the_package_to_be_turned_off($item): void
148144
{
149145
$manager = new Manager($this->container, \Mockery::mock(Dispatcher::class));
@@ -155,7 +151,7 @@ public function test_it_can_flag_parts_of_the_package_to_be_turned_off($item): v
155151
$this->assertFalse($manager->{"uses$item"}());
156152
}
157153

158-
public function services(): array
154+
public static function services(): array
159155
{
160156
return [
161157
['Blade'],

tests/QueryBuilderMixinTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ protected function getPackageProviders($app): array
1717
];
1818
}
1919

20-
/**
21-
* @dataProvider positiveSqlStatements
22-
*/
20+
#[\PHPUnit\Framework\Attributes\DataProvider('positiveSqlStatements')]
2321
public function test_modifying_queries_when_the_feature_is_enabled(bool $flag, string $expectedSql)
2422
{
2523
Features::fake(['my-feature' => $flag]);
@@ -31,7 +29,7 @@ public function test_modifying_queries_when_the_feature_is_enabled(bool $flag, s
3129
$this->assertSame($expectedSql, $sql);
3230
}
3331

34-
public function positiveSqlStatements(): \Generator
32+
public static function positiveSqlStatements(): \Generator
3533
{
3634
yield 'flag is true' => [
3735
true,
@@ -43,9 +41,7 @@ public function positiveSqlStatements(): \Generator
4341
];
4442
}
4543

46-
/**
47-
* @dataProvider negativeSqlStatements
48-
*/
44+
#[\PHPUnit\Framework\Attributes\DataProvider('negativeSqlStatements')]
4945
public function test_modifying_queries_when_the_feature_is_not_enabled(bool $flag, string $expectedSql)
5046
{
5147
Features::fake(['my-feature' => $flag]);
@@ -57,7 +53,7 @@ public function test_modifying_queries_when_the_feature_is_not_enabled(bool $fla
5753
$this->assertSame($expectedSql, $sql);
5854
}
5955

60-
public function negativeSqlStatements(): \Generator
56+
public static function negativeSqlStatements(): \Generator
6157
{
6258
yield 'flag is true' => [
6359
true,

tests/Support/FeatureFakeTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ public function test_it_can_be_fake_accessibility_results_from_the_container()
5252
Event::fake();
5353
Features::fake(['my-feature' => true]);
5454

55-
$this->assertTrue(app()->call(function (FeaturesContract $accessible): bool {
56-
return $accessible->accessible('my-feature');
57-
}));
55+
$this->assertTrue(app()->call(fn(FeaturesContract $accessible): bool => $accessible->accessible('my-feature')));
5856
}
5957

6058
public function test_it_can_be_fake_accessibility_results_if_no_value_is_provided()

tests/Support/FeatureFilterTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,30 @@ public function test_it_can_be_initialised(): void
1414
$this->assertInstanceOf(FeatureFilter::class, $component);
1515
}
1616

17-
/**
18-
* @dataProvider successfulPatterns
19-
*/
17+
#[\PHPUnit\Framework\Attributes\DataProvider('successfulPatterns')]
2018
public function test_it_fails_filters_correctly(string $feature, array $filters): void
2119
{
2220
$component = new FeatureFilter($filters);
2321

2422
$this->assertTrue($component->fails($feature));
2523
}
2624

27-
/**
28-
* @dataProvider failurePatterns
29-
*/
25+
#[\PHPUnit\Framework\Attributes\DataProvider('failurePatterns')]
3026
public function test_it_does_not_fail_filters_correctly(string $feature, array $filters): void
3127
{
3228
$component = new FeatureFilter($filters);
3329

3430
$this->assertFalse($component->fails($feature));
3531
}
3632

37-
public function successfulPatterns(): \Generator
33+
public static function successfulPatterns(): \Generator
3834
{
3935
yield 'simple' => ['my-feature', ['system.*']];
4036
yield 'advanced' => ['my-feature', ['system.*', 'my-feature-1.*']];
4137
yield 'more advanced' => ['my-feature', ['system.*', '!my-feature']];
4238
}
4339

44-
public function failurePatterns(): \Generator
40+
public static function failurePatterns(): \Generator
4541
{
4642
yield 'simple' => ['my-feature.1', ['my-feature.*']];
4743
}

tests/Support/GatewayInspectorTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ public function test_it_sets_results_in_the_action(): void
177177
$this->assertFalse($action->getResult());
178178
}
179179

180-
/**
181-
* @dataProvider debugScenarios
182-
*/
180+
#[\PHPUnit\Framework\Attributes\DataProvider('debugScenarios')]
183181
public function test_it_provides_debug_information(callable $constructs, callable $assert, ?bool $result = null)
184182
{
185183
$action = new ActionableFlag();

tests/Support/MaintenanceScenarioTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
class MaintenanceScenarioTest extends TestCase
99
{
10-
/**
11-
* @dataProvider scenarioOptions
12-
*/
10+
#[\PHPUnit\Framework\Attributes\DataProvider('scenarioOptions')]
1311
public function test_it_builds_a_maintenance_scenario(callable $builder, bool $polarity, array $result)
1412
{
1513
$scenario = new MaintenanceScenario();
@@ -20,7 +18,7 @@ public function test_it_builds_a_maintenance_scenario(callable $builder, bool $p
2018
$this->assertSame($result, $scenario->toArray());
2119
}
2220

23-
public function scenarioOptions(): \Generator
21+
public static function scenarioOptions(): \Generator
2422
{
2523
yield 'secret' => [
2624
fn (MaintenanceScenario $scenario): MaintenanceScenario => $scenario

0 commit comments

Comments
 (0)