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 ?: []);
Function loader
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function loader($file)
{
foreach ($this->folders as $folder)
{
foreach (FileLoader::extensions() as $ext)
- 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 using static access to class 'Bavix\Flow\Cache' in method 'tryLoad'. Open
$item = Cache::getItem(__CLASS__ . $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\Flow\Cache' in method 'lexerApply'. Open
return Cache::get($name, function () use ($store) {
return $store;
});
- 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 'apply'. Open
$data = Arr::map($data, [$this, 'lexerApply']);
- 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\SDK\FileLoader' in method 'loader'. Open
foreach (FileLoader::extensions() as $ext)
- 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 'property'. Open
$extends = Arr::map((array)$prop['extends'], function ($extend) use ($self, &$props) {
return $self->property($props, $extend);
});
- 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 'addFolder'. Open
Arr::unShift($this->folders, $path);
- 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\Property' in method '__construct'. Open
$this->types = Property::get('types');
- 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 'lexerApply'. Open
$item = Cache::getItem($name);
- 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\SDK\FileLoader' in method 'loader'. Open
return FileLoader::load($folder . '/' . $file . '.' . $ext);
- 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 'apply'. Open
$data = Arr::filter($outs, function (...$args) {
return \is_string(\end($args));
});
- 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 'syntax2Array'. Open
return Cache::get(__CLASS__ . $key, function () use ($syntax, $props, $closed) {
return [
'syntax' => $syntax,
'props' => $props,
'closed' => $closed,
- 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
Define a constant instead of duplicating this literal "syntax" 3 times. Open
'syntax' => $syntax,
- 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.
Rename "$closed" which has the same name as the field declared at line 44. Open
$closed = $this->closed[$key] ?? false;
- Read upRead up
- Exclude checks
Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.
Noncompliant Code Example
class Foo { public $myField; public function doSomething() { $myField = 0; ... } }
See
- CERT, DCL51-J. - Do not shadow or obscure identifiers in subscopes
Rename "$data" which has the same name as the field declared at line 39. Open
$data = null;
- Read upRead up
- Exclude checks
Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.
Noncompliant Code Example
class Foo { public $myField; public function doSomething() { $myField = 0; ... } }
See
- CERT, DCL51-J. - Do not shadow or obscure identifiers in subscopes
Rename "$props" which has the same name as the field declared at line 34. Open
$props = $this->props[$key] ?? null;
- Read upRead up
- Exclude checks
Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.
Noncompliant Code Example
class Foo { public $myField; public function doSomething() { $myField = 0; ... } }
See
- CERT, DCL51-J. - Do not shadow or obscure identifiers in subscopes
Define a constant instead of duplicating this literal "types" 3 times. Open
'types' => [
- 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.
Define a constant instead of duplicating this literal "closed" 3 times. Open
'closed' => $closed,
- 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.
Avoid unused local variables such as '$prop'. Open
foreach ($props as $key => $prop)
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
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
foreach ($data['directives'] ?? [] as $_key => $directive)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
foreach ($data['syntax'] ?? [] as $text)
- Exclude checks
Expected 1 space after closing parenthesis; found 13 Open
foreach (FileLoader::extensions() as $ext)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (null === $loader)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (!\array_key_exists($key, $this->data))
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if ($loader)
- Exclude checks
Expected 1 space after TRY keyword; newline found Open
try
- Exclude checks
Expected 1 space after closing parenthesis; found 13 Open
if ($item && $item->isHit())
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
foreach ($types as $type)
- Exclude checks
Expected 1 space after closing parenthesis; found 17 Open
catch (\Throwable $throwable)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
foreach ($lexData as $datum)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
foreach ($this->folders as $folder)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (empty($this->data[$key]))
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (!$this->lexer)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (empty($this->data[$key]))
- Exclude checks
Expected 1 space after closing parenthesis; found 13 Open
foreach ($vars as $var)
- Exclude checks
Expected 1 space after closing parenthesis; found 13 Open
if (\is_object($mixed))
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (true === $lexData)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
foreach ($props as $key => $prop)
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (empty($this->props[$key]))
- Exclude checks
Expected 1 space after closing brace; newline found Open
}
- Exclude checks
Expected 1 space after closing parenthesis; found 13 Open
if (isset($prop['extends']))
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if ($item && $item->isHit())
- Exclude checks
Expected 1 space after closing parenthesis; found 13 Open
if (\preg_match($datum['regexp'], $tpl, $outs))
- Exclude checks
The variable $_lexer is not named in camelCase. Open
public function lexerApply(string $value): array
{
$name = __FUNCTION__ . $value;
$item = Cache::getItem($name);
- 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 $_key is not named in camelCase. Open
protected function syntax(string $key, array $data)
{
foreach ($data['directives'] ?? [] as $_key => $directive)
{
$this->data($_key, $directive ?: []);
- 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 $_key is not named in camelCase. Open
protected function syntax(string $key, array $data)
{
foreach ($data['directives'] ?? [] as $_key => $directive)
{
$this->data($_key, $directive ?: []);
- 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 $_lexer is not named in camelCase. Open
public function lexerApply(string $value): array
{
$name = __FUNCTION__ . $value;
$item = Cache::getItem($name);
- 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 $_cache is not named in camelCase. Open
protected function tryLoad(string $key)
{
if (empty($this->data[$key]))
{
$item = Cache::getItem(__CLASS__ . $key);
- 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 $_cache is not named in camelCase. Open
protected function tryLoad(string $key)
{
if (empty($this->data[$key]))
{
$item = Cache::getItem(__CLASS__ . $key);
- 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 $_cache is not named in camelCase. Open
protected function tryLoad(string $key)
{
if (empty($this->data[$key]))
{
$item = Cache::getItem(__CLASS__ . $key);
- 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 $_cache is not named in camelCase. Open
protected function tryLoad(string $key)
{
if (empty($this->data[$key]))
{
$item = Cache::getItem(__CLASS__ . $key);
- 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 $_lexer is not named in camelCase. Open
public function lexerApply(string $value): array
{
$name = __FUNCTION__ . $value;
$item = Cache::getItem($name);
- 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();
}
}