ServiceProviderCertificateCheck   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 9.68%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 62
ccs 3
cts 31
cp 0.0968
rs 10
wmc 11

7 Methods

Rating   Name   Duplication   Size   Complexity  
A runCheck() 0 33 5
A getExpiresSoonMessage() 0 2 1
A getInvalidMessage() 0 2 1
A getEmptyMessage() 0 2 1
A __construct() 0 2 1
A getFineMessage() 0 2 1
A getExpiredMessage() 0 2 1
1
<?php
2
3
namespace App\HealthCheck;
4
5
use Exception;
6
use App\Entity\SamlServiceProvider;
7
use App\Repository\ServiceProviderRepositoryInterface;
8
9
class ServiceProviderCertificateCheck extends AbstractCertificateHealthCheck {
10
11
    public function __construct(private ServiceProviderRepositoryInterface $repository)
12 14
    {
13 14
    }
14 14
15
    /**
16
     * @inheritDoc
17
     */
18
    public function runCheck(): HealthCheckResult|array {
19
        $result = [ ];
20
21
        foreach($this->repository->findAll() as $serviceProvider) {
22
            if(!$serviceProvider instanceof SamlServiceProvider) {
23
                continue;
24
            }
25
26
            try {
27
                $certificate = $serviceProvider->getCertificate();
28
29
                $result = $this->checkCertificate($certificate);
30
                $result->addMessageParameter('%service_provider%', $serviceProvider->getName());
31
32
                if($result->getType() !== HealthCheckResultType::Fine) {
33
                    $result->setRoute('edit_service_provider');
34
                    $result->setRouteParameter([
35
                        'uuid' => $serviceProvider->getUuid()
36
                    ]);
37
                }
38
            } catch(Exception $e) {
39
                $result[] = new HealthCheckResult(
40
                    HealthCheckResultType::Error,
41
                    'health_check.error',
42
                    'health_check.error',
43
                    [
44
                        '%exception%' => $e->getMessage()
45
                    ]
46
                );
47
            }
48
        }
49
50
        return $result;
51
    }
52
53
    protected function getEmptyMessage(): string {
54
        return 'health_check.sp_certificate.empty';
55
    }
56
57
    protected function getInvalidMessage(): string {
58
        return 'health_check.sp_certificate.invalid';
59
    }
60
61
    protected function getExpiredMessage(): string {
62
        return 'health_check.sp_certificate.expired';
63
    }
64
65
    protected function getExpiresSoonMessage(): string {
66
        return 'health_check.sp_certificate.expires_soon';
67
    }
68
69
    protected function getFineMessage(): string {
70
        return 'health_check.sp_certificate.fine';
71
    }
72
}