Skip to content

Commit 62da1c0

Browse files
authored
[PHP 8.1] Add DowngradeOctalNumberRector (#187)
1 parent 9abc4ab commit 62da1c0

File tree

11 files changed

+214
-17
lines changed

11 files changed

+214
-17
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ phpstan.neon export-ignore
77
phpunit.xml export-ignore
88
tests export-ignore
99
rules-tests export-ignore
10-
/easy-ci.php export-ignore
1110
/rector.php export-ignore

config/set/downgrade-php81.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22

33
declare(strict_types=1);
4-
use Rector\DowngradePhp81\Rector\MethodCall\DowngradeIsEnumRector;
54

5+
use Rector\DowngradePhp81\Rector\LNumber\DowngradeOctalNumberRector;
6+
use Rector\DowngradePhp81\Rector\MethodCall\DowngradeIsEnumRector;
67
use Rector\Config\RectorConfig;
78
use Rector\Core\ValueObject\PhpVersion;
89
use Rector\DowngradePhp81\Rector\Array_\DowngradeArraySpreadStringKeyRector;
@@ -34,6 +35,7 @@
3435
DowngradeArrayIsListRector::class,
3536
DowngradeSetAccessibleReflectionPropertyRector::class,
3637
DowngradeIsEnumRector::class,
38+
DowngradeOctalNumberRector::class
3739
]);
3840

3941
// @see https://php.watch/versions/8.1/internal-method-return-types#reflection

docs/rector_rules_overview.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 70 Rules Overview
1+
# 71 Rules Overview
22

33
## ArrowFunctionToAnonymousFunctionRector
44

@@ -429,7 +429,7 @@ Downgrades `isEnum()` on class reflection
429429
public function run(ReflectionClass $reflectionClass)
430430
{
431431
- return $reflectionClass->isEnum();
432-
+ return false;
432+
+ return method_exists($reflectionClass, 'isEnum') ? $reflectionClass->isEnum() : false;
433433
}
434434
}
435435
```
@@ -736,6 +736,25 @@ Remove the "object" param and return type, add a `@param` and `@return` tags ins
736736

737737
<br>
738738

739+
## DowngradeOctalNumberRector
740+
741+
Downgrades octal numbers to decimal ones
742+
743+
- class: [`Rector\DowngradePhp81\Rector\LNumber\DowngradeOctalNumberRector`](../rules/DowngradePhp81/Rector/LNumber/DowngradeOctalNumberRector.php)
744+
745+
```diff
746+
class SomeClass
747+
{
748+
public function run()
749+
{
750+
- return 0o777;
751+
+ return 0777;
752+
}
753+
}
754+
```
755+
756+
<br>
757+
739758
## DowngradeParameterTypeWideningRector
740759

741760
Change param type to match the lowest type in whole family tree

easy-ci.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

ecs.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
__DIR__ . '/tests',
1919
__DIR__ . '/rules-tests',
2020
__DIR__ . '/ecs.php',
21-
__DIR__ . '/easy-ci.php',
2221
]);
2322

2423
$ecsConfig->ruleWithConfiguration(NoSuperfluousPhpdocTagsFixer::class, [
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\DowngradePhp81\Rector\LNumber\DowngradeOctalNumberRector;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class DowngradeOctalNumberRectorTest 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+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp81\Rector\LNumber\DowngradeOctalNumberRector\Fixture;
4+
5+
final class BiggerOu
6+
{
7+
public function run()
8+
{
9+
return 0O777;
10+
}
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\DowngradePhp81\Rector\LNumber\DowngradeOctalNumberRector\Fixture;
18+
19+
final class BiggerOu
20+
{
21+
public function run()
22+
{
23+
return 0777;
24+
}
25+
}
26+
27+
?>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp81\Rector\LNumber\DowngradeOctalNumberRector\Fixture;
4+
5+
final class SkipAnotherValues
6+
{
7+
public function run()
8+
{
9+
$result = '0O777';
10+
11+
$next = '0o77Oo7';
12+
13+
$binaryNumber = 0b1111;
14+
}
15+
}
16+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp81\Rector\LNumber\DowngradeOctalNumberRector\Fixture;
4+
5+
class SomeClass
6+
{
7+
public function run()
8+
{
9+
return 0o777;
10+
}
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\DowngradePhp81\Rector\LNumber\DowngradeOctalNumberRector\Fixture;
18+
19+
class SomeClass
20+
{
21+
public function run()
22+
{
23+
return 0777;
24+
}
25+
}
26+
27+
?>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
7+
use Rector\DowngradePhp81\Rector\LNumber\DowngradeOctalNumberRector;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->rule(DowngradeOctalNumberRector::class);
11+
};

0 commit comments

Comments
 (0)