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.
Completed
Branch php72 (a7f01e)
by Joni
04:53
created

GeneralSubtrees   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 86
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getIterator() 0 3 1
A toASN1() 0 10 2
A __construct() 0 3 1
A fromASN1() 0 11 2
A count() 0 3 1
A all() 0 3 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X509\Certificate\Extension\NameConstraints;
6
7
use Sop\ASN1\Type\Constructed\Sequence;
8
use Sop\ASN1\Type\UnspecifiedType;
9
10
/**
11
 * Implements <i>GeneralSubtrees</i> ASN.1 type used by
12
 * 'Name Constraints' certificate extension.
13
 *
14
 * @see @link https://tools.ietf.org/html/rfc5280#section-4.2.1.10
15
 */
16
class GeneralSubtrees implements \Countable, \IteratorAggregate
17
{
18
    /**
19
     * Subtrees.
20
     *
21
     * @var GeneralSubtree[]
22
     */
23
    protected $_subtrees;
24
25
    /**
26
     * Constructor.
27
     *
28
     * @param GeneralSubtree ...$subtrees
29
     */
30 14
    public function __construct(GeneralSubtree ...$subtrees)
31
    {
32 14
        $this->_subtrees = $subtrees;
33 14
    }
34
35
    /**
36
     * Initialize from ASN.1.
37
     *
38
     * @param Sequence $seq
39
     *
40
     * @return self
41
     */
42 11
    public static function fromASN1(Sequence $seq): self
43
    {
44 11
        $subtrees = array_map(
45
            function (UnspecifiedType $el) {
46 10
                return GeneralSubtree::fromASN1($el->asSequence());
47 11
            }, $seq->elements());
48 11
        if (!count($subtrees)) {
49 1
            throw new \UnexpectedValueException(
50 1
                'GeneralSubtrees must contain at least one GeneralSubtree.');
51
        }
52 10
        return new self(...$subtrees);
53
    }
54
55
    /**
56
     * Get all subtrees.
57
     *
58
     * @return GeneralSubtree[]
59
     */
60 5
    public function all(): array
61
    {
62 5
        return $this->_subtrees;
63
    }
64
65
    /**
66
     * Generate ASN.1 structure.
67
     *
68
     * @return Sequence
69
     */
70 18
    public function toASN1(): Sequence
71
    {
72 18
        if (!count($this->_subtrees)) {
73 1
            throw new \LogicException('No subtrees.');
74
        }
75 17
        $elements = array_map(
76
            function (GeneralSubtree $gs) {
77 17
                return $gs->toASN1();
78 17
            }, $this->_subtrees);
79 17
        return new Sequence(...$elements);
80
    }
81
82
    /**
83
     * @see \Countable::count()
84
     *
85
     * @return int
86
     */
87 2
    public function count(): int
88
    {
89 2
        return count($this->_subtrees);
90
    }
91
92
    /**
93
     * Get iterator for subtrees.
94
     *
95
     * @see \IteratorAggregate::getIterator()
96
     *
97
     * @return \ArrayIterator
98
     */
99 2
    public function getIterator(): \ArrayIterator
100
    {
101 2
        return new \ArrayIterator($this->_subtrees);
102
    }
103
}
104