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

Adjust logic targeting inaccessible nodes #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions src/NodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,12 @@ public function leaveNode(Node $node, bool $preserveStack = false)
// either a method, property, or constant, or its part of the
// declaration itself (e.g., `extends`).

if (!$this->includeInaccessibleClassNodes && $parent instanceof Class_ && ($node instanceof ClassMethod || $node instanceof ClassConst || $node instanceof Property)) {
if ($node->isPrivate() || ($parent->isFinal() && $node->isProtected())) {
return NodeTraverser::REMOVE_NODE;
}
if (!$this->includeInaccessibleClassNodes
&& $parent instanceof Class_
&& ($node instanceof ClassMethod || $node instanceof ClassConst || $node instanceof Property)
&& ($node->isPrivate() || $node->isProtected())
) {
Comment on lines +247 to +251
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!$this->includeInaccessibleClassNodes
&& $parent instanceof Class_
&& ($node instanceof ClassMethod || $node instanceof ClassConst || $node instanceof Property)
&& ($node->isPrivate() || $node->isProtected())
) {
if (
!$this->includeInaccessibleClassNodes
&& $parent instanceof Class_
&& ($node instanceof ClassMethod || $node instanceof ClassConst || $node instanceof Property)
&& ($node->isPrivate() || $node->isProtected())
) {

return NodeTraverser::REMOVE_NODE;
}

return;
Expand Down
25 changes: 0 additions & 25 deletions test/files/classes.out.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
/** doc */
abstract class A extends \B implements \C
{
/** doc */
protected const A = 'B';

/** doc */
public static $a = 'a';

Expand All @@ -15,14 +12,6 @@ public static function b($a): void

/** doc */
abstract public function c($a): string;

/** doc */
protected function d($a) : void
{
}

/** doc */
protected abstract function e($a) : string;
}

class D
Expand All @@ -45,22 +34,8 @@ public function a($a) : void

trait F
{
/** doc */
private $a = 'a';

/** doc */
private function a($a) : void
{
}

/** doc */
abstract public function b($a): string;

/** doc */
abstract protected function c($a): string;

/** doc */
abstract private function d($a): string;
}

final class G
Expand Down