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
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 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 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 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
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method dumpCoverage() has 153 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function dumpCoverage(bool $output = false, string $directory = null)
{
if ($directory) {
static::addEmptyDirectory($directory);
foreach (static::$assets as $asset) {
- Exclude checks
The method dumpCoverage() has a Cyclomatic Complexity of 38. The configured cyclomatic complexity threshold is 10. 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
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 '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
Assigning null
to property but \Phug\Tester\Coverage::$singleton
is \Phug\Tester\Coverage
Open
static::$singleton = null;
- Exclude checks
Call to method getSourceLocation
from undeclared class \Phug\Parser\NodeInterface
Open
if (!($node instanceof DocumentNode) && ($location = $node->getSourceLocation())) {
- Exclude checks
Argument 1 (input)
is int
but \str_pad()
takes string
Open
str_pad($coveredNodes, 3, ' ', STR_PAD_LEFT).' / '.
- Exclude checks
Call to method getOption
from undeclared class \Phug\Renderer
Open
static::removeDirectory($this->renderer->getOption('cache_dir'));
- Exclude checks
Call to method getOption
from undeclared class \Phug\Renderer
Open
$cache = $this->renderer->getOption('cache_dir');
- Exclude checks
Call to method getCompiler
from undeclared class \Phug\Renderer
Open
$document = $this->renderer->getCompiler()->getParser()->parse($contents, $file);
- Exclude checks
Checking instanceof against undeclared class \Phug\Parser\NodeInterface
Open
if ($node instanceof NodeInterface && !($node instanceof DocumentNode) && !$list->offsetExists($node)) {
- Exclude checks
Checking instanceof against undeclared class \Phug\Ast\NodeInterface
Open
if ($node instanceof AstNodeInterface) {
- Exclude checks
Argument 1 (input)
is int
but \str_pad()
takes string
Open
str_pad($_nodes, 3, ' ', STR_PAD_LEFT).' '.
- Exclude checks
Call to method getOuterNode
from undeclared class \Phug\Parser\NodeInterface
Open
$node = $node->getOuterNode() ?: $node->getParent()) {
- Exclude checks
Checking instanceof against undeclared class \Phug\Parser\Node\DocumentNode
Open
if (!($node instanceof DocumentNode) && ($location = $node->getSourceLocation())) {
- Exclude checks
Parameter $location
has undeclared type ?\Phug\Util\SourceLocationInterface
Open
protected function recordLocation(SourceLocationInterface $location = null, int $covered = 0)
- Exclude checks
Argument 1 (input)
is 0|int
but \str_pad()
takes string
Open
str_pad($_coveredNodes, 3, ' ', STR_PAD_LEFT).' / '.
- Exclude checks
Call to method getPath
from undeclared class \Phug\Util\SourceLocationInterface
Open
$locationPath = realpath($location->getPath());
- Exclude checks
Call to method getOption
from undeclared class \Phug\Renderer
Open
return $this->renderer->getOption('paths');
- Exclude checks
Call to method scanDirectory
from undeclared class \Phug\Renderer
Open
foreach ($this->renderer->scanDirectory($path) as $file) {
- Exclude checks
Checking instanceof against undeclared class \Phug\Parser\Node\DocumentNode
Open
if ($node instanceof NodeInterface && !($node instanceof DocumentNode) && !$list->offsetExists($node)) {
- Exclude checks
Return type of createRenderer()
is undeclared type \Phug\Renderer
Open
public function createRenderer($renderer, array $options = []): Renderer
- Exclude checks
Call to method getCompiler
from undeclared class \Phug\Renderer
Open
$formatter = $this->renderer->getCompiler()->getFormatter();
- Exclude checks
Call to method getParent
from undeclared class \Phug\Parser\NodeInterface
Open
$node = $node->getOuterNode() ?: $node->getParent()) {
- Exclude checks
Return type of getRenderer()
is undeclared type \Phug\Renderer
Open
public function getRenderer(): Renderer
- Exclude checks
Static property \Phug\Tester\Coverage::$singleton
is declared to have type static,
but the only instance is shared among all subclasses (Did you mean \Phug\Tester\Coverage)
Open
* @var static
- Exclude checks
Call to method getChildren
from undeclared class \Phug\Ast\NodeInterface
Open
foreach ($node->getChildren() as $child) {
- Exclude checks
Call to method getCompiler
from undeclared class \Phug\Renderer
Open
$compiler = $this->renderer->getCompiler();
- Exclude checks
Argument 1 (input)
is int
but \str_pad()
takes string
Open
str_pad($id, $pad, ' ', STR_PAD_LEFT).
- Exclude checks
Call to method getOption
from undeclared class \Phug\Renderer
Open
static::emptyDirectory($this->renderer->getOption('cache_dir'));
- Exclude checks
Call to method getLine
from undeclared class \Phug\Util\SourceLocationInterface
Open
$locationLine = $location->getLine() - 1;
- Exclude checks
Call to method getSourceLocation
from undeclared class \Phug\Parser\NodeInterface
Open
$this->recordLocation($node->getSourceLocation());
- Exclude checks
Argument 1 (input)
is int
but \str_pad()
takes string
Open
str_pad($nodes, 3, ' ', STR_PAD_LEFT).' '.
- Exclude checks
Property \Phug\Tester\Coverage->renderer
has undeclared type \Phug\Renderer
Open
protected $renderer;
- Exclude checks
Call to method setOption
from undeclared class \Phug\Renderer
Open
$this->renderer->setOption('cache_dir', realpath($cache));
- Exclude checks
Call to method getOffset
from undeclared class \Phug\Util\SourceLocationInterface
Open
$this->coverage[$locationPath][$locationLine][$location->getOffset() - 1] = $covered;
- Exclude checks
Call to method getOption
from undeclared class \Phug\Renderer
Open
$cache = realpath($this->renderer->getOption('cache_dir')).DIRECTORY_SEPARATOR;
- Exclude checks
Checking instanceof against undeclared class \Phug\Parser\NodeInterface
Open
$node instanceof NodeInterface;
- Exclude checks
Argument #2 of this call to \str_pad
is typically a literal or constant but isn't, but argument #1 (which is typically a variable) is a literal or constant. The arguments may be in the wrong order. Open
str_pad('Total', $pad, ' ', STR_PAD_RIGHT).
- Exclude checks
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
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
The variable $_nodes is not named in camelCase. 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
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_coveredNodes is not named in camelCase. 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
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $__php is not named in camelCase. Open
protected function getTemplateFile(string $file, array $vars): string
{
$__php = file_get_contents(__DIR__."/../../template/$file");
extract($vars);
ob_start();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_coveredNodes is not named in camelCase. 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
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_coveredNodes is not named in camelCase. 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
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_nodes is not named in camelCase. 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
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_coveredNodes is not named in camelCase. 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
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_nodes is not named in camelCase. 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
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $__php is not named in camelCase. Open
protected function getTemplateFile(string $file, array $vars): string
{
$__php = file_get_contents(__DIR__."/../../template/$file");
extract($vars);
ob_start();
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_nodes is not named in camelCase. 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
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}