Function validatePDF
has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring. Open
public static function validatePDF(string $pdf) : array
{
$signers = [];
$matches = [];
$current = -1;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
The class P7S has an overall complexity of 63 which is very high. The configured complexity threshold is 50. Open
class P7S
{
protected $p7s;
protected $raw;
- Exclude checks
Method validateXML
has 72 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function validateXML(string $xmlContent, ?Certificate $crt = null) : array
{
$xml = new \DOMDocument();
$xml->preserveWhiteSpace = true;
$xml->formatOutput = false;
File P7S.php
has 275 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace vakata\certificate;
use vakata\asn1\ASN1;
Function getSigners
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
public function getSigners() : array
{
$signers = [];
foreach ($this->p7s->toArray()['data']['signerInfos'] as $k => $v) {
$signers[$k] = [
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method validatePDF
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function validatePDF(string $pdf) : array
{
$signers = [];
$matches = [];
$current = -1;
Function validateXML
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public static function validateXML(string $xmlContent, ?Certificate $crt = null) : array
{
$xml = new \DOMDocument();
$xml->preserveWhiteSpace = true;
$xml->formatOutput = false;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getSigners
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getSigners() : array
{
$signers = [];
foreach ($this->p7s->toArray()['data']['signerInfos'] as $k => $v) {
$signers[$k] = [
Function validate
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function validate(string $data, bool $hashOnly = false) : array
{
$signers = $this->getSigners();
foreach ($this->p7s->toArray()['data']['signerInfos'] as $k => $v) {
$signers[$k]['valid'] = false;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
The method validatePDF() has a Cyclomatic Complexity of 20. The configured cyclomatic complexity threshold is 10. Open
public static function validatePDF(string $pdf) : array
{
$signers = [];
$matches = [];
$current = -1;
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method validateXML() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public static function validateXML(string $xmlContent, ?Certificate $crt = null) : array
{
$xml = new \DOMDocument();
$xml->preserveWhiteSpace = true;
$xml->formatOutput = false;
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Missing class import via use statement (line '232', column '28'). Open
$tmp = new \DOMDocument();
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '209', column '20'). Open
$xml = new \DOMDocument();
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Avoid using static access to class '\vakata\asn1\Encoder' in method 'validateXML'. Open
$sig = Encoder::encode([
'i1' => substr($sig, 0, strlen($sig) / 2),
'i2' => substr($sig, strlen($sig) / 2),
], $map);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'vakata\certificate\Signature' in method 'validateXML'. Open
(Signature::verify($dat1, $sig, $pub, $alg) || Signature::verify($dat2, $sig, $pub, $alg))
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\vakata\asn1\structures\TimestampResponse' in method 'getSigners'. Open
)->map(TimestampResponse::mapToken());
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\vakata\asn1\structures\P7S' in method '__construct'. Open
$raw = Parser::map();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'vakata\certificate\Signature' in method 'validate'. Open
$signers[$k]['valid'] = $dHash === $signers[$k]['hash'] && Signature::verify(
$signed,
base64_decode($v['signature']),
Certificate::fromString($signers[$k]['certificate'])->getPublicKey(),
$signers[$k]['algorithm']
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\vakata\asn1\ASN1' in method 'getSigners'. Open
'algorithm' => ASN1::OIDtoText($v['digest_algo']['algorithm']),
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'vakata\certificate\Certificate' in method 'validateXML'. Open
$crt = Certificate::fromString(base64_decode($crt));
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'vakata\certificate\Signature' in method 'validateXML'. Open
(Signature::verify($dat1, $sig, $pub, $alg) || Signature::verify($dat2, $sig, $pub, $alg))
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\vakata\asn1\ASN1' in method 'getSigners'. Open
ASN1::OIDtoText(
$timestamp['messageImprint']['hashAlgorithm']['algorithm']
),
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'vakata\certificate\Certificate' in method 'getSigners'. Open
$cert = Certificate::fromString(
$this->raw['data']['certificates'][$kk]
);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\vakata\asn1\structures\P7S' in method '__construct'. Open
$this->p7s = Parser::fromString($data);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid unused local variables such as '$sHash'. Open
$sHash = $dHash;
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Line exceeds 120 characters; contains 124 characters Open
$raw['children']['data']['children']['signerInfos']['repeat']['children']['signed']['tag'] = ASN1::TYPE_ANY_DER;
- Exclude checks
Line exceeds 120 characters; contains 135 characters Open
$ranges = explode(' ', trim(explode(']', (explode('[', (explode('ByteRange', $obj, 2)[1] ?? ''), 2)[1] ?? ''), 2)[0]));
- Exclude checks
Line exceeds 120 characters; contains 136 characters Open
$signature = hex2bin(explode('>', explode('/Contents<', str_replace(["\r","\n","\t", " "], '', $obj), 2)[1], 2)[0]);
- Exclude checks
Multi-line function call not indented correctly; expected 28 spaces but found 32 Open
true
- Exclude checks
Multi-line function call not indented correctly; expected 24 spaces but found 28 Open
)
- Exclude checks
Multi-line function call not indented correctly; expected 28 spaces but found 32 Open
base64_decode($v['signature']),
- Exclude checks
Closing brace must be on a line by itself Open
} catch (\Throwable $e) { continue; }
- Exclude checks
Multi-line function call not indented correctly; expected 28 spaces but found 32 Open
ASN1::OIDtoText(
- Exclude checks
Newline required after opening brace Open
} catch (\Throwable $e) { continue; }
- Exclude checks
Whitespace found at end of line Open
'valid' => $dig === $tmp &&
- Exclude checks