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);
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)
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"
Further reading
The method buildWithoutCache() has an NPath complexity of 58801. The configured NPath complexity threshold is 200. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 buildWithoutCache() has 105 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- Exclude checks
The method buildWithoutCache() has a Cyclomatic Complexity of 28. The configured cyclomatic complexity threshold is 10. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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
Refactor this function to reduce its Cognitive Complexity from 43 to the 15 allowed. Open
public function buildWithoutCache(array $data): string
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Class "Flow" has 25 methods, which is greater than 20 authorized. Split it into smaller classes. Open
class Flow
- Read upRead up
- Exclude checks
A class that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and therefore to maintain. Above a specific threshold, it is strongly advised to refactor the class into smaller ones which focus on well defined topics.
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
The method printers has a boolean flag argument $escape, which is a certain sign of a Single Responsibility Principle violation. Open
protected function printers(array $rows, $escape = true)
- 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 using static access to class 'Bavix\Flow\Property' in method '__construct'. Open
$this->constructs = Property::get('constructs');
- 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 '\Bavix\Helpers\Arr' in method 'fragment'. Open
$data = Arr::map($tokens['tokens'] ?? $tokens, function (Token $token) {
return $token->token;
});
- 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 'Bavix\Flow\Cache' in method '__construct'. Open
Cache::setPool($options['cache'] ?? null);
- 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 '\Bavix\Helpers\Arr' in method 'buildWithoutCache'. Open
Arr::pop($code);
- 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 '\Bavix\Helpers\Arr' in method 'buildWithoutCache'. Open
(!$last || !Arr::in([
Validator::T_ENDBRACKET,
Validator::T_ENDARRAY,
Validator::T_DOT,
T_NS_SEPARATOR,
- 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 '\Bavix\Helpers\Arr' in method 'compile'. Open
\get_class(Arr::pop($items))
- 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 '\Bavix\Helpers\Arr' in method 'buildWithoutCache'. Open
Arr::push($code, $pop);
- 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 '\Bavix\Helpers\Str' in method 'buildWithoutCache'. Open
if (Str::ucFirst($_token->token) === $_token->token)
- 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 '\Bavix\Helpers\Str' in method 'ifEnd'. Open
if (0 === Str::pos($key, 'end'))
- 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 '\Minify_HTML' in method 'minify'. Open
$html = \Minify_HTML::minify(\trim($html), [
'cssMinifier' => [\Minify_CSSmin::class, 'minify'],
'jsMinifier' => [JSMin::class, 'minify'],
]);
- 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 '\Bavix\Helpers\Arr' in method 'popDirective'. Open
return Arr::pop($this->directives[$key]);
- 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 '\Bavix\Helpers\Arr' in method 'buildWithoutCache'. Open
if (Arr::in([T_NEW, T_CLONE, T_INSTEADOF, T_INSTANCEOF, T_AS], $_token->type))
- 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 '\Bavix\Helpers\Arr' in method 'buildWithoutCache'. Open
Arr::pop($code);
- 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 '\Bavix\Helpers\Arr' in method 'buildWithoutCache'. Open
Arr::push($code, '->');
- 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 '\Bavix\Helpers\Str' in method 'buildWithoutCache'. Open
if (Str::ucFirst($_token->token) !== $_token->token &&
- 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 'Bavix\Flow\Cache' in method 'build'. Open
return Cache::get($_storeKey, function () use ($self, &$data) {
return $self->buildWithoutCache($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 using static access to class '\Bavix\Helpers\Arr' in method 'buildWithoutCache'. Open
$pop = Arr::pop($code);
- 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 '\Bavix\Helpers\Arr' in method 'buildWithoutCache'. Open
Arr::push($code, '\\' . WithDirective::class . '::last()');
- 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 '\Bavix\Helpers\Arr' in method 'buildWithoutCache'. Open
($last && !Arr::in([\T_DOUBLE_COLON, Validator::T_DOT], $last->type))) &&
- 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 '\Bavix\Helpers\JSON' in method 'build'. Open
$_storeKey = __CLASS__ . JSON::encode($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 using static access to class '\Bavix\Helpers\Arr' in method 'buildWithoutCache'. Open
!Arr::in($this->constructs, $_token->token))
- 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 '\Bavix\Helpers\Arr' in method 'buildWithoutCache'. Open
if (!Arr::in([T_FUNCTION, T_CLASS], $_token->type) &&
- 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 '\Bavix\Helpers\Arr' in method 'buildWithoutCache'. Open
if (!Arr::in([T_NEW, T_CLASS], $_token->type))
- 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 '\Bavix\Helpers\Arr' in method 'buildWithoutCache'. Open
if (Arr::in([Validator::T_BRACKET, T_ARRAY], $_token->type))
- 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 '\Bavix\Helpers\Str' in method 'directive'. Open
$class = __NAMESPACE__ . '\\Directives\\' . Str::ucFirst($key) . 'Directive';
- 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 '\Bavix\Helpers\Arr' in method 'buildWithoutCache'. Open
if (Arr::in([T_VARIABLE, T_FUNCTION], $_token->type))
- 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 '\Bavix\Helpers\Str' in method 'ifEnd'. Open
$key = Str::sub($key, 3);
- 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
Merge this if statement with the enclosing one. Open
if ($last && $last->type === Validator::T_DOT)
- Read upRead up
- Exclude checks
Merging collapsible if
statements increases the code's readability.
Noncompliant Code Example
if (condition1) { if (condition2) { ... } }
Compliant Solution
if (condition1 && condition2) { ... }
Define a constant instead of duplicating this literal "minify" 3 times. Open
$this->minify = $options['minify'] ?? false;
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Merge this if statement with the enclosing one. Open
if (!empty($items))
- Read upRead up
- Exclude checks
Merging collapsible if
statements increases the code's readability.
Noncompliant Code Example
if (condition1) { if (condition2) { ... } }
Compliant Solution
if (condition1 && condition2) { ... }
Merge this if statement with the enclosing one. Open
if (Str::ucFirst($_token->token) !== $_token->token &&
- Read upRead up
- Exclude checks
Merging collapsible if
statements increases the code's readability.
Noncompliant Code Example
if (condition1) { if (condition2) { ... } }
Compliant Solution
if (condition1 && condition2) { ... }
Define a constant instead of duplicating this literal "tokens" 3 times. Open
$data = Arr::map($tokens['tokens'] ?? $tokens, function (Token $token) {
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
The closing brace for the class must go on the next line after the body Open
}
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (!$this->lexer)
- Exclude checks
Expected 1 space after closing parenthesis; found 13 Open
foreach ($this->folders as $folder => $path)
- Exclude checks
Expected 1 space after closing parenthesis; found 17 Open
if ($last && $last->type === Validator::T_DOT)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (!empty($this->extends))
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (!$this->fileSystem()->has($view))
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
foreach ($this->directives as $name => $items)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
foreach ($rows as $row)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (!$this->lexeme)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (!$this->native)
- Exclude checks
Expected 1 space after closing parenthesis; found 13 Open
if ($this->lexeme()->closed($name))
- Exclude checks
Expected 1 space after closing parenthesis; found 17 Open
if (!empty($items))
- Exclude checks
Expected 1 space after closing parenthesis; found 13 Open
if (Arr::in([Validator::T_BRACKET, T_ARRAY], $_token->type))
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
foreach ($this->lexemes as $folder)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if ($native)
- Exclude checks
Expected 1 space after closing parenthesis; found 13 Open
$_token->type === T_FUNCTION)
- Exclude checks
Expected 1 space after closing parenthesis; found 17 Open
if (Str::ucFirst($_token->token) === $_token->token)
- Exclude checks
Expected 1 space after closing parenthesis; found 13 Open
if ($_token->type === T_OBJECT_OPERATOR)
- Exclude checks
Expected 1 space after closing parenthesis; found 17 Open
!Arr::in($this->constructs, $_token->token))
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
foreach ($data['tokens'] as $token)
- Exclude checks
Expected 1 space after closing parenthesis; found 17 Open
if ($last && $last->type === Validator::T_DOT)
- Exclude checks
Expected 1 space after closing parenthesis; found 13 Open
if (true !== $data && $this->lexeme()->closed($key))
- Exclude checks
Expected 1 space after closing parenthesis; found 13 Open
if (Arr::in([T_NEW, T_CLONE, T_INSTEADOF, T_INSTANCEOF, T_AS], $_token->type))
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (!$tpl)
- Exclude checks
Expected 1 space after closing parenthesis; found 17 Open
], $last->type)))
- Exclude checks
Expected 1 space after closing parenthesis; found 13 Open
if ($end && true !== $data)
- Exclude checks
Expected 1 space after closing parenthesis; found 13 Open
if ($_token->type === Validator::T_CONCAT)
- Exclude checks
Expected 1 space after closing parenthesis; found 13 Open
&& $last->type === Validator::T_DOT)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (!$this->fileSystem)
- Exclude checks
Expected 1 space after closing parenthesis; found 17 Open
if (!Arr::in([T_NEW, T_CLASS], $_token->type))
- Exclude checks
Expected 1 space after closing parenthesis; found 13 Open
if (Arr::in([T_VARIABLE, T_FUNCTION], $_token->type))
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
foreach ($this->operators as $operator)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (isset($this->mapDirectives[$key]))
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (0 === Str::pos($key, 'end'))
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
foreach ($this->literals as $key => $literal)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if ($this->minify)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (empty($this->directives[$key]))
- Exclude checks
The variable $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_storeKey is not named in camelCase. Open
public function build(array $data): string
{
$self = $this;
$_storeKey = __CLASS__ . JSON::encode($data);
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
protected function operators()
{
foreach ($this->operators as $operator)
{
/**
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_storeKey is not named in camelCase. Open
public function build(array $data): string
{
$self = $this;
$_storeKey = __CLASS__ . JSON::encode($data);
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
protected function operators()
{
foreach ($this->operators as $operator)
{
/**
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
protected function operators()
{
foreach ($this->operators as $operator)
{
/**
- 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 $_token is not named in camelCase. Open
protected function operators()
{
foreach ($this->operators as $operator)
{
/**
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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 $_token is not named in camelCase. Open
protected function operators()
{
foreach ($this->operators as $operator)
{
/**
- 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 $_token is not named in camelCase. Open
protected function operators()
{
foreach ($this->operators as $operator)
{
/**
- 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 $_token is not named in camelCase. Open
public function buildWithoutCache(array $data): string
{
$code = [];
$lastLast = null;
$last = null;
- 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();
}
}