Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Minor optimizations in if() blocks #2951

Merged
merged 2 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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