Skip to content

Commit

Permalink
Improve performance of Assertion Chain class (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
scyzoryck authored Dec 16, 2021
1 parent dbc94e5 commit fc352a3
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/Assert/AssertionChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace Assert;

use LogicException;
use ReflectionClass;

/**
* Chaining builder for assertions.
Expand Down Expand Up @@ -171,13 +170,12 @@ public function __call($methodName, $args): AssertionChain
return $this;
}

if (!\method_exists($this->assertionClassName, $methodName)) {
try {
$method = new \ReflectionMethod($this->assertionClassName, $methodName);
} catch (\ReflectionException $exception) {
throw new \RuntimeException("Assertion '".$methodName."' does not exist.");
}

$reflClass = new ReflectionClass($this->assertionClassName);
$method = $reflClass->getMethod($methodName);

\array_unshift($args, $this->value);
$params = $method->getParameters();

Expand All @@ -186,12 +184,13 @@ public function __call($methodName, $args): AssertionChain
continue;
}

if ('message' == $param->getName()) {
$args[$idx] = $this->defaultMessage;
}

if ('propertyPath' == $param->getName()) {
$args[$idx] = $this->defaultPropertyPath;
switch ($param->getName()) {
case 'message':
$args[$idx] = $this->defaultMessage;
break;
case 'propertyPath':
$args[$idx] = $this->defaultPropertyPath;
break;
}
}

Expand Down

0 comments on commit fc352a3

Please sign in to comment.