Passed
Push — master ( d1b72a...68b5a8 )
by Anatoly
01:04 queued 11s
created

DoormanMiddleware::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 10
ccs 0
cts 5
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace App\Middleware;
4
5
/**
6
 * Import classes
7
 */
8
use App\ContainerAwareTrait;
9
use Arus\Http\Response\ResponseFactoryAwareTrait;
10
use Psr\Http\Message\ResponseInterface;
11
use Psr\Http\Message\ServerRequestInterface;
12
use Psr\Http\Server\MiddlewareInterface;
13
use Psr\Http\Server\RequestHandlerInterface;
14
use Sunrise\Http\Header\HeaderRetryAfter;
15
use DateTime;
16
17
/**
18
 * Import functions
19
 */
20
use function file_exists;
21
22
/**
23
 * DoormanMiddleware
24
 */
25
final class DoormanMiddleware implements MiddlewareInterface
26
{
27
    use ContainerAwareTrait;
28
    use ResponseFactoryAwareTrait;
29
30
    /**
31
     * {@inheritDoc}
32
     */
33
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
34
    {
35
        // if the file exists, then the application is closed for maintenance...
36
        $file = $this->container->get('app.root') . '/.down';
37
        if (file_exists($file)) {
38
            return $this->createResponse(503)
39
                ->withHeaderObject(new HeaderRetryAfter(new DateTime('+5 minutes')));
0 ignored issues
show
Bug introduced by
The method withHeaderObject() does not exist on Psr\Http\Message\ResponseInterface. Did you maybe mean withHeader()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
                ->/** @scrutinizer ignore-call */ withHeaderObject(new HeaderRetryAfter(new DateTime('+5 minutes')));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
        }
41
42
        return $handler->handle($request);
43
    }
44
}
45