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

Closes #220: ignore php4 style ctor in interfaces and namespaces #221

Merged
merged 3 commits into from Nov 10, 2014
Merged

Conversation

gooh
Copy link
Contributor

@gooh gooh commented Nov 1, 2014

PHPMD will report violations when it finds a method with the same name as the enclosing class, e.g. php4 style constructors. However, as of PHP 5.3 such methods will not be considered constructors when they are in a namespace. PHPMD should not mark these methods then.

PHPMD will also report methods with the same name as the enclosing interface. Given that interfaces should not contain constructors, marking those methods as such seems wrong to me. A dedicated sniff for finding constructors in interfaces as suggested in #31 seems more useful here.

The commit adds checks for the above two cases. When found, PHPMD will no longer mark those cases as ConstructorWithNameAsEnclosingClass violations. I've also added two tests to verify the behavior.

PHPMD will report violations when it finds a method with the same name
as the enclosing class, e.g. php4 style constructors. However, as of PHP
5.3 such methods will not be considered constructors when they are in a
namespace. PHPMD should not mark these methods then.

PHPMD will also report methods with the same name as the enclosing
interface. Given that interfaces should not contain constructors,
marking those methods as such seems wrong to me. A dedicated sniff for
finding constructors in interfaces as suggested in #31 seems more useful
here.

The commit adds checks for the above two cases. When found, PHPMD will
no longer mark those cases as ConstructorWithNameAsEnclosingClass
violations. I've also added two tests to verify the behavior.
because methods in an interface may not have a body
manuelpichler added a commit that referenced this pull request Nov 10, 2014
Closes #220: ignore php4 style ctor in interfaces and namespaces
@manuelpichler manuelpichler merged commit ff1bb8b into phpmd:master Nov 10, 2014
@ravage84 ravage84 added this to the 2.2.0 milestone Jul 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants