File IncompatibleXMLSignatureDetector.php
has 878 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
declare(strict_types=1);
use Phan\Config;
IncompatibleXMLSignatureDetector
has 45 functions (exceeds 20 allowed). Consider refactoring. Open
class IncompatibleXMLSignatureDetector extends IncompatibleSignatureDetectorBase
{
use Memoize;
/** @var string the directory for english PHP element references */
Method main
has 86 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function main(): void
{
error_reporting(E_ALL);
ini_set('memory_limit', '2G');
global $argv;
The class IncompatibleXMLSignatureDetector has 26 non-getter- and setter-methods. Consider refactoring IncompatibleXMLSignatureDetector to keep number of methods under 25. Open
class IncompatibleXMLSignatureDetector extends IncompatibleSignatureDetectorBase
{
use Memoize;
/** @var string the directory for english PHP element references */
- Read upRead up
- Exclude checks
TooManyMethods
Since: 0.1
A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
The default was changed from 10 to 25 in PHPMD 2.3.
Example
Source https://phpmd.org/rules/codesize.html#toomanymethods
The class IncompatibleXMLSignatureDetector has an overall complexity of 204 which is very high. The configured complexity threshold is 50. Open
class IncompatibleXMLSignatureDetector extends IncompatibleSignatureDetectorBase
{
use Memoize;
/** @var string the directory for english PHP element references */
- Exclude checks
Function main
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public static function main(): void
{
error_reporting(E_ALL);
ini_set('memory_limit', '2G');
global $argv;
- 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 compareNamedParameters
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function compareNamedParameters(): void
{
if (PHP_MAJOR_VERSION < 8) {
fwrite(STDERR, "compare-named-parameters MUST BE RUN IN PHP 8.0+, BUT WAS RUN IN " . PHP_VERSION . "\n");
fwrite(STDERR, "exiting without generating stubs\n");
Function getMethodsForClassName
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function getMethodsForClassName(string $class_name): ?array
{
$class_name_lc = strtolower($class_name);
$class_name_file_map = $this->getFoldersForClassNameList();
$class_name_files = $class_name_file_map[$class_name_lc] ?? null;
- 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 getMethodsForClassName
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getMethodsForClassName(string $class_name): ?array
{
$class_name_lc = strtolower($class_name);
$class_name_file_map = $this->getFoldersForClassNameList();
$class_name_files = $class_name_file_map[$class_name_lc] ?? null;
Function parseClassName
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
private function parseClassName(string $folder_in_reference_directory): string
{
foreach ($this->getPossibleFilesInReferenceDirectory($folder_in_reference_directory) as $file_in_reference_directory) {
//echo "Looking for $file_in_reference_directory\n";
if (file_exists($file_in_reference_directory)) {
- 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
Function compareNamedParameters
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public static function compareNamedParameters(): void
{
if (PHP_MAJOR_VERSION < 8) {
fwrite(STDERR, "compare-named-parameters MUST BE RUN IN PHP 8.0+, BUT WAS RUN IN " . PHP_VERSION . "\n");
fwrite(STDERR, "exiting without generating stubs\n");
- 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 getClassXMLFiles
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getClassXMLFiles(): array
{
return $this->memoize(__METHOD__, /** @return array<string,SimpleXMLElement> */ function (): array {
$remaining_folders = [
$this->reference_directory,
Method getAvailableMethodPHPDocSummaries
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function getAvailableMethodPHPDocSummaries(): array
{
return $this->memoize(__METHOD__, /** @return array<string,string> */ function (): array {
$method_name_map = [];
$maybe_add_refpurpose = static function (string $name, SimpleXMLElement $xml) use (&$method_name_map): void {
Method getAvailablePropertyPHPDocSummaries
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function getAvailablePropertyPHPDocSummaries(): array
{
return $this->memoize(__METHOD__, /** @return array<string,string> */ function (): array {
$map = [];
foreach ($this->getClassXMLFiles() as $xml) {
Function extractConstantEntries
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private static function extractConstantEntries(array $constants_entries): array
{
$result = [];
foreach ($constants_entries as $entry) {
$entry->registerXPathNamespace('a', 'http://docbook.org/ns/docbook');
- 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
Function extractMethodParams
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private static function extractMethodParams(SimpleXMLElement $param): array
{
if ($param->count() === 0) {
return [];
}
- 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
Function computeKnownEntities
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function computeKnownEntities(): array
{
$this->known_entities = [];
foreach (['doc-base/entities/global.ent', 'en/contributors.ent', 'en/extensions.ent', 'en/language-defs.ent', 'en/language-snippets.ent'] as $sub_path) {
$abs_path = "$this->doc_base_directory/$sub_path";
- 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
Function parseAliases
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function parseAliases(): array
{
$file_name = $this->doc_base_directory . '/en/appendices/aliases.xml';
$xml = $this->getSimpleXMLForFile($file_name);
if (!$xml) {
- 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
Function scandirForXML
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static function scandirForXML(string $dir): array
{
$result = [];
foreach (static::scandir($dir) as $basename) {
if (substr($basename, -4) !== '.xml') {
- 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
Function getMethodNameFromXML
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static function getMethodNameFromXML(SimpleXMLElement $xml): ?string
{
$name = $xml->xpath('/a:refentry/a:refnamediv/a:refname') ?: [];
if (count($name) === 0) {
return null;
- 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 IncompatibleXMLSignatureDetector has 1135 lines of code. Current threshold is 1000. Avoid really long classes. Open
class IncompatibleXMLSignatureDetector extends IncompatibleSignatureDetectorBase
{
use Memoize;
/** @var string the directory for english PHP element references */
- Exclude checks
The method getAvailableMethodPHPDocSummaries() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
protected function getAvailableMethodPHPDocSummaries(): array
{
return $this->memoize(__METHOD__, /** @return array<string,string> */ function (): array {
$method_name_map = [];
$maybe_add_refpurpose = static function (string $name, SimpleXMLElement $xml) use (&$method_name_map): void {
- 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 main() has a Cyclomatic Complexity of 20. The configured cyclomatic complexity threshold is 10. Open
public static function main(): void
{
error_reporting(E_ALL);
ini_set('memory_limit', '2G');
global $argv;
- 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 compareNamedParameters() contains an exit expression. Open
exit(0);
- Read upRead up
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}
Source https://phpmd.org/rules/design.html#exitexpression
The method expectFunctionLikeSignaturesMatch() contains an exit expression. Open
exit(1);
- Read upRead up
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}
Source https://phpmd.org/rules/design.html#exitexpression
The method compareNamedParameters() contains an exit expression. Open
exit(1);
- Read upRead up
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}
Source https://phpmd.org/rules/design.html#exitexpression
Avoid using count() function in while loops. Open
while (count($remaining_folders) > 0) {
$folder = array_pop($remaining_folders);
if (!$folder) {
// impossible
break;
- Read upRead up
- Exclude checks
CountInLoopExpression
Since: 2.7.0
Using count/sizeof in loops expressions is considered bad practice and is a potential source of many bugs, especially when the loop manipulates an array, as count happens on each iteration.
Example
class Foo {
public function bar()
{
$array = array();
for ($i = 0; count($array); $i++) {
// ...
}
}
}
Source https://phpmd.org/rules/design.html#countinloopexpression
Avoid variables with short names like $i. Configured minimum length is 3. Open
$i = 0;
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}