Showing 93 of 93 total issues
Function dumpCoverage
has a Cognitive Complexity of 94 (exceeds 5 allowed). Consider refactoring. Open
public function dumpCoverage(bool $output = false, string $directory = null)
{
if ($directory) {
static::addEmptyDirectory($directory);
foreach (static::$assets as $asset) {
- 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
File Coverage.php
has 412 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace Phug\Tester;
use Phug\Ast\NodeInterface as AstNodeInterface;
Method dumpCoverage
has 146 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function dumpCoverage(bool $output = false, string $directory = null)
{
if ($directory) {
static::addEmptyDirectory($directory);
foreach (static::$assets as $asset) {
Coverage
has 29 functions (exceeds 20 allowed). Consider refactoring. Open
class Coverage
{
const VERSION = '0.1.0';
/**
The class Coverage has an overall complexity of 101 which is very high. The configured complexity threshold is 50. Open
class Coverage
{
const VERSION = '0.1.0';
/**
- Exclude checks
Function exec
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
protected function exec(array $arguments): bool
{
$phpunit = $this->getVendorScript('phpunit/phpunit/phpunit');
$phpunitArguments = [$phpunit];
$textCoverage = 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 exec
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function exec(array $arguments): bool
{
$phpunit = $this->getVendorScript('phpunit/phpunit/phpunit');
$phpunitArguments = [$phpunit];
$textCoverage = false;
Avoid excessively long variable names like $thresholdValueArgLength. Keep variable name length under 20. Open
$thresholdValueArgLength = strlen($thresholdValueArg);
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $coverageStoppingAllowed. Keep variable name length under 20. Open
protected $coverageStoppingAllowed = true;
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Function getLocationPath
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function getLocationPath(string $path): string
{
foreach ($this->getPaths() as $base) {
$realBase = realpath($base);
if ($realBase) {
- 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 emptyDirectory
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
protected static function emptyDirectory(string $dir)
{
if (!is_dir($dir)) {
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
Avoid variables with short names like $id. Configured minimum length is 3. Open
$id = $number + 1;
- 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;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid deeply nested control flow statements. Open
if (!($node instanceof DocumentNode) && ($location = $node->getSourceLocation())) {
$locationPath = $location->getPath();
if (!isset($counts[$locationPath])) {
$counts[$locationPath] = $this->countFileNodes($locationPath);
}
The method run has a boolean flag argument $exit, which is a certain sign of a Single Responsibility Principle violation. Open
public function run(array $arguments, $exit = true): bool
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method getTemplateFile() contains an eval expression. Open
eval("?>$__php");
- Read upRead up
- Exclude checks
EvalExpression
Since: 0.2
An eval-expression is untestable, a security risk and bad practice. Therefore it should be avoided. Consider to replace the eval-expression with regular code.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
eval('$param = 23;');
}
}
}
Source https://phpmd.org/rules/design.html#evalexpression
Missing class import via use statement (line '185', column '23'). Open
throw new \BadFunctionCallException('You need to install XDebug to use coverage feature.');
- 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
The method dumpCoverage has a boolean flag argument $output, which is a certain sign of a Single Responsibility Principle violation. Open
public function dumpCoverage(bool $output = false, string $directory = null)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Avoid assigning values to variables in if clauses and the like (line '361', column '74'). Open
public function dumpCoverage(bool $output = false, string $directory = null)
{
if ($directory) {
static::addEmptyDirectory($directory);
foreach (static::$assets as $asset) {
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
The method run() contains an exit expression. Open
exit($result ? 0 : 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 dumpCoverage() has an NPath complexity of 3646296. The configured NPath complexity threshold is 200. Open
public function dumpCoverage(bool $output = false, string $directory = null)
{
if ($directory) {
static::addEmptyDirectory($directory);
foreach (static::$assets as $asset) {
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}