• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlocati / ocsp / 3930993832

pending completion
3930993832

push

github

GitHub
Merge pull request #9 from mlocati/gh-actions

6 of 6 new or added lines in 3 files covered. (100.0%)

446 of 669 relevant lines covered (66.67%)

1.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.77
/src/Asn1/Element/AbstractList.php
1
<?php
2

3
namespace Ocsp\Asn1\Element;
4

5
use Ocsp\Asn1\Element;
6
use Ocsp\Asn1\Encoder;
7
use Ocsp\Asn1\TaggableElement;
8
use Ocsp\Asn1\TaggableElementTrait;
9

10
/**
11
 * Base handy class for CONSTRUCTED ASN.1 elements.
12
 */
13
abstract class AbstractList implements TaggableElement
14
{
15
    use TaggableElementTrait;
16

17
    /**
18
     * The child elements.
19
     *
20
     * @var \Ocsp\Asn1\Element[]
21
     */
22
    private $elements = [];
23

24
    /**
25
     * {@inheritdoc}
26
     *
27
     * @see \Ocsp\Asn1\Element::getClass()
28
     */
29
    public function getClass()
30
    {
31
        return static::CLASS_UNIVERSAL;
3✔
32
    }
33

34
    /**
35
     * {@inheritdoc}
36
     *
37
     * @see \Ocsp\Asn1\Element::isConstructed()
38
     */
39
    public function isConstructed()
40
    {
41
        return true;
2✔
42
    }
43

44
    /**
45
     * Get the child elements.
46
     *
47
     * @return \Ocsp\Asn1\Element[]
48
     */
49
    public function getElements()
50
    {
51
        return $this->elements;
3✔
52
    }
53

54
    /**
55
     * Add a new child element.
56
     *
57
     * @param \Ocsp\Asn1\Element $element
58
     *
59
     * @return $this
60
     */
61
    public function addElement(Element $element)
62
    {
63
        $this->elements[] = $element;
3✔
64

65
        return $this;
3✔
66
    }
67

68
    /**
69
     * Add child elements.
70
     *
71
     * @param \Ocsp\Asn1\Element[] $elements
72
     *
73
     * @return $this
74
     */
75
    public function addElements(array $elements)
76
    {
77
        foreach ($elements as $element) {
3✔
78
            $this->addElement($element);
3✔
79
        }
80

81
        return $this;
3✔
82
    }
83

84
    /**
85
     * {@inheritdoc}
86
     *
87
     * @see \Ocsp\Asn1\Element::getEncodedValue()
88
     */
89
    public function getEncodedValue(Encoder $encoder)
90
    {
91
        $elementBytes = [];
2✔
92
        foreach ($this->getElements() as $element) {
2✔
93
            $elementBytes[] = $encoder->encodeElement($element);
2✔
94
        }
95

96
        return implode('', $elementBytes);
2✔
97
    }
98

99
    /**
100
     * Find the first child of a specific type.
101
     *
102
     * @param int|string|\phpseclib\Math\BigInteger $typeID
103
     * @param string $class
104
     * @param string $tagEnvironment
105
     *
106
     * @return \Ocsp\Asn1\Element|null
107
     */
108
    public function getFirstChildOfType($typeID, $class = Element::CLASS_UNIVERSAL, $tagEnvironment = '')
109
    {
110
        return $this->getNthChildOfType(1, $typeID, $class, $tagEnvironment);
3✔
111
    }
112

113
    /**
114
     * Find the Nth child of a specific type.
115
     *
116
     * @param int $position
117
     * @param int|string|\phpseclib\Math\BigInteger $typeID
118
     * @param string $class
119
     * @param string $tagEnvironment
120
     *
121
     * @return \Ocsp\Asn1\Element|null
122
     */
123
    public function getNthChildOfType($position, $typeID, $class = Element::CLASS_UNIVERSAL, $tagEnvironment = '')
124
    {
125
        $typeIDString = (string) $typeID;
3✔
126
        $found = 0;
3✔
127
        foreach ($this->getElements() as $element) {
3✔
128
            $tag = $element instanceof TaggableElement ? $element->getTag() : null;
3✔
129
            $actualTypeIDString = (string) ($tag === null ? $element->getTypeID() : $tag->getTagID());
3✔
130
            if ($actualTypeIDString !== $typeIDString) {
3✔
131
                continue;
3✔
132
            }
133
            $actualClass = $tag === null ? $element->getClass() : $tag->getClass();
3✔
134
            if ($actualClass !== $class) {
3✔
135
                continue;
3✔
136
            }
137
            if ($tagEnvironment === '') {
3✔
138
                if ($tag !== null) {
3✔
139
                    continue;
3✔
140
                }
141
            } else {
142
                if ($tag === null || $tag->getEnvironment() !== $tagEnvironment) {
3✔
143
                    continue;
×
144
                }
145
            }
146
            $found++;
3✔
147
            if ($found === $position) {
3✔
148
                return $element;
3✔
149
            }
150
        }
151

152
        return null;
×
153
    }
154

155
    /**
156
     * Find the Nth child of an untagged element with a specific class.
157
     *
158
     * @param int $position
159
     * @param string $class
160
     *
161
     * @return \Ocsp\Asn1\Element|null
162
     */
163
    public function getNthUntaggedChild($position, $class)
164
    {
165
        $found = 0;
×
166
        foreach ($this->getElements() as $element) {
×
167
            if ($element instanceof TaggableElement) {
×
168
                if ($element->getTag() !== null) {
×
169
                    continue;
×
170
                }
171
            }
172
            if ($element->getClass() !== $class) {
×
173
                continue;
×
174
            }
175
            $found++;
×
176
            if ($found === $position) {
×
177
                return $element;
×
178
            }
179
        }
180

181
        return null;
×
182
    }
183
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc