Skip to content

Commit f93be40

Browse files
committed
Fix [Naming]: Trait can have method same as trait's name
1 parent f2255e0 commit f93be40

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/main/php/PHP/PMD/Rule/Naming/ConstructorWithNameAsEnclosingClass.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,18 @@ class PHP_PMD_Rule_Naming_ConstructorWithNameAsEnclosingClass
6767
implements PHP_PMD_Rule_IMethodAware
6868
{
6969
/**
70-
* Extracts all variable and variable declarator nodes from the given node
71-
* and checks the variable name length against the configured minimum
72-
* length.
70+
* Is method has the same name as the enclosing class
71+
* (php4 style constructor).
7372
*
7473
* @param PHP_PMD_AbstractNode $node The context source code node.
7574
*
7675
* @return void
7776
*/
7877
public function apply(PHP_PMD_AbstractNode $node)
7978
{
80-
if (strcasecmp($node->getName(), $node->getParentName()) !== 0) {
79+
if (strcasecmp($node->getName(), $node->getParentName()) !== 0
80+
|| $node->getNode()->getParent() instanceof PHP_Depend_Code_Trait
81+
) {
8182
return;
8283
}
8384
$this->addViolation($node);

0 commit comments

Comments
 (0)