Skip to content

Commit 4dc75ff

Browse files
authored
Trying to remove public constructors (#12)
* Trying to remove public constructors * Fix PHPUnit minimum version See https://stackoverflow.com/questions/70321515/catching-warnings-notices-and-deprecations-with-phpunit-9-4-on-php-8-1-0 * Increased Mutation limits
1 parent 3e61cb6 commit 4dc75ff

File tree

318 files changed

+2932
-2713
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

318 files changed

+2932
-2713
lines changed

.github/stale.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
daysUntilStale: 60
1+
daysUntilStale: 30
22
daysUntilClose: 7
33
staleLabel: wontfix
44
markComment: >

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ st: vendor ## Run static analyse
1818
################################################
1919

2020
ci-mu: vendor ## Mutation tests (for Github only)
21-
vendor/bin/infection --logger-github -s --threads=$(nproc) --min-msi=40 --min-covered-msi=40
21+
vendor/bin/infection --logger-github -s --threads=$(nproc) --min-msi=80 --min-covered-msi=80
2222

2323
.PHONY: ci-cc
2424
ci-cc: vendor ## Show test coverage rates (for CI/CD only)

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"phpstan/phpstan-deprecation-rules": "^1.0",
5959
"phpstan/phpstan-phpunit": "^1.1",
6060
"phpstan/phpstan-strict-rules": "^1.3",
61-
"phpunit/phpunit": "^9.0",
61+
"phpunit/phpunit": "^9.5.5",
6262
"rector/rector": "^0.14",
6363
"roave/security-advisories": "dev-latest",
6464
"symfony/phpunit-bridge": "^6.1",

src/ASN1/Component/Identifier.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static function fromDER(string $data, int &$offset = null): self
103103
$tag = (0b00011111 & $byte);
104104
// long-form identifier
105105
if ($tag === 0x1f) {
106-
$tag = self::_decodeLongFormTag($data, $idx);
106+
$tag = self::decodeLongFormTag($data, $idx);
107107
}
108108
if (isset($offset)) {
109109
$offset = $idx;
@@ -256,7 +256,7 @@ public static function classToName(int $class): string
256256
*
257257
* @return BigInteger Tag number
258258
*/
259-
private static function _decodeLongFormTag(string $data, int &$offset): BigInteger
259+
private static function decodeLongFormTag(string $data, int &$offset): BigInteger
260260
{
261261
$datalen = mb_strlen($data, '8bit');
262262
$tag = BigInteger::of(0);

src/ASN1/Component/Length.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static function fromDER(string $data, int &$offset = null): self
6868
if ($idx + $length > $datalen) {
6969
throw new DecodeException('Unexpected end of data while decoding long form length.');
7070
}
71-
$length = self::_decodeLongFormLength($length, $data, $idx);
71+
$length = self::decodeLongFormLength($length, $data, $idx);
7272
}
7373
}
7474
if (isset($offset)) {
@@ -186,7 +186,7 @@ public function isIndefinite(): bool
186186
* @param string $data Data
187187
* @param int $offset reference to the variable containing offset to the data
188188
*/
189-
private static function _decodeLongFormLength(int $length, string $data, int &$offset): BigInteger
189+
private static function decodeLongFormLength(int $length, string $data, int &$offset): BigInteger
190190
{
191191
// first octet must not be 0xff (spec 8.1.3.5c)
192192
if ($length === 127) {

src/ASN1/DERData.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,28 @@ final class DERData extends Element
2020
/**
2121
* DER encoded data.
2222
*/
23-
protected string $_der;
23+
private readonly string $der;
2424

2525
/**
2626
* Identifier of the underlying type.
2727
*/
28-
protected Identifier $_identifier;
28+
private readonly Identifier $identifier;
2929

3030
/**
3131
* Offset to the content in DER data.
3232
*/
33-
protected int $_contentOffset = 0;
33+
private int $contentOffset = 0;
3434

3535
/**
3636
* @param string $data DER encoded data
3737
*/
3838
private function __construct(string $data)
3939
{
40-
$this->_identifier = Identifier::fromDER($data, $this->_contentOffset);
40+
$this->identifier = Identifier::fromDER($data, $this->contentOffset);
4141
// check that length encoding is valid
42-
Length::expectFromDER($data, $this->_contentOffset);
43-
$this->_der = $data;
44-
parent::__construct($this->_identifier->intTag());
42+
Length::expectFromDER($data, $this->contentOffset);
43+
$this->der = $data;
44+
parent::__construct($this->identifier->intTag());
4545
}
4646

4747
public static function create(string $data): self
@@ -51,26 +51,26 @@ public static function create(string $data): self
5151

5252
public function typeClass(): int
5353
{
54-
return $this->_identifier->typeClass();
54+
return $this->identifier->typeClass();
5555
}
5656

5757
public function isConstructed(): bool
5858
{
59-
return $this->_identifier->isConstructed();
59+
return $this->identifier->isConstructed();
6060
}
6161

6262
public function toDER(): string
6363
{
64-
return $this->_der;
64+
return $this->der;
6565
}
6666

6767
protected function encodedAsDER(): string
6868
{
6969
// if there's no content payload
70-
if (mb_strlen($this->_der, '8bit') === $this->_contentOffset) {
70+
if (mb_strlen($this->der, '8bit') === $this->contentOffset) {
7171
return '';
7272
}
73-
return mb_substr($this->_der, $this->_contentOffset, null, '8bit');
73+
return mb_substr($this->der, $this->contentOffset, null, '8bit');
7474
}
7575

7676
protected static function decodeFromDER(Identifier $identifier, string $data, int &$offset): ElementBase

src/ASN1/Element.php

+18-18
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@ abstract class Element implements ElementBase
218218
];
219219

220220
/**
221-
* @param bool $_indefiniteLength Whether type shall be encoded with indefinite length.
221+
* @param bool $indefiniteLength Whether type shall be encoded with indefinite length.
222222
*/
223223
protected function __construct(
224-
protected int $typeTag,
225-
protected bool $_indefiniteLength = false
224+
protected readonly int $typeTag,
225+
protected bool $indefiniteLength = false
226226
) {
227227
}
228228

@@ -245,7 +245,7 @@ public static function fromDER(string $data, int &$offset = null): static
245245
// decode identifier
246246
$identifier = Identifier::fromDER($data, $idx);
247247
// determine class that implements type specific decoding
248-
$cls = self::_determineImplClass($identifier);
248+
$cls = self::determineImplClass($identifier);
249249
// decode remaining element
250250
$element = $cls::decodeFromDER($identifier, $data, $idx);
251251
// if called in the context of a concrete class, check
@@ -271,7 +271,7 @@ public function toDER(): string
271271
$this->typeTag
272272
);
273273
$content = $this->encodedAsDER();
274-
if ($this->_indefiniteLength) {
274+
if ($this->indefiniteLength) {
275275
$length = Length::create(0, true);
276276
$eoc = EOC::create();
277277
return $identifier->toDER() . $length->toDER() . $content . $eoc->toDER();
@@ -293,16 +293,16 @@ public function isType(int $tag): bool
293293
}
294294
// negative tags identify an abstract pseudotype
295295
if ($tag < 0) {
296-
return $this->_isPseudoType($tag);
296+
return $this->isPseudoType($tag);
297297
}
298-
return $this->_isConcreteType($tag);
298+
return $this->isConcreteType($tag);
299299
}
300300

301301
public function expectType(int $tag): ElementBase
302302
{
303303
if (! $this->isType($tag)) {
304304
throw new UnexpectedValueException(
305-
sprintf('%s expected, got %s.', self::tagToName($tag), $this->_typeDescriptorString())
305+
sprintf('%s expected, got %s.', self::tagToName($tag), $this->typeDescriptorString())
306306
);
307307
}
308308
return $this;
@@ -331,7 +331,7 @@ public function expectTagged(?int $tag = null): TaggedType
331331
*/
332332
public function hasIndefiniteLength(): bool
333333
{
334-
return $this->_indefiniteLength;
334+
return $this->indefiniteLength;
335335
}
336336

337337
/**
@@ -342,7 +342,7 @@ public function hasIndefiniteLength(): bool
342342
public function withIndefiniteLength(bool $indefinite = true): self
343343
{
344344
$obj = clone $this;
345-
$obj->_indefiniteLength = $indefinite;
345+
$obj->indefiniteLength = $indefinite;
346346
return $obj;
347347
}
348348

@@ -391,11 +391,11 @@ abstract protected static function decodeFromDER(Identifier $identifier, string
391391
*
392392
* @return string Class name
393393
*/
394-
protected static function _determineImplClass(Identifier $identifier): string
394+
protected static function determineImplClass(Identifier $identifier): string
395395
{
396396
switch ($identifier->typeClass()) {
397397
case Identifier::CLASS_UNIVERSAL:
398-
$cls = self::_determineUniversalImplClass($identifier->intTag());
398+
$cls = self::determineUniversalImplClass($identifier->intTag());
399399
// constructed strings may be present in BER
400400
if ($identifier->isConstructed()
401401
&& is_subclass_of($cls, StringType::class)) {
@@ -421,7 +421,7 @@ protected static function _determineImplClass(Identifier $identifier): string
421421
*
422422
* @return string Class name
423423
*/
424-
protected static function _determineUniversalImplClass(int $tag): string
424+
protected static function determineUniversalImplClass(int $tag): string
425425
{
426426
if (! array_key_exists($tag, self::MAP_TAG_TO_CLASS)) {
427427
throw new UnexpectedValueException("Universal tag {$tag} not implemented.");
@@ -432,7 +432,7 @@ protected static function _determineUniversalImplClass(int $tag): string
432432
/**
433433
* Get textual description of the type for debugging purposes.
434434
*/
435-
protected function _typeDescriptorString(): string
435+
protected function typeDescriptorString(): string
436436
{
437437
if ($this->typeClass() === Identifier::CLASS_UNIVERSAL) {
438438
return self::tagToName($this->typeTag);
@@ -441,17 +441,17 @@ protected function _typeDescriptorString(): string
441441
}
442442

443443
/**
444-
* Check whether the element is a concrete type of a given tag.
444+
* Check whether the element is a concrete type of given tag.
445445
*/
446-
private function _isConcreteType(int $tag): bool
446+
private function isConcreteType(int $tag): bool
447447
{
448448
// if tag doesn't match
449449
if ($this->tag() !== $tag) {
450450
return false;
451451
}
452452
// if type is universal check that instance is of a correct class
453453
if ($this->typeClass() === Identifier::CLASS_UNIVERSAL) {
454-
$cls = self::_determineUniversalImplClass($tag);
454+
$cls = self::determineUniversalImplClass($tag);
455455
if (! $this instanceof $cls) {
456456
return false;
457457
}
@@ -462,7 +462,7 @@ private function _isConcreteType(int $tag): bool
462462
/**
463463
* Check whether the element is a pseudotype.
464464
*/
465-
private function _isPseudoType(int $tag): bool
465+
private function isPseudoType(int $tag): bool
466466
{
467467
return match ($tag) {
468468
self::TYPE_STRING => $this instanceof StringType,

src/ASN1/Type/BaseString.php

+11-6
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ abstract class BaseString extends Element implements StringType, Stringable
1616
/**
1717
* String value.
1818
*/
19-
protected string $_string;
19+
private readonly string $string;
2020

21-
public function __construct(int $typeTag, string $string)
21+
protected function __construct(int $typeTag, string $string)
2222
{
2323
parent::__construct($typeTag);
24-
if (! $this->_validateString($string)) {
24+
if (! $this->validateString($string)) {
2525
throw new InvalidArgumentException(sprintf('Not a valid %s string.', self::tagToName($this->typeTag)));
2626
}
27-
$this->_string = $string;
27+
$this->string = $string;
2828
}
2929

3030
public function __toString(): string
@@ -37,13 +37,18 @@ public function __toString(): string
3737
*/
3838
public function string(): string
3939
{
40-
return $this->_string;
40+
return $this->string;
41+
}
42+
43+
protected function encodedAsDER(): string
44+
{
45+
return $this->string;
4146
}
4247

4348
/**
4449
* Check whether string is valid for the concrete type.
4550
*/
46-
protected function _validateString(string $string): bool
51+
protected function validateString(string $string): bool
4752
{
4853
// Override in derived classes
4954
return true;

src/ASN1/Type/BaseTime.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ abstract class BaseTime extends Element implements TimeType, Stringable
2020
*/
2121
public const TZ_UTC = 'UTC';
2222

23-
public function __construct(
23+
protected function __construct(
2424
int $typeTag,
25-
protected readonly DateTimeImmutable $_dateTime
25+
protected readonly DateTimeImmutable $dateTime
2626
) {
2727
parent::__construct($typeTag);
2828
}
@@ -46,7 +46,7 @@ abstract public static function fromString(string $time): static;
4646
*/
4747
public function dateTime(): DateTimeImmutable
4848
{
49-
return $this->_dateTime;
49+
return $this->dateTime;
5050
}
5151

5252
/**

src/ASN1/Type/Constructed/ConstructedString.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ protected static function decodeIndefiniteLength(int $typeTag, string $data, int
150150
}
151151
$offset = $idx;
152152
$type = self::createWithTag($typeTag, ...$elements);
153-
$type->_indefiniteLength = true;
153+
$type->indefiniteLength = true;
154154
return $type;
155155
}
156156
}

src/ASN1/Type/Constructed/Sequence.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected static function decodeIndefiniteLength(string $data, int &$offset): se
8686
}
8787
$offset = $idx;
8888
$type = self::create(...$elements);
89-
$type->_indefiniteLength = true;
89+
$type->indefiniteLength = true;
9090
return $type;
9191
}
9292
}

src/ASN1/Type/Constructed/Set.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ protected static function decodeIndefiniteLength(string $data, int &$offset): El
129129
}
130130
$offset = $idx;
131131
$type = self::create(...$elements);
132-
$type->_indefiniteLength = true;
132+
$type->indefiniteLength = true;
133133
return $type;
134134
}
135135
}

src/ASN1/Type/Primitive/BMPString.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static function create(string $string): self
2727
return new self($string);
2828
}
2929

30-
protected function _validateString(string $string): bool
30+
protected function validateString(string $string): bool
3131
{
3232
// UCS-2 has fixed with of 2 octets (16 bits)
3333
return mb_strlen($string, '8bit') % 2 === 0;

0 commit comments

Comments
 (0)