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.
Passed
Push — master ( 95c197...564e5e )
by Joni
04:32
created

Set   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 53
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A sortedSet() 0 14 5
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
     * @return self
32
     */
33 3
    public function sortedSet(): self
34
    {
35 3
        $obj = clone $this;
36 3
        usort($obj->_elements,
37
            function (Element $a, Element $b) {
38 3
                if ($a->typeClass() !== $b->typeClass()) {
39 1
                    return $a->typeClass() < $b->typeClass() ? -1 : 1;
40
                }
41 3
                if ($a->tag() === $b->tag()) {
42 1
                    return 0;
43
                }
44 2
                return $a->tag() < $b->tag() ? -1 : 1;
45 3
            });
46 3
        return $obj;
47
    }
48
49
    /**
50
     * Sort by encoding ascending order.
51
     *
52
     * Used for DER encoding of SET OF type.
53
     *
54
     * @return self
55
     */
56 1
    public function sortedSetOf(): self
57
    {
58 1
        $obj = clone $this;
59 1
        usort($obj->_elements,
60
            function (Element $a, Element $b) {
61 1
                $a_der = $a->toDER();
62 1
                $b_der = $b->toDER();
63 1
                return strcmp($a_der, $b_der);
64 1
            });
65 1
        return $obj;
66
    }
67
}
68