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.

Set::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\ASN1\Type\Constructed;
6
7
use Sop\ASN1\Element;
8
use Sop\ASN1\Type\Structure;
9
10
/**
11
 * Implements *SET* and *SET OF* types.
12
 */
13
class Set extends Structure
14
{
15
    /**
16
     * Constructor.
17
     *
18
     * @param Element ...$elements Any number of elements
19
     */
20 12
    public function __construct(Element ...$elements)
21
    {
22 12
        $this->_typeTag = self::TYPE_SET;
23 12
        parent::__construct(...$elements);
24 12
    }
25
26
    /**
27
     * Sort by canonical ascending order.
28
     *
29
     * Used for DER encoding of *SET* type.
30
     */
31 3
    public function sortedSet(): self
32
    {
33 3
        $obj = clone $this;
34 3
        usort($obj->_elements,
35
            function (Element $a, Element $b) {
36 3
                if ($a->typeClass() !== $b->typeClass()) {
37 1
                    return $a->typeClass() < $b->typeClass() ? -1 : 1;
38
                }
39 3
                if ($a->tag() === $b->tag()) {
40 1
                    return 0;
41
                }
42 2
                return $a->tag() < $b->tag() ? -1 : 1;
43 3
            });
44 3
        return $obj;
45
    }
46
47
    /**
48
     * Sort by encoding ascending order.
49
     *
50
     * Used for DER encoding of *SET OF* type.
51
     */
52 1
    public function sortedSetOf(): self
53
    {
54 1
        $obj = clone $this;
55 1
        usort($obj->_elements,
56
            function (Element $a, Element $b) {
57 1
                $a_der = $a->toDER();
58 1
                $b_der = $b->toDER();
59 1
                return strcmp($a_der, $b_der);
60 1
            });
61 1
        return $obj;
62
    }
63
}
64