CredentialStore   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 25
c 2
b 0
f 0
dl 0
loc 46
rs 10
ccs 0
cts 32
cp 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getByEntityId() 0 34 4
1
<?php
2
3
namespace DMK\MKSamlAuth\Store;
4
5
use LightSaml\Credential\KeyHelper;
6
use LightSaml\Credential\X509Certificate;
7
use LightSaml\Credential\X509Credential;
8
use LightSaml\Store\Credential\CredentialStoreInterface;
9
use TYPO3\CMS\Core\Database\ConnectionPool;
10
use TYPO3\CMS\Core\SingletonInterface;
11
12
class CredentialStore implements CredentialStoreInterface, SingletonInterface
13
{
14
    /**
15
     * @var ConnectionPool
16
     */
17
    private $pool;
18
19
    public function __construct(ConnectionPool $pool)
20
    {
21
        $this->pool = $pool;
22
    }
23
24
    public function getByEntityId($entityId)
25
    {
26
        $qb = $this->pool->getQueryBuilderForTable('tx_mksamlauth_domain_model_identityprovider');
27
        $qb->select('*');
28
        $qb->from('tx_mksamlauth_domain_model_identityprovider');
29
        $qb->where($qb->expr()->eq('idp_entity_id', '?'));
30
        $qb->setMaxResults(1);
31
        $qb->setParameters([$entityId]);
32
33
        if (false === $stmt = $qb->execute()) {
0 ignored issues
show
introduced by
The condition false === $stmt = $qb->execute() is always false.
Loading history...
34
            return [];
35
        }
36
37
        if (false === $row = $stmt->fetch()) {
38
            return [];
39
        }
40
41
        $certificate = new X509Certificate();
42
        $certificate->loadPem($row['certificate']);
43
44
        $privateKey = null;
45
        if (0 < \strlen($row['cert_key'])) {
46
            $privateKey = KeyHelper::createPrivateKey(
47
                $row['cert_key'],
48
                $row['passphrase'],
49
                false,
50
                $certificate->getSignatureAlgorithm()
51
            );
52
        }
53
54
        $credential = new X509Credential($certificate, $privateKey);
55
        $credential->setEntityId($entityId);
56
57
        return [$credential];
58
    }
59
}
60