Completed
Push — ft/remove-vendor ( 825fc6...4801b9 )
by Philippe
56:00 queued 47:37
created

HomepageAccessibleCheck   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 60%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
eloc 10
c 2
b 0
f 1
dl 0
loc 25
ccs 6
cts 10
cp 0.6
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get_http_response_code() 0 13 2
A check() 0 3 1
A message() 0 3 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Thinktomorrow\Chief\HealthMonitor\Checks;
6
7
use Thinktomorrow\Chief\Settings\Homepage;
8
9
class HomepageAccessibleCheck implements HealthCheck
10
{
11 1
    public function check(): bool
12
    {
13 1
        return $this->get_http_response_code(Homepage::url()) == 200;
14
    }
15
16 1
    private function get_http_response_code(string $url) {
17 1
        if($url =='') return false;
18
19
        // Avoid ssl errors: SSL operation failed with code 1
20
        stream_context_set_default([
21
            'ssl' => [
22
                'verify_peer' => false,
23
                'verify_peer_name' => false,
24
            ],
25
        ]);
26
27
        $headers = get_headers($url);
28
        return substr($headers[0], 9, 3);
29
    }
30
31 1
    public function message(): string
32
    {
33 1
        return 'Het lijkt erop dat de homepagina niet meer bereikbaar is. <a href="'. route('chief.back.settings.edit') .'" class="text-secondary-800 underline hover:text-white">Kies een nieuwe</a>.';
34
    }
35
}
36