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

SubjectDirectoryAttributesExtension::_fromDER()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
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 11
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\X501\ASN1\Attribute;
11
use Sop\X509\Feature\AttributeContainer;
12
13
/**
14
 * Implements 'Subject Directory Attributes' certificate extension.
15
 *
16
 * @see https://tools.ietf.org/html/rfc5280#section-4.2.1.8
17
 */
18
class SubjectDirectoryAttributesExtension extends Extension implements \Countable, \IteratorAggregate
19
{
20
    use AttributeContainer;
21
22
    /**
23
     * Constructor.
24
     *
25
     * @param bool      $critical
26
     * @param Attribute ...$attribs One or more Attribute objects
27
     */
28 11
    public function __construct(bool $critical, Attribute ...$attribs)
29
    {
30 11
        parent::__construct(self::OID_SUBJECT_DIRECTORY_ATTRIBUTES, $critical);
31 11
        $this->_attributes = $attribs;
32 11
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 10
    protected static function _fromDER(string $data, bool $critical): Extension
38
    {
39 10
        $attribs = array_map(
40
            function (UnspecifiedType $el) {
41 9
                return Attribute::fromASN1($el->asSequence());
42 10
            }, UnspecifiedType::fromDER($data)->asSequence()->elements());
43 10
        if (!count($attribs)) {
44 1
            throw new \UnexpectedValueException(
45 1
                'SubjectDirectoryAttributes must have at least one Attribute.');
46
        }
47 9
        return new self($critical, ...$attribs);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 16
    protected function _valueASN1(): Element
54
    {
55 16
        if (!count($this->_attributes)) {
56 1
            throw new \LogicException('No attributes');
57
        }
58 15
        $elements = array_map(
59
            function (Attribute $attr) {
60 15
                return $attr->toASN1();
61 15
            }, array_values($this->_attributes));
62 15
        return new Sequence(...$elements);
63
    }
64
}
65