Skip to content

Commit a836483

Browse files
committed
bug #4787 NoUnneededFinalMethodFixer - Mark as risky (SpacePossum)
This PR was merged into the 2.15 branch. Discussion ---------- NoUnneededFinalMethodFixer - Mark as risky closes #4771 Commits ------- e9e586f NoUnneededFinalMethodFixer - mark as risky
2 parents 42a6d52 + e9e586f commit a836483

File tree

11 files changed

+117
-19
lines changed

11 files changed

+117
-19
lines changed

README.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,11 +1157,13 @@ Choose from the list of available rules:
11571157
- ``namespaces`` (``bool``): remove unneeded curly braces from bracketed
11581158
namespaces; defaults to ``false``
11591159

1160-
* **no_unneeded_final_method** [@Symfony, @PhpCsFixer]
1160+
* **no_unneeded_final_method** [@Symfony:risky, @PhpCsFixer:risky]
11611161

1162-
A ``final`` class must not have ``final`` methods and ``private`` method must
1162+
A ``final`` class must not have ``final`` methods and ``private`` methods must
11631163
not be ``final``.
11641164

1165+
*Risky rule: risky when child class overrides a ``private`` method.*
1166+
11651167
* **no_unreachable_default_argument_value** [@PhpCsFixer:risky]
11661168

11671169
In function arguments there must not be arguments with default values

src/Fixer/ClassNotation/NoUnneededFinalMethodFixer.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,26 @@ final class NoUnneededFinalMethodFixer extends AbstractFixer
2828
public function getDefinition()
2929
{
3030
return new FixerDefinition(
31-
'A `final` class must not have `final` methods and `private` method must not be `final`.',
31+
'A `final` class must not have `final` methods and `private` methods must not be `final`.',
3232
[
3333
new CodeSample(
3434
'<?php
35-
final class Foo {
36-
final public function foo() {}
35+
final class Foo
36+
{
37+
final public function foo1() {}
3738
final protected function bar() {}
3839
final private function baz() {}
3940
}
40-
'
41-
),
42-
new CodeSample(
43-
'<?php
44-
class Foo {
45-
final private function bar() {}
41+
42+
class Bar
43+
{
44+
final private function bar1() {}
4645
}
4746
'
4847
),
49-
]
48+
],
49+
null,
50+
'Risky when child class overrides a `private` method.'
5051
);
5152
}
5253

@@ -58,6 +59,11 @@ public function isCandidate(Tokens $tokens)
5859
return $tokens->isAllTokenKindsFound([T_CLASS, T_FINAL]);
5960
}
6061

62+
public function isRisky()
63+
{
64+
return true;
65+
}
66+
6167
/**
6268
* {@inheritdoc}
6369
*/

src/RuleSet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ final class RuleSet implements RuleSetInterface
108108
'no_trailing_comma_in_singleline_array' => true,
109109
'no_unneeded_control_parentheses' => true,
110110
'no_unneeded_curly_braces' => ['namespaces' => true],
111-
'no_unneeded_final_method' => true,
112111
'no_unused_imports' => true,
113112
'no_whitespace_before_comma_in_array' => true,
114113
'no_whitespace_in_blank_line' => true,
@@ -206,6 +205,7 @@ final class RuleSet implements RuleSetInterface
206205
],
207206
'no_alias_functions' => true,
208207
'no_homoglyph_names' => true,
208+
'no_unneeded_final_method' => true,
209209
'non_printable_character' => true,
210210
'php_unit_construct' => true,
211211
'php_unit_mock_short_will_return' => true,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--TEST--
2+
Integration of @Symfony:risky.
3+
--RULESET--
4+
{"@Symfony:risky": true}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Acme;
13+
14+
declare(ticks=1);
15+
16+
final class FinalClass
17+
{
18+
final function finalMethod(){}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Acme;
13+
14+
declare(ticks=1);
15+
16+
final class FinalClass
17+
{
18+
function finalMethod(){}
19+
}

tests/Fixtures/Integration/set/@Symfony.test-in.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function testFooBar($a)
112112
}
113113
}
114114

115-
final class finalClass
115+
final class FinalClass
116116
{
117117
final function finalMethod(){}
118118
}

tests/Fixtures/Integration/set/@Symfony.test-out.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ public function testFooBar($a)
107107
}
108108
}
109109

110-
final class finalClass
110+
final class FinalClass
111111
{
112-
public function finalMethod()
112+
final public function finalMethod()
113113
{
114114
}
115115
}

tests/Fixtures/Integration/set/@Symfony_whitespaces.test-in.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function testFooBar($a)
112112
}
113113
}
114114

115-
final class finalClass
115+
final class FinalClass
116116
{
117117
final function finalMethod(){}
118118
}

tests/Fixtures/Integration/set/@Symfony_whitespaces.test-out.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ public function testFooBar($a)
107107
}
108108
}
109109

110-
final class finalClass
110+
final class FinalClass
111111
{
112-
public function finalMethod()
112+
final public function finalMethod()
113113
{
114114
}
115115
}

0 commit comments

Comments
 (0)