Skip to content

Commit

Permalink
Merge pull request #2951 from Ayesh/if-branching
Browse files Browse the repository at this point in the history
Minor optimizations in if() blocks
  • Loading branch information
l0gicgate authored May 6, 2020
2 parents b66a2d8 + d5a3f35 commit 18f23fe
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Slim/CallableResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private function resolveByPredicate($toResolve, callable $predicate, string $def
}
if (is_string($toResolve)) {
[$instance, $method] = $this->resolveSlimNotation($toResolve);
if ($predicate($instance) && $method === null) {
if ($method === null && $predicate($instance)) {
$method = $defaultMethod;
}
$resolved = [$instance, $method ?? '__invoke'];
Expand Down
2 changes: 1 addition & 1 deletion Slim/Factory/AppFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static function determineResponseFactory(): ResponseFactoryInterface
if ($psr17factory::isResponseFactoryAvailable()) {
$responseFactory = $psr17factory::getResponseFactory();

if ($psr17factory::isStreamFactoryAvailable() || static::$streamFactory) {
if (static::$streamFactory || $psr17factory::isStreamFactoryAvailable()) {
$streamFactory = static::$streamFactory ?? $psr17factory::getStreamFactory();
return static::attemptResponseFactoryDecoration($responseFactory, $streamFactory);
}
Expand Down
14 changes: 8 additions & 6 deletions Slim/Middleware/ErrorMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,15 @@ public function getErrorHandler(string $type)
{
if (isset($this->handlers[$type])) {
return $this->callableResolver->resolve($this->handlers[$type]);
} elseif (isset($this->subClassHandlers[$type])) {
}

if (isset($this->subClassHandlers[$type])) {
return $this->callableResolver->resolve($this->subClassHandlers[$type]);
} else {
foreach ($this->subClassHandlers as $class => $handler) {
if (is_subclass_of($type, $class)) {
return $this->callableResolver->resolve($handler);
}
}

foreach ($this->subClassHandlers as $class => $handler) {
if (is_subclass_of($type, $class)) {
return $this->callableResolver->resolve($handler);
}
}

Expand Down
8 changes: 6 additions & 2 deletions tests/Mocks/MockStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ public function seek($offset, $whence = SEEK_SET): void
{
if (!$this->seekable) {
throw new RuntimeException('Stream is not seekable');
} elseif (fseek($this->stream, $offset, $whence) === -1) {
}

if (fseek($this->stream, $offset, $whence) === -1) {
throw new RuntimeException(
'Unable to seek to stream position '
. $offset . ' with whence ' . var_export($whence, true)
Expand Down Expand Up @@ -253,7 +255,9 @@ public function getMetadata($key = null)
{
if (!isset($this->stream)) {
return $key ? null : [];
} elseif (null === $key) {
}

if (null === $key) {
return stream_get_meta_data($this->stream);
}

Expand Down

0 comments on commit 18f23fe

Please # to comment.