Showing 264 of 264 total issues
Function buildWithoutCache
has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = 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
File Flow.php
has 378 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace Bavix\Flow;
use Bavix\Exceptions\Invalid;
The class Flow has 12 public methods. Consider refactoring Flow to keep number of public methods under 10. Open
class Flow
{
const VERSION = '1.0.6';
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public 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'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
The class Flow has an overall complexity of 79 which is very high. The configured complexity threshold is 50. Open
class Flow
{
const VERSION = '1.0.6';
- Exclude checks
Method buildWithoutCache
has 82 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
Flow
has 25 functions (exceeds 20 allowed). Consider refactoring. Open
class Flow
{
const VERSION = '1.0.6';
The class Flow has 19 fields. Consider redesigning Flow to keep the number of fields under 15. Open
class Flow
{
const VERSION = '1.0.6';
- Read upRead up
- Exclude checks
TooManyFields
Since: 0.1
Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.
Example
class Person {
protected $one;
private $two;
private $three;
[... many more fields ...]
}
Source https://phpmd.org/rules/codesize.html#toomanyfields
Method compile
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function compile(string $view): string
{
$path = $this->native()->path($view . $this->ext());
$this->tpl = \file_get_contents($path);
$tokens = $this->lexer()->tokens($this->tpl);
Method syntax
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function syntax(string $key, array $data)
{
foreach ($data['directives'] ?? [] as $_key => $directive)
{
$this->data($_key, $directive ?: []);
Method testExtends
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function testExtends()
{
$codeWithoutComments = <<<code
<h1>{{ message }}</h1>
Method testRaw
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function testRaw()
{
$code = <<<code
{{ message }}
Method testComments
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function testComments()
{
$code = <<<code
<!-- print message -->
Avoid variables with short names like $a. Configured minimum length is 3. Open
$a = 'hello';
- 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 class Flow has a coupling between objects value of 22. Consider to reduce the number of dependencies under 13. Open
class Flow
{
const VERSION = '1.0.6';
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
Consider simplifying this complex logical expression. Open
if ($last && (!$lastLast ||
($lastLast->type !== T_VARIABLE &&
$lastLast->type !== Validator::T_ENDBRACKET &&
$lastLast->type !== Validator::T_ENDARRAY))
&& $last->type === Validator::T_DOT)
The closing brace for the class must go on the next line after the body Open
}
- Exclude checks
The closing brace for the class must go on the next line after the body Open
}
- Exclude checks
Function closing brace must go on the next line following the body; found 1 blank lines before brace Open
}
- Exclude checks
The closing brace for the class must go on the next line after the body Open
}
- Exclude checks
Function compile
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function compile(string $view): string
{
$path = $this->native()->path($view . $this->ext());
$this->tpl = \file_get_contents($path);
$tokens = $this->lexer()->tokens($this->tpl);
- 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"