Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Methods\FinalInAbstractClassRule: allow __construct method to be non-final #248

Merged
merged 1 commit into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
{
}
}
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