Skip to content

Commit

Permalink
Refactor: EarlyExit
Browse files Browse the repository at this point in the history
  • Loading branch information
koriym committed Oct 5, 2023
1 parent e9c1968 commit e1d2619
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
1 change: 0 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ com
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming.SuperfluousSuffix"/>
<!-- /Base -->
<!-- Option -->
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed"/>
<exclude name="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall.MissingTrailingComma"/>
<!-- /Option -->
<!-- Exclude Fake files form Doctrine CS -->
Expand Down
6 changes: 4 additions & 2 deletions src/AopCodeGen.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ private function addMethods(AopCodeGenNewCode $newCode, ReflectionClass $class,
$additionalMethods[] = sprintf(" %s\n {\n %s%s\n }\n", $signature, $return, self::INTERCEPT_STATEMENT);
}

if ($additionalMethods) {
$newCode->insert(implode("\n", $additionalMethods));
if (! $additionalMethods) {
return;
}

$newCode->insert(implode("\n", $additionalMethods));
}
}
6 changes: 4 additions & 2 deletions src/Matcher/AnyMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ public function __construct()
{
parent::__construct();

if (self::$builtinMethods === []) {
$this->setBuildInMethods();
if (self::$builtinMethods !== []) {
return;
}

$this->setBuildInMethods();
}

/**
Expand Down
16 changes: 10 additions & 6 deletions src/MethodMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ public function __invoke(ReflectionClass $class, \Ray\Aop\ReflectionMethod $meth
$annotations = $method->getAnnotations();
// priority bind
foreach ($pointcuts as $key => $pointcut) {
if ($pointcut instanceof PriorityPointcut) {
$this->annotatedMethodMatchBind($class, $method, $pointcut);
unset($pointcuts[$key]);
if (! ($pointcut instanceof PriorityPointcut)) {
continue;
}

$this->annotatedMethodMatchBind($class, $method, $pointcut);
unset($pointcuts[$key]);
}

$onion = $this->onionOrderMatch($class, $method, $pointcuts, $annotations);
Expand Down Expand Up @@ -78,10 +80,12 @@ private function onionOrderMatch(
// method bind in annotation order
foreach ($annotations as $annotation) {
$annotationIndex = get_class($annotation);
if (array_key_exists($annotationIndex, $pointcuts)) {
$this->annotatedMethodMatchBind($class, $method, $pointcuts[$annotationIndex]);
unset($pointcuts[$annotationIndex]);
if (! array_key_exists($annotationIndex, $pointcuts)) {
continue;
}

$this->annotatedMethodMatchBind($class, $method, $pointcuts[$annotationIndex]);
unset($pointcuts[$annotationIndex]);
}

return $pointcuts;
Expand Down
10 changes: 6 additions & 4 deletions src/ReflectiveMethodInvocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ public function getNamedArguments(): ArrayObject
$namedParams = [];
foreach ($params as $param) {
$pos = $param->getPosition();
if (array_key_exists($pos, (array) $args)) {
$name = $param->getName();
/** @psalm-suppress MixedAssignment */
$namedParams[$name] = $args[$pos];
if (! array_key_exists($pos, (array) $args)) {
continue;

Check warning on line 91 in src/ReflectiveMethodInvocation.php

View check run for this annotation

Codecov / codecov/patch

src/ReflectiveMethodInvocation.php#L91

Added line #L91 was not covered by tests
}

$name = $param->getName();
/** @psalm-suppress MixedAssignment */
$namedParams[$name] = $args[$pos];
}

return new ArrayObject($namedParams); // @phpstan-ignore-line
Expand Down

0 comments on commit e1d2619

Please sign in to comment.