File tree Expand file tree Collapse file tree 5 files changed +149
-0
lines changed
tests/Rector/FuncCall/NotFilledBlankFuncCallToBlankFilledFuncCallRector Expand file tree Collapse file tree 5 files changed +149
-0
lines changed Original file line number Diff line number Diff line change @@ -403,6 +403,25 @@ Change minutes argument to seconds in `Illuminate\Contracts\Cache\Store` and Ill
403
403
404
404
<br >
405
405
406
+ ## NotFilledBlankFuncCallToBlankFilledFuncCallRector
407
+
408
+ Change ` !blank() ` func calls to ` filled() ` func calls and vice versa.
409
+
410
+ - class: [ ` RectorLaravel\Rector\FuncCall\NotFilledBlankFuncCallToBlankFilledFuncCallRector ` ] ( ../src/Rector/FuncCall/NotFilledBlankFuncCallToBlankFilledFuncCallRector.php )
411
+
412
+ ``` diff
413
+ class SomeClass
414
+ {
415
+ public function run()
416
+ {
417
+ - return !blank($value);
418
+ + return filled($value);
419
+ }
420
+ }
421
+ ```
422
+
423
+ <br >
424
+
406
425
## NowFuncWithStartOfDayMethodCallToTodayFuncRector
407
426
408
427
Changes the user of ` now()->startOfDay() ` to be replaced with ` today() ` .
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace RectorLaravel \Rector \FuncCall ;
4
+
5
+ use PhpParser \Node ;
6
+ use PhpParser \Node \Expr \BooleanNot ;
7
+ use Rector \Core \Rector \AbstractRector ;
8
+ use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
9
+ use Symplify \RuleDocGenerator \ValueObject \RuleDefinition ;
10
+
11
+ /**
12
+ * @see \RectorLaravel\Tests\Rector\FuncCall\NotFilledBlankFuncCallToBlankFilledFuncCallRector\NotFilledBlankFuncCallToBlankFilledFuncCallRectorTest
13
+ */
14
+ class NotFilledBlankFuncCallToBlankFilledFuncCallRector extends AbstractRector
15
+ {
16
+
17
+ public function getRuleDefinition (): RuleDefinition
18
+ {
19
+ return new RuleDefinition (
20
+ 'Swap the use of NotBooleans used with filled() and blank() to the correct helper. ' ,
21
+ [
22
+ new CodeSample (
23
+ <<<'CODE_SAMPLE'
24
+ !filled([]);
25
+ !blank([]);
26
+ CODE_SAMPLE
27
+ ,
28
+ <<<'CODE_SAMPLE'
29
+ blank([]);
30
+ filled([]);
31
+ CODE_SAMPLE
32
+ ),
33
+
34
+ ]
35
+ );
36
+ }
37
+
38
+ public function getNodeTypes (): array
39
+ {
40
+ return [BooleanNot::class];
41
+ }
42
+
43
+ /**
44
+ * @param BooleanNot $node
45
+ */
46
+ public function refactor (Node $ node ): ?Node \Expr \FuncCall
47
+ {
48
+ if (! $ node ->expr instanceof Node \Expr \FuncCall) {
49
+ return null ;
50
+ }
51
+
52
+ if (
53
+ ! $ this ->isName ($ node ->expr ->name , 'filled ' ) &&
54
+ ! $ this ->isName ($ node ->expr ->name , 'blank ' )
55
+ ) {
56
+ return null ;
57
+ }
58
+
59
+ $ method = $ this ->isName ($ node ->expr ->name , 'filled ' ) ? 'blank ' : 'filled ' ;
60
+ return $ this ->nodeFactory ->createFuncCall ($ method , $ node ->expr ->args );
61
+ }
62
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace RectorLaravel \Tests \Rector \FuncCall \NotFilledBlankFuncCallToBlankFilledFuncCallRector \Fixture ;
4
+
5
+ class Fixture
6
+ {
7
+ public function run ()
8
+ {
9
+ !filled ([]);
10
+ !blank ([]);
11
+ }
12
+ }
13
+
14
+ ?>
15
+ -----
16
+ <?php
17
+
18
+ namespace RectorLaravel \Tests \Rector \FuncCall \NotFilledBlankFuncCallToBlankFilledFuncCallRector \Fixture ;
19
+
20
+ class Fixture
21
+ {
22
+ public function run ()
23
+ {
24
+ blank ([]);
25
+ filled ([]);
26
+ }
27
+ }
28
+
29
+ ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace RectorLaravel \Tests \Rector \FuncCall \NotFilledBlankFuncCallToBlankFilledFuncCallRector ;
6
+
7
+ use Iterator ;
8
+ use PHPUnit \Framework \Attributes \DataProvider ;
9
+ use Rector \Testing \PHPUnit \AbstractRectorTestCase ;
10
+
11
+ final class NotFilledBlankFuncCallToBlankFilledFuncCallRectorTest extends AbstractRectorTestCase
12
+ {
13
+ #[DataProvider('provideData ' )]
14
+ public function test (string $ filePath ): void
15
+ {
16
+ $ this ->doTestFile ($ filePath );
17
+ }
18
+
19
+ public static function provideData (): Iterator
20
+ {
21
+ return self ::yieldFilesFromDirectory (__DIR__ . '/Fixture ' );
22
+ }
23
+
24
+ public function provideConfigFilePath (): string
25
+ {
26
+ return __DIR__ . '/config/configured_rule.php ' ;
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ use Rector \Config \RectorConfig ;
6
+
7
+ return static function (RectorConfig $ rectorConfig ): void {
8
+ $ rectorConfig ->import (__DIR__ . '/../../../../../config/config.php ' );
9
+
10
+ $ rectorConfig ->rule (\RectorLaravel \Rector \FuncCall \NotFilledBlankFuncCallToBlankFilledFuncCallRector::class);
11
+ };
You can’t perform that action at this time.
0 commit comments