Skip to content

Commit 47e82b8

Browse files
committed
phpcs fix
1 parent 304cc40 commit 47e82b8

31 files changed

+245
-263
lines changed

src/ASN1/ASN1Object.php

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@
3939
use FG\ASN1\Universal\ObjectDescriptor;
4040

4141
/**
42-
* @property ASN1Object $parent
43-
* @property ASN1Object[] $children
42+
* @property ASN1Object $parent
43+
* @property ASN1Object[] $children
4444
* @property ContentLength $contentLength
45-
* @property Content $content
46-
* @property Identifier $identifier
47-
*
45+
* @property Content $content
46+
* @property Identifier $identifier
4847
* Class Object is the base class for all concrete ASN.1 objects.
4948
*/
5049
abstract class ASN1Object
@@ -63,7 +62,8 @@ public function __construct(
6362
ContentLength $contentLength,
6463
Content $content,
6564
array $children = []
66-
) {
65+
)
66+
{
6767
$this->identifier = $identifier;
6868
$this->contentLength = $contentLength;
6969
$this->content = $content;
@@ -91,9 +91,7 @@ private function addChildren(array $children)
9191

9292
/**
9393
* Encode the object using DER encoding.
94-
*
9594
* @see http://en.wikipedia.org/wiki/X.690#DER_encoding
96-
*
9795
* @return string the binary representation of an objects value
9896
*/
9997
abstract protected function getEncodedValue();
@@ -139,10 +137,11 @@ public function getObjectLength()
139137
abstract public function __toString(): string;
140138

141139
/**
142-
* @param $binaryData
143-
* @param int $offsetIndex
144-
* @param Identifier $identifier
140+
* @param $binaryData
141+
* @param int $offsetIndex
142+
* @param Identifier $identifier
145143
* @param ContentLength $contentLength
144+
*
146145
* @return Object[]
147146
* @throws ParserException
148147
*/
@@ -153,9 +152,9 @@ public static function parseChildren(&$binaryData, &$offsetIndex = 0, ContentLen
153152
$octetsToRead = $contentLength->getLength();
154153
while ($octetsToRead > 0) {
155154
$newChild = ASN1Object::fromBinary($binaryData, $offsetIndex);
156-
if(is_null($newChild)) throw new ParserException('Children not found', $offsetIndex);
155+
if (is_null($newChild)) throw new ParserException('Children not found', $offsetIndex);
157156
$octetsToRead -= ($newChild->contentLength->getLength() + $newChild->identifier->getNrOfOctets() + $newChild->contentLength->getNrOfOctets());
158-
$children[] = $newChild;
157+
$children[] = $newChild;
159158
}
160159
} else {
161160
/*try {*/
@@ -173,7 +172,7 @@ public static function parseChildren(&$binaryData, &$offsetIndex = 0, ContentLen
173172

174173
/**
175174
* @param string $binaryData
176-
* @param int $offsetIndex
175+
* @param int $offsetIndex
177176
*
178177
* @throws ParserException
179178
* @return ASN1Object
@@ -199,11 +198,11 @@ public static function fromBinary(&$binaryData, &$offsetIndex = 0)
199198
//разница между текущем положением сдвига и стартовым - длина детей, блина контента составного элемента
200199
$contentLength->length = abs($startPos - $offsetIndex);
201200
} else {
202-
if($contentLength->form === ContentLength::INDEFINITE_FORM) {
201+
if ($contentLength->form === ContentLength::INDEFINITE_FORM) {
203202
for (; ;) {
204-
$firstOctet = $binaryData[$offsetIndex];
203+
$firstOctet = $binaryData[$offsetIndex];
205204
$secondOctet = $binaryData[$offsetIndex++];
206-
if($firstOctet.$secondOctet === chr(0) . chr(0)) {
205+
if ($firstOctet . $secondOctet === chr(0) . chr(0)) {
207206
$contentLength->length = abs($startPos - $offsetIndex) + 1;
208207
break;
209208
}
@@ -217,7 +216,7 @@ public static function fromBinary(&$binaryData, &$offsetIndex = 0)
217216
}
218217

219218
//todo exception raises when object not constructed and length form is indefinite - its wrong
220-
if(!is_int($contentLength->length)) {
219+
if (!is_int($contentLength->length)) {
221220
throw new ParserException('Length of Object not determined', $offsetIndex);
222221
}
223222

@@ -316,7 +315,7 @@ protected static function parseBinaryIdentifier($binaryData, &$offsetIndex)
316315
if (strlen($binaryData) <= $offsetIndex) {
317316
throw new ParserException('Can not parse identifier (long form) from data: Offset index larger than input size', $offsetIndex);
318317
}
319-
$nextOctet = $binaryData[$offsetIndex++];
318+
$nextOctet = $binaryData[$offsetIndex++];
320319
$identifier .= $nextOctet;
321320

322321
if ((ord($nextOctet) & 0x80) === 0) {
@@ -335,7 +334,7 @@ protected static function parseContentLength(&$binaryData, &$offsetIndex)
335334
}
336335

337336
$contentLengthOctets = $binaryData[$offsetIndex++];
338-
$firstOctet = ord($contentLengthOctets);
337+
$firstOctet = ord($contentLengthOctets);
339338

340339
if (($firstOctet & 0x80) != 0) {
341340
// bit 8 is set -> this is the long form
@@ -371,14 +370,14 @@ public function findByOid(string $oidString): array
371370
{
372371
$objects = [];
373372

374-
if ($this instanceof ObjectIdentifier && (string) $this === $oidString) {
373+
if ($this instanceof ObjectIdentifier && (string)$this === $oidString) {
375374
return [$this];
376375
}
377376

378-
if($this->isConstructed()) {
377+
if ($this->isConstructed()) {
379378
foreach ($this->children as $child) {
380379
$objectsFound = $child->findByOid($oidString);
381-
if(count($objectsFound) > 0) {
380+
if (count($objectsFound) > 0) {
382381
array_push($objects, ...$objectsFound);
383382
}
384383
}
@@ -391,12 +390,12 @@ public function findByOid(string $oidString): array
391390

392391
public function remove()
393392
{
394-
if($this->parent) {
393+
if ($this->parent) {
395394
foreach ($this->parent->children as $key => $child) {
396-
if($child === $this) {
397-
unset($this->parent->children[$key]);
398-
$this->parent->children = $this->parent->getChildren();
399-
$this->parent->rebuildTree();
395+
if ($child === $this) {
396+
unset($this->parent->children[$key]);
397+
$this->parent->children = $this->parent->getChildren();
398+
$this->parent->rebuildTree();
400399
}
401400
}
402401

@@ -420,13 +419,13 @@ public function getNrOfOctets(): int
420419
public function rebuildTree()
421420
{
422421
$this->restoreContentFromParts();
423-
if($this->validateLengthContent()) {
422+
if ($this->validateLengthContent()) {
424423
//nothing to rebuild
425424
return true;
426425
} else {
427426
//если форма неопределенная, то и у родителя она тоже неопределенная
428427
// и энкодировать длину ни у одного родителя не нужно - просто изменить контент у всех предков
429-
if($this->contentLength->getLengthForm() === ContentLength::INDEFINITE_FORM) {
428+
if ($this->contentLength->getLengthForm() === ContentLength::INDEFINITE_FORM) {
430429
$this->contentLength->length = $this->content->getNrOfOctets();
431430
} else {
432431
$this->contentLength = ElementBuilder::createContentLength(
@@ -435,12 +434,12 @@ public function rebuildTree()
435434
);
436435
}
437436

438-
if($this->parent) {
437+
if ($this->parent) {
439438
$this->parent->rebuildTree();
440439
}
441440
}
442441

443-
if($this->validateLengthContent()) {
442+
if ($this->validateLengthContent()) {
444443
return true;
445444
} else {
446445
throw new \Exception('Дерево не восстановлено');
@@ -454,7 +453,7 @@ private function validateLengthContent()
454453

455454
private function restoreContentFromParts()
456455
{
457-
if($this->identifier->isConstructed()) {
456+
if ($this->identifier->isConstructed()) {
458457
$contentOctets = '';
459458
foreach ($this->getChildren() as $child) {
460459
$contentOctets .= $child->getBinary();
@@ -478,8 +477,8 @@ final public function isConstructed(): bool
478477
*/
479478
public function getSiblings(): array
480479
{
481-
if($this->parent && $this->parent->isConstructed()) {
482-
$siblings = array_filter($this->parent->getChildren(), function($value) {
480+
if ($this->parent && $this->parent->isConstructed()) {
481+
$siblings = array_filter($this->parent->getChildren(), function ($value) {
483482
return $value !== $this;
484483
});
485484

@@ -507,10 +506,10 @@ public function getParent()
507506

508507
public function insertAfter(ASN1Object $object)
509508
{
510-
if($this->parent) {
509+
if ($this->parent) {
511510
foreach ($this->parent->children as $key => $child) {
512-
if($child === $this) {
513-
if($key + 1 === count($this->parent->children)) {
511+
if ($child === $this) {
512+
if ($key + 1 === count($this->parent->children)) {
514513
array_push($this->parent->children, $object);
515514
} else {
516515
array_splice($this->parent->children, $key + 1, 0, [$object]);
@@ -526,9 +525,9 @@ public function insertAfter(ASN1Object $object)
526525

527526
public function insertBefore(ASN1Object $object)
528527
{
529-
if($this->parent) {
528+
if ($this->parent) {
530529
foreach ($this->parent->children as $key => $child) {
531-
if($child === $this) {
530+
if ($child === $this) {
532531
array_splice($this->parent->children, $key, 0, [$object]);
533532
$object->parent = $this->parent;
534533
$this->parent->rebuildTree();
@@ -541,16 +540,17 @@ public function insertBefore(ASN1Object $object)
541540

542541
/**
543542
* @param string $className
543+
*
544544
* @return \FG\ASN1\ASN1Object[]
545545
* @throws \Exception
546546
*/
547547
public function findChildrenByType($className)
548548
{
549-
if(!class_exists($className)) {
549+
if (!class_exists($className)) {
550550
throw new Exception('Unknown class type object');
551551
}
552552

553-
$children = array_filter($this->children, function($value) use ($className) {
553+
$children = array_filter($this->children, function ($value) use ($className) {
554554
return is_a($value, $className);
555555
});
556556

@@ -559,18 +559,18 @@ public function findChildrenByType($className)
559559

560560
/**
561561
* @param $fileContent
562-
* @return \FG\ASN1\ASN1Object
563562
*
563+
* @return \FG\ASN1\ASN1Object
564564
* @throws \Exception
565565
*/
566566
public final static function fromFile($fileContent)
567567
{
568568
$temp = trim($fileContent);
569-
if(substr($fileContent, 0, 1) === '-') {
569+
if (substr($fileContent, 0, 1) === '-') {
570570
$temp = preg_replace('#.*?^-+[^-]+-+#ms', '', $fileContent, 1);
571-
if(is_null($temp)) throw new \Exception('Preg_error:' . preg_last_error());
571+
if (is_null($temp)) throw new \Exception('Preg_error:' . preg_last_error());
572572
$temp = preg_replace('#--+[^-]+--+#', '', $temp);
573-
if(is_null($temp)) throw new \Exception('Preg_error:' . preg_last_error());
573+
if (is_null($temp)) throw new \Exception('Preg_error:' . preg_last_error());
574574
}
575575

576576
$temp = str_replace(array("\r", "\n", ' '), '', $temp);
@@ -582,7 +582,7 @@ public final static function fromFile($fileContent)
582582

583583
public function detach()
584584
{
585-
$object = clone $this;
585+
$object = clone $this;
586586
$this->parent = null;
587587

588588
return $object;
@@ -593,7 +593,7 @@ public function detach()
593593
*/
594594
public function getRoot()
595595
{
596-
if(is_null($this->parent)) return $this;
596+
if (is_null($this->parent)) return $this;
597597

598598
return $this->parent->getRoot();
599599
}

src/ASN1/AbstractCharacterString.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(Identifier $identifier, ContentLength $contentLength
2525
parent::__construct($identifier, $contentLength, $content, $children);
2626

2727
$this->value = $this->getBinaryContent();
28-
if(count($this->allowedCharacters) > 0) {
28+
if (count($this->allowedCharacters) > 0) {
2929
$this->checkString();
3030
}
3131
}
@@ -45,7 +45,7 @@ protected function allowCharacters(...$characters)
4545
protected function allowNumbers()
4646
{
4747
foreach (range('0', '9') as $char) {
48-
$this->allowedCharacters[] = (string) $char;
48+
$this->allowedCharacters[] = (string)$char;
4949
}
5050
}
5151

src/ASN1/AbstractTime.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ abstract class AbstractTime extends ASN1Object
2121
public function __construct(Identifier $identifier, ContentLength $contentLength, Content $content, array $children = [])
2222
{
2323

24-
parent::__construct($identifier, $contentLength, $content,$children);
24+
parent::__construct($identifier, $contentLength, $content, $children);
2525

26-
if(!$this->identifier->isConstructed) {
26+
if (!$this->identifier->isConstructed) {
2727
$this->setValue($content);
2828
}
2929
}
@@ -46,7 +46,7 @@ public function getStringValue()
4646

4747
protected function getLastDateTimeErrors()
4848
{
49-
$messages = '';
49+
$messages = '';
5050
$lastErrors = DateTime::getLastErrors();
5151
foreach ($lastErrors['errors'] as $errorMessage) {
5252
$messages .= "{$errorMessage}, ";
@@ -62,10 +62,10 @@ public function __toString(): string
6262

6363
protected static function extractTimeZoneData(&$binaryData, &$offsetIndex, DateTime $dateTime)
6464
{
65-
$sign = $binaryData[$offsetIndex++];
66-
$timeOffsetHours = (int) substr($binaryData, $offsetIndex, 2);
67-
$timeOffsetMinutes = (int) substr($binaryData, $offsetIndex + 2, 2);
68-
$offsetIndex += 4;
65+
$sign = $binaryData[$offsetIndex++];
66+
$timeOffsetHours = (int)substr($binaryData, $offsetIndex, 2);
67+
$timeOffsetMinutes = (int)substr($binaryData, $offsetIndex + 2, 2);
68+
$offsetIndex += 4;
6969

7070
$interval = new DateInterval("PT{$timeOffsetHours}H{$timeOffsetMinutes}M");
7171
if ($sign === '+') {

src/ASN1/Base128.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Base128
1616
*/
1717
public static function encode(int $intValue)
1818
{
19-
$value = gmp_init($intValue, 10);
19+
$value = gmp_init($intValue, 10);
2020
$octets = chr(gmp_strval(gmp_and($value, 0x7f), 10));
2121

2222
$rightShift = function ($number, $positions) {
@@ -26,7 +26,7 @@ public static function encode(int $intValue)
2626
$value = $rightShift($value, 7);
2727
while (gmp_cmp($value, 0) > 0) {
2828
$octets .= chr(gmp_strval(gmp_or(0x80, gmp_and($value, 0x7f)), 10));
29-
$value = $rightShift($value, 7);
29+
$value = $rightShift($value, 7);
3030
}
3131

3232
return strrev($octets);
@@ -36,14 +36,13 @@ public static function encode(int $intValue)
3636
* @param string $octets
3737
*
3838
* @throws InvalidArgumentException if the given octets represent a malformed base-128 value or the decoded value would exceed the the maximum integer length
39-
*
4039
* @return int
4140
*/
4241
public static function decode($octets)
4342
{
4443
$bitsPerOctet = 7;
45-
$value = gmp_init(0, 10);
46-
$i = 0;
44+
$value = gmp_init(0, 10);
45+
$i = 0;
4746

4847
$leftShift = function ($number, $positions) {
4948
return gmp_mul($number, gmp_pow(2, $positions));
@@ -56,8 +55,8 @@ public static function decode($octets)
5655

5756
$octet = gmp_init(ord($octets[$i++]), 10);
5857

59-
$l1 = $leftShift($value, $bitsPerOctet);
60-
$r1 = gmp_and($octet, 0x7f);
58+
$l1 = $leftShift($value, $bitsPerOctet);
59+
$r1 = gmp_and($octet, 0x7f);
6160
$value = gmp_add($l1, $r1);
6261

6362
if (0 === gmp_cmp(gmp_and($octet, 0x80), 0)) {

src/ASN1/Construct.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function addChild(ASN1Object $child)
9696
public function __toString(): string
9797
{
9898
$nrOfChildren = $this->getNumberOfChildren();
99-
$childString = $nrOfChildren === 1 ? 'child' : 'children';
99+
$childString = $nrOfChildren === 1 ? 'child' : 'children';
100100

101101
return "[{$nrOfChildren} {$childString}]";
102102
}

0 commit comments

Comments
 (0)