Failed Conditions
Pull Request — master (#144)
by Florent
08:48 queued 04:12
created

X5UJWKSet::getKeys()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 16
rs 9.4285
c 1
b 0
f 1
cc 3
eloc 11
nc 3
nop 0
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose\Object;
13
14
use Assert\Assertion;
15
use Jose\KeyConverter\KeyConverter;
16
17
/**
18
 * Class JKUJWKSet.
19
 */
20
final class X5UJWKSet extends DownloadedJWKSet
21
{
22
    /**
23
     * @return \Jose\Object\JWKInterface[]
24
     */
25
    public function getKeys()
26
    {
27
        $content = json_decode($this->getContent(), true);
28
        Assertion::isArray($content, 'Invalid content.');
29
        $jwkset = new JWKSet();
30
        foreach ($content as $kid => $cert) {
31
            $jwk = KeyConverter::loadKeyFromCertificate($cert);
32
            Assertion::notEmpty($jwk, 'Invalid content.');
33
            if (is_string($kid)) {
34
                $jwk['kid'] = $kid;
35
            }
36
            $jwkset->addKey(new JWK($jwk));
37
        }
38
39
        return $jwkset->getKeys();
40
    }
41
}
42