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

HomepageAccessibleCheck::message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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