Passed
Push — master ( 0d45b3...efe930 )
by Greg
05:15
created

Ping   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 11 3
1
<?php
2
/**
3
 * webtrees: online genealogy
4
 * Copyright (C) 2019 webtrees development team
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
 * GNU General Public License for more details.
13
 * You should have received a copy of the GNU General Public License
14
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15
 */
16
declare(strict_types=1);
17
18
namespace Fisharebest\Webtrees\Http\RequestHandlers;
19
20
use Fisharebest\Webtrees\Services\ServerCheckService;
21
use Psr\Http\Message\ResponseInterface;
22
use Psr\Http\Message\ServerRequestInterface;
23
use Psr\Http\Server\RequestHandlerInterface;
24
use function response;
25
26
/**
27
 * Check the server is up.
28
 */
29
class Ping implements RequestHandlerInterface
30
{
31
    /** @var ServerCheckService */
32
    private $server_check_service;
33
34
    /**
35
     * @param ServerCheckService $server_check_service
36
     */
37
    public function __construct(ServerCheckService $server_check_service)
38
    {
39
        $this->server_check_service = $server_check_service;
40
    }
41
42
    /**
43
     * @param ServerRequestInterface $request
44
     *
45
     * @return ResponseInterface
46
     */
47
    public function handle(ServerRequestInterface $request): ResponseInterface
48
    {
49
        if ($this->server_check_service->serverErrors()->isNotEmpty()) {
50
            return response('ERROR');
51
        }
52
53
        if ($this->server_check_service->serverWarnings()->isNotEmpty()) {
54
            return response('WARNING');
55
        }
56
57
        return response('OK');
58
    }
59
}
60