diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 69415854f..9b48453b8 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -11,7 +11,7 @@ pull request for each branch. This allows me to review and pull in new features
## Style Guide
-All pull requests must adhere to the [PSR-2 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md).
+All pull requests must adhere to the [PSR-12 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-coding-style-guide.md).
## Unit Testing
diff --git a/Slim/App.php b/Slim/App.php
index 299c160d0..65825121d 100644
--- a/Slim/App.php
+++ b/Slim/App.php
@@ -1,4 +1,5 @@
tip;
- $this->tip = new class($middleware, $next) implements RequestHandlerInterface
+ $this->tip = new class ($middleware, $next) implements RequestHandlerInterface
{
private $middleware;
private $next;
@@ -149,7 +157,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
public function addDeferred(string $middleware): self
{
$next = $this->tip;
- $this->tip = new class(
+ $this->tip = new class (
$middleware,
$next,
$this->container,
@@ -259,7 +267,7 @@ public function addCallable(callable $middleware): self
$middleware = $middleware->bindTo($this->container);
}
- $this->tip = new class($middleware, $next) implements RequestHandlerInterface
+ $this->tip = new class ($middleware, $next) implements RequestHandlerInterface
{
private $middleware;
private $next;
diff --git a/Slim/ResponseEmitter.php b/Slim/ResponseEmitter.php
index 6f0f159b3..51294f4f6 100644
--- a/Slim/ResponseEmitter.php
+++ b/Slim/ResponseEmitter.php
@@ -1,4 +1,5 @@
invocationStrategy;
- if (is_array($callable)
+ if (
+ is_array($callable)
&& $callable[0] instanceof RequestHandlerInterface
&& !in_array(RequestHandlerInvocationStrategyInterface::class, class_implements($strategy))
) {
diff --git a/Slim/Routing/RouteCollector.php b/Slim/Routing/RouteCollector.php
index 154dcc18e..0508c9400 100644
--- a/Slim/Routing/RouteCollector.php
+++ b/Slim/Routing/RouteCollector.php
@@ -1,4 +1,5 @@
-
+
diff --git a/tests/AppTest.php b/tests/AppTest.php
index 2d94bad2f..63f3ee126 100644
--- a/tests/AppTest.php
+++ b/tests/AppTest.php
@@ -1,4 +1,5 @@
addRoutingMiddleware();
// Check that the routing middleware really has been added to the tip of the app middleware stack.
- $middlewareDispatcherProperty = new \ReflectionProperty(App::class, 'middlewareDispatcher');
+ $middlewareDispatcherProperty = new ReflectionProperty(App::class, 'middlewareDispatcher');
$middlewareDispatcherProperty->setAccessible(true);
/** @var MiddlewareDispatcher $middlewareDispatcher */
$middlewareDispatcher = $middlewareDispatcherProperty->getValue($app);
- $tipProperty = new \ReflectionProperty(MiddlewareDispatcher::class, 'tip');
+ $tipProperty = new ReflectionProperty(MiddlewareDispatcher::class, 'tip');
$tipProperty->setAccessible(true);
/** @var RequestHandlerInterface $tip */
$tip = $tipProperty->getValue($middlewareDispatcher);
- $reflection = new \ReflectionClass($tip);
+ $reflection = new ReflectionClass($tip);
$middlewareProperty = $reflection->getProperty('middleware');
$middlewareProperty->setAccessible(true);
@@ -719,17 +731,17 @@ public function testAddErrorMiddleware()
$errorMiddleware = $app->addErrorMiddleware(true, true, true);
// Check that the error middleware really has been added to the tip of the app middleware stack.
- $middlewareDispatcherProperty = new \ReflectionProperty(App::class, 'middlewareDispatcher');
+ $middlewareDispatcherProperty = new ReflectionProperty(App::class, 'middlewareDispatcher');
$middlewareDispatcherProperty->setAccessible(true);
/** @var MiddlewareDispatcher $middlewareDispatcher */
$middlewareDispatcher = $middlewareDispatcherProperty->getValue($app);
- $tipProperty = new \ReflectionProperty(MiddlewareDispatcher::class, 'tip');
+ $tipProperty = new ReflectionProperty(MiddlewareDispatcher::class, 'tip');
$tipProperty->setAccessible(true);
/** @var RequestHandlerInterface $tip */
$tip = $tipProperty->getValue($middlewareDispatcher);
- $reflection = new \ReflectionClass($tip);
+ $reflection = new ReflectionClass($tip);
$middlewareProperty = $reflection->getProperty('middleware');
$middlewareProperty->setAccessible(true);
@@ -749,17 +761,17 @@ public function testAddBodyParsingMiddleware()
$bodyParsingMiddleware = $app->addBodyParsingMiddleware();
// Check that the body parsing middleware really has been added to the tip of the app middleware stack.
- $middlewareDispatcherProperty = new \ReflectionProperty(App::class, 'middlewareDispatcher');
+ $middlewareDispatcherProperty = new ReflectionProperty(App::class, 'middlewareDispatcher');
$middlewareDispatcherProperty->setAccessible(true);
/** @var MiddlewareDispatcher $middlewareDispatcher */
$middlewareDispatcher = $middlewareDispatcherProperty->getValue($app);
- $tipProperty = new \ReflectionProperty(MiddlewareDispatcher::class, 'tip');
+ $tipProperty = new ReflectionProperty(MiddlewareDispatcher::class, 'tip');
$tipProperty->setAccessible(true);
/** @var RequestHandlerInterface $tip */
$tip = $tipProperty->getValue($middlewareDispatcher);
- $reflection = new \ReflectionClass($tip);
+ $reflection = new ReflectionClass($tip);
$middlewareProperty = $reflection->getProperty('middleware');
$middlewareProperty->setAccessible(true);
diff --git a/tests/Assets/HeaderStack.php b/tests/Assets/HeaderStack.php
index ba93dd26f..82664df55 100644
--- a/tests/Assets/HeaderStack.php
+++ b/tests/Assets/HeaderStack.php
@@ -1,4 +1,5 @@
resolve(__NAMESPACE__.'\testAdvancedCallable');
- $callableRoute = $resolver->resolveRoute(__NAMESPACE__.'\testAdvancedCallable');
- $callableMiddleware = $resolver->resolveMiddleware(__NAMESPACE__.'\testAdvancedCallable');
+ $callable = $resolver->resolve(__NAMESPACE__ . '\testAdvancedCallable');
+ $callableRoute = $resolver->resolveRoute(__NAMESPACE__ . '\testAdvancedCallable');
+ $callableMiddleware = $resolver->resolveMiddleware(__NAMESPACE__ . '\testAdvancedCallable');
$this->assertEquals(true, $callable());
$this->assertEquals(true, $callableRoute());
@@ -315,9 +316,9 @@ public function testMiddlewareObjPsrRequestHandlerClassInContainer()
public function testResolutionToAPsrRequestHandlerClassWithCustomMethod()
{
$resolver = new CallableResolver(); // No container injected
- $callable = $resolver->resolve(RequestHandlerTest::class.':custom');
- $callableRoute = $resolver->resolveRoute(RequestHandlerTest::class.':custom');
- $callableMiddleware = $resolver->resolveMiddleware(RequestHandlerTest::class.':custom');
+ $callable = $resolver->resolve(RequestHandlerTest::class . ':custom');
+ $callableRoute = $resolver->resolveRoute(RequestHandlerTest::class . ':custom');
+ $callableMiddleware = $resolver->resolveMiddleware(RequestHandlerTest::class . ':custom');
$this->assertIsArray($callable);
$this->assertInstanceOf(RequestHandlerTest::class, $callable[0]);
diff --git a/tests/Error/AbstractErrorRendererTest.php b/tests/Error/AbstractErrorRendererTest.php
index 434558609..ff2f98f2d 100644
--- a/tests/Error/AbstractErrorRendererTest.php
+++ b/tests/Error/AbstractErrorRendererTest.php
@@ -1,4 +1,5 @@
createResponse();
- return new class($response) implements RequestHandlerInterface {
+ return new class ($response) implements RequestHandlerInterface {
private $response;
public function __construct(ResponseInterface $response)
diff --git a/tests/Middleware/ContentLengthMiddlewareTest.php b/tests/Middleware/ContentLengthMiddlewareTest.php
index 8fdc00101..79a1c7766 100644
--- a/tests/Middleware/ContentLengthMiddlewareTest.php
+++ b/tests/Middleware/ContentLengthMiddlewareTest.php
@@ -1,4 +1,5 @@
reveal();
$dispatcher = $this->createMiddlewareDispatcher($kernel, null);
- $dispatcher->addDeferred(\stdClass::class);
+ $dispatcher->addDeferred(stdClass::class);
$dispatcher->handle($requestProphecy->reveal());
$kernelProphecy->handle(Argument::type(ServerRequestInterface::class))->shouldNotHaveBeenCalled();
diff --git a/tests/Mocks/CallableTest.php b/tests/Mocks/CallableTest.php
index ad2b880bb..19b271927 100644
--- a/tests/Mocks/CallableTest.php
+++ b/tests/Mocks/CallableTest.php
@@ -1,4 +1,5 @@
stream = $body;
- $meta = \stream_get_meta_data($this->stream);
+ $meta = stream_get_meta_data($this->stream);
$this->seekable = $meta['seekable'];
$this->readable = isset(self::$readWriteHash['read'][$meta['mode']]);
$this->writable = isset(self::$readWriteHash['write'][$meta['mode']]);
@@ -99,8 +119,8 @@ public function __toString(): string
public function close(): void
{
if (isset($this->stream)) {
- if (\is_resource($this->stream)) {
- \fclose($this->stream);
+ if (is_resource($this->stream)) {
+ fclose($this->stream);
}
$this->detach();
}
@@ -132,10 +152,10 @@ public function getSize(): ?int
// Clear the stat cache if the stream has a URI
if ($this->uri) {
- \clearstatcache(true, $this->uri);
+ clearstatcache(true, $this->uri);
}
- $stats = \fstat($this->stream);
+ $stats = fstat($this->stream);
if (isset($stats['size'])) {
$this->size = $stats['size'];
@@ -147,8 +167,8 @@ public function getSize(): ?int
public function tell(): int
{
- if (false === $result = \ftell($this->stream)) {
- throw new \RuntimeException('Unable to determine stream position');
+ if (false === $result = ftell($this->stream)) {
+ throw new RuntimeException('Unable to determine stream position');
}
return $result;
@@ -156,7 +176,7 @@ public function tell(): int
public function eof(): bool
{
- return !$this->stream || \feof($this->stream);
+ return !$this->stream || feof($this->stream);
}
public function isSeekable(): bool
@@ -164,14 +184,14 @@ public function isSeekable(): bool
return $this->seekable;
}
- public function seek($offset, $whence = \SEEK_SET): void
+ 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) {
- throw new \RuntimeException(
+ throw new RuntimeException('Stream is not seekable');
+ } elseif (fseek($this->stream, $offset, $whence) === -1) {
+ throw new RuntimeException(
'Unable to seek to stream position '
- .$offset.' with whence '.\var_export($whence, true)
+ . $offset . ' with whence ' . var_export($whence, true)
);
}
}
@@ -189,14 +209,14 @@ public function isWritable(): bool
public function write($string): int
{
if (!$this->writable) {
- throw new \RuntimeException('Cannot write to a non-writable stream');
+ throw new RuntimeException('Cannot write to a non-writable stream');
}
// We can't know the size after writing anything
$this->size = null;
- if (false === $result = \fwrite($this->stream, $string)) {
- throw new \RuntimeException('Unable to write to stream');
+ if (false === $result = fwrite($this->stream, $string)) {
+ throw new RuntimeException('Unable to write to stream');
}
return $result;
@@ -210,20 +230,20 @@ public function isReadable(): bool
public function read($length): string
{
if (!$this->readable) {
- throw new \RuntimeException('Cannot read from non-readable stream');
+ throw new RuntimeException('Cannot read from non-readable stream');
}
- return \fread($this->stream, $length);
+ return fread($this->stream, $length);
}
public function getContents(): string
{
if (!isset($this->stream)) {
- throw new \RuntimeException('Unable to read stream contents');
+ throw new RuntimeException('Unable to read stream contents');
}
- if (false === $contents = \stream_get_contents($this->stream)) {
- throw new \RuntimeException('Unable to read stream contents');
+ if (false === $contents = stream_get_contents($this->stream)) {
+ throw new RuntimeException('Unable to read stream contents');
}
return $contents;
@@ -234,10 +254,10 @@ public function getMetadata($key = null)
if (!isset($this->stream)) {
return $key ? null : [];
} elseif (null === $key) {
- return \stream_get_meta_data($this->stream);
+ return stream_get_meta_data($this->stream);
}
- $meta = \stream_get_meta_data($this->stream);
+ $meta = stream_get_meta_data($this->stream);
return isset($meta[$key]) ? $meta[$key] : null;
}
diff --git a/tests/Mocks/RequestHandlerTest.php b/tests/Mocks/RequestHandlerTest.php
index 93ee33375..7025c876e 100644
--- a/tests/Mocks/RequestHandlerTest.php
+++ b/tests/Mocks/RequestHandlerTest.php
@@ -1,4 +1,5 @@
amountToRead, self::CHUNK_SIZE, $length);
$this->amountToRead -= $size;
return str_repeat('.', $size);
diff --git a/tests/Mocks/SmallChunksStream.php b/tests/Mocks/SmallChunksStream.php
index 510364e6b..b136c7f37 100644
--- a/tests/Mocks/SmallChunksStream.php
+++ b/tests/Mocks/SmallChunksStream.php
@@ -1,4 +1,5 @@
getMethod('emitBody');
$emitBodyMethod->setAccessible(true);
$emitBodyMethod->invoke($responseEmitter, $response);
diff --git a/tests/Routing/DispatcherTest.php b/tests/Routing/DispatcherTest.php
index bade186fd..5ef716127 100644
--- a/tests/Routing/DispatcherTest.php
+++ b/tests/Routing/DispatcherTest.php
@@ -1,4 +1,5 @@
[
+ 'connection_status' => function (): int {
+ if (isset($GLOBALS['connection_status_return'])) {
+ return $GLOBALS['connection_status_return'];
+ }
-require __DIR__ . '/Assets/PhpFunctionOverrides.php';
-require __DIR__ . '/Assets/PhpRoutingFunctionOverrides.php';
+ return connection_status();
+ },
+ 'header' => function (string $string, bool $replace = true, int $statusCode = null): void {
+ HeaderStack::push(
+ [
+ 'header' => $string,
+ 'replace' => $replace,
+ 'status_code' => $statusCode,
+ ]
+ );
+ },
+ 'headers_sent' => function (): bool {
+ return false;
+ }
+ ],
+ RouteCollector::class => [
+ 'is_readable' => function (string $file): bool {
+ if (stripos($file, 'non-readable.cache') !== false) {
+ return false;
+ }
+ return true;
+ },
+ 'is_writable' => function (string $path): bool {
+ if (stripos($path, 'non-writable-directory') !== false) {
+ return false;
+ }
+ return true;
+ }
+ ]
+]);