Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosas committed Nov 24, 2023
2 parents 7f1c8de + 063ea2d commit 0c79df3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
10 changes: 9 additions & 1 deletion src/Statement/Builder/DeclarationStatementBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,20 @@ private function extractCurrentAssertion(array $rules): array
$result = [];
foreach ($rules as $rule) {
if ($rule->getAssertion() === $this->assertion) {
$ruleName = $this->extractRuleName($rule->getRuleName());
foreach ($rule->getSubjects() as $selector) {
$result[] = [$rule->getRuleName(), $selector, $rule->getSubjectExcludes(), $rule->getTips()];
$result[] = [$ruleName, $selector, $rule->getSubjectExcludes(), $rule->getTips()];
}
}
}

return $result;
}

private function extractRuleName(string $fullName): string
{
$pos = mb_strpos($fullName, ':');

return mb_substr($fullName, $pos !== false ? $pos + 1 : 0);
}
}
17 changes: 16 additions & 1 deletion src/Statement/Builder/RelationStatementBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,27 @@ private function extractCurrentAssertion(array $rules): array
$result = [];
foreach ($rules as $rule) {
if ($rule->getAssertion() === $this->assertion) {
$ruleName = $this->extractRuleName($rule->getRuleName());
foreach ($rule->getSubjects() as $selector) {
$result[] = [$rule->getRuleName(), $selector, $rule->getSubjectExcludes(), $rule->getTargets(), $rule->getTargetExcludes(), $rule->getTips()];
$result[] = [
$ruleName,
$selector,
$rule->getSubjectExcludes(),
$rule->getTargets(),
$rule->getTargetExcludes(),
$rule->getTips(),
];
}
}
}

return $result;
}

private function extractRuleName(string $fullName): string
{
$pos = mb_strpos($fullName, ':');

return mb_substr($fullName, $pos !== false ? $pos + 1 : 0);
}
}
11 changes: 4 additions & 7 deletions src/Test/TestParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,17 @@ private function parse(): array
foreach ($tests as $test) {
$methods = [];
$reflected = $test->getNativeReflection();
$classname = $reflected->getName();
$object = $reflected->newInstanceWithoutConstructor();
foreach ($reflected->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
if (
!empty($method->getAttributes(Test::class))
|| preg_match('/^(test)[A-Za-z0-9_\x80-\xff]*/', $method->getName())
) {
$methods[] = $method->getName();
$ruleBuilder = $object->{$method->getName()}();
$rules[$classname.':'.$method->getName()] = $ruleBuilder;
}
}

$object = $reflected->newInstanceWithoutConstructor();
foreach ($methods as $method) {
$ruleBuilder = $object->{$method}();
$rules[$method] = $ruleBuilder;
}
}

return $this->buildRules($rules);
Expand Down

0 comments on commit 0c79df3

Please sign in to comment.