Skip to content

Commit

Permalink
Methods\FinalInAbstractClassRule: allow __construct method to be non-…
Browse files Browse the repository at this point in the history
…final
  • Loading branch information
Slamdunk authored and localheinz committed Jul 31, 2020
1 parent c51e259 commit ea6621d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

For a full diff see [`0.15.0...main`][0.15.0...main].
For a full diff see [`0.15.1...main`][0.15.1...main].

## [`0.15.1`][0.15.1]

For a full diff see [`0.15.0...0.15.1`][0.15.0...0.15.1].

### Changed

* Adjusted `Methods\FinalInAbstractClass` rule to allow non-`final` `public` constructors in abstract classes ([#248]), by [@Slamdunk]

## [`0.15.0`][0.15.0]

Expand Down Expand Up @@ -323,6 +331,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0].
[0.14.3]: https://github.com/ergebnis/phpstan-rules/releases/tag/0.14.3
[0.14.4]: https://github.com/ergebnis/phpstan-rules/releases/tag/0.14.4
[0.15.0]: https://github.com/ergebnis/phpstan-rules/releases/tag/0.15.0
[0.15.1]: https://github.com/ergebnis/phpstan-rules/releases/tag/0.15.1

[362c7ea...0.1.0]: https://github.com/ergebnis/phpstan-rules/compare/362c7ea...0.1.0
[0.1.0...0.2.0]: https://github.com/ergebnis/phpstan-rules/compare/0.1.0...0.2.0
Expand All @@ -348,7 +357,8 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0].
[0.14.2...0.14.3]: https://github.com/ergebnis/phpstan-rules/compare/0.14.2...0.14.3
[0.14.3...0.14.4]: https://github.com/ergebnis/phpstan-rules/compare/0.14.3...0.14.4
[0.14.4...0.15.0]: https://github.com/ergebnis/phpstan-rules/compare/0.14.4...0.15.0
[0.15.0...main]: https://github.com/ergebnis/phpstan-rules/compare/0.15.0...main
[0.15.0...0.15.1]: https://github.com/ergebnis/phpstan-rules/compare/0.15.0...0.15.1
[0.15.1...main]: https://github.com/ergebnis/phpstan-rules/compare/0.15.1...main

[#1]: https://github.com/ergebnis/phpstan-rules/pull/1
[#4]: https://github.com/ergebnis/phpstan-rules/pull/4
Expand Down Expand Up @@ -398,7 +408,9 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0].
[#186]: https://github.com/ergebnis/phpstan-rules/pull/186
[#202]: https://github.com/ergebnis/phpstan-rules/pull/202
[#225]: https://github.com/ergebnis/phpstan-rules/pull/225
[#248]: https://github.com/ergebnis/phpstan-rules/pull/248

[@ergebnis]: https://github.com/ergebnis
[@Great-Antique]: https://github.com/Great-Antique
[@localheinz]: https://github.com/localheinz
[@Slamdunk]: https://github.com/Slamdunk
4 changes: 4 additions & 0 deletions src/Methods/FinalInAbstractClassRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

if ('__construct' === $node->name->name) {
return [];
}

return [
\sprintf(
'Method %s::%s() is not final, but since the containing class is abstract, it should be.',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Ergebnis\PHPStan\Rules\Test\Fixture\Methods\FinalInAbstractClassRule\Success;

abstract class AbstractClassWithNonFinalConstructor
{
public function __construct()
{
}
}
1 change: 1 addition & 0 deletions test/Integration/Methods/FinalInAbstractClassRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function provideCasesWhereAnalysisShouldSucceed(): iterable
'abstract-class-with-abstract-method' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithAbstractMethod.php',
'abstract-class-with-final-protected-method' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithFinalProtectedMethod.php',
'abstract-class-with-final-public-method' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithFinalPublicMethod.php',
'abstract-class-with-non-final-constructor' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithNonFinalConstructor.php',
'abstract-class-with-private-method' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPrivateMethod.php',
'interface-with-public-method' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/InterfaceWithPublicMethod.php',
];
Expand Down

0 comments on commit ea6621d

Please sign in to comment.