GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CRLDistributionPointsExtension::_fromDER()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X509\Certificate\Extension;
6
7
use Sop\ASN1\Element;
8
use Sop\ASN1\Type\Constructed\Sequence;
9
use Sop\ASN1\Type\UnspecifiedType;
10
use Sop\X509\Certificate\Extension\DistributionPoint\DistributionPoint;
11
12
/**
13
 * Implements 'CRL Distribution Points' certificate extension.
14
 *
15
 * @see https://tools.ietf.org/html/rfc5280#section-4.2.1.13
16
 */
17
class CRLDistributionPointsExtension extends Extension implements \Countable, \IteratorAggregate
18
{
19
    /**
20
     * Distribution points.
21
     *
22
     * @var DistributionPoint[]
23
     */
24
    protected $_distributionPoints;
25
26
    /**
27
     * Constructor.
28
     *
29
     * @param bool              $critical
30
     * @param DistributionPoint ...$distribution_points
31
     */
32 11
    public function __construct(bool $critical,
33
        DistributionPoint ...$distribution_points)
34
    {
35 11
        parent::__construct(self::OID_CRL_DISTRIBUTION_POINTS, $critical);
36 11
        $this->_distributionPoints = $distribution_points;
37 11
    }
38
39
    /**
40
     * Get distribution points.
41
     *
42
     * @return DistributionPoint[]
43
     */
44 1
    public function distributionPoints(): array
45
    {
46 1
        return $this->_distributionPoints;
47
    }
48
49
    /**
50
     * Get the number of distribution points.
51
     *
52
     * @see \Countable::count()
53
     *
54
     * @return int
55
     */
56 1
    public function count(): int
57
    {
58 1
        return count($this->_distributionPoints);
59
    }
60
61
    /**
62
     * Get iterator for distribution points.
63
     *
64
     * @see \IteratorAggregate::getIterator()
65
     *
66
     * @return \ArrayIterator
67
     */
68 3
    public function getIterator(): \ArrayIterator
69
    {
70 3
        return new \ArrayIterator($this->_distributionPoints);
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76 11
    protected static function _fromDER(string $data, bool $critical): Extension
77
    {
78 11
        $dps = array_map(
79
            function (UnspecifiedType $el) {
80 10
                return DistributionPoint::fromASN1($el->asSequence());
81 11
            }, UnspecifiedType::fromDER($data)->asSequence()->elements());
82 11
        if (!count($dps)) {
83 1
            throw new \UnexpectedValueException(
84 1
                'CRLDistributionPoints must have at least one DistributionPoint.');
85
        }
86
        // late static bound, extended by Freshest CRL extension
87 10
        return new static($critical, ...$dps);
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93 17
    protected function _valueASN1(): Element
94
    {
95 17
        if (!count($this->_distributionPoints)) {
96 1
            throw new \LogicException('No distribution points.');
97
        }
98 16
        $elements = array_map(
99
            function (DistributionPoint $dp) {
100 16
                return $dp->toASN1();
101 16
            }, $this->_distributionPoints);
102 16
        return new Sequence(...$elements);
103
    }
104
}
105