Skip to content

Commit

Permalink
filters private class constants and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ju1ius committed Dec 27, 2023
1 parent 7de7a61 commit 9c21a89
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/Internal/AstBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ private function buildClass(ReflectionClass $class): Stmt\Class_
}
$builder->implement(...$this->resolveNames(ReflectionUtils::getOwnInterfaceNames($class)));
foreach (ReflectionUtils::getOwnConstants($class) as $constant) {
if ($constant->isPrivate()) {
continue;
}
$builder->addStmt($this->buildClassConst($constant));
}
foreach (ReflectionUtils::getOwnProperties($class) as $property) {
Expand All @@ -138,6 +141,9 @@ private function buildClass(ReflectionClass $class): Stmt\Class_
$builder->addStmt($this->buildProperty($property));
}
foreach (ReflectionUtils::getOwnMethods($class) as $method) {
if ($method->isPrivate()) {
continue;
}
$builder->addStmt($this->buildMethod($method));
}
return $builder->getNode();
Expand Down Expand Up @@ -184,10 +190,9 @@ private function buildClassConst(ReflectionClassConstant $constant): Stmt\ClassC
if ($constant->hasType()) {
$builder->setType($this->buildType($constant->getType()));
}
assert(!$constant->isPrivate());
if ($constant->isProtected()) {
$builder->makeProtected();
} elseif ($constant->isPrivate()) {
$builder->makePrivate();
} else {
$builder->makePublic();
}
Expand All @@ -203,10 +208,9 @@ private function buildProperty(ReflectionProperty $property): Stmt\Property
if ($doc = $property->getDocComment()) {
$builder->setDocComment($doc);
}
assert(!$property->isPrivate());
if ($property->isProtected()) {
$builder->makeProtected();
} elseif ($property->isPrivate()) {
$builder->makePrivate();
} else {
$builder->makePublic();
}
Expand Down Expand Up @@ -239,10 +243,9 @@ private function buildMethod(ReflectionMethod $method): Stmt\ClassMethod
} elseif ($method->isAbstract()) {
$builder->makeAbstract();
}
assert(!$method->isPrivate());
if ($method->isProtected()) {
$builder->makeProtected();
} elseif ($method->isPrivate()) {
$builder->makePrivate();
} else {
$builder->makePublic();
}
Expand Down
2 changes: 0 additions & 2 deletions tests/ExtensionClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ class Root
{
public final const int ZERO = 0;
protected const int ONE = 1;
private const int TWO = 2;
public static string $static = 'static';
/** @var int */
public readonly int $public;
protected string $protected = 'a';
public function publicMethod() : void {}
protected function protectedMethod() : void {}
private function privateMethod() : void {}
}
PHP,
];
Expand Down

0 comments on commit 9c21a89

Please sign in to comment.