Showing 60 of 60 total issues
The class ConfigProvider has a coupling between objects value of 16. Consider to reduce the number of dependencies under 13. Open
class ConfigProvider
{
public function __invoke(): array
{
return [
- 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
Avoid too many return
statements within this method. Open
return sprintf(
$this->view->translatePlural('%1$s minutes ago', null, $minutes),
$minutes
);
Avoid too many return
statements within this method. Open
return $this->view->translate('an hour ago');
Avoid too many return
statements within this method. Open
return $this->view->translate('in few seconds');
Avoid too many return
statements within this method. Open
return $this->view->humanDate($time);
The method __invoke has a boolean flag argument $escape, which is a certain sign of a Single Responsibility Principle violation. Open
public function __invoke($attribs = [], $content = '', $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 too many return
statements within this method. Open
return $this->view->translate('few seconds ago');
Avoid too many return
statements within this method. Open
return $this->view->translate('a minute ago');
Avoid too many return
statements within this method. Open
return $this->view->translate('now');
Avoid too many return
statements within this method. Open
return sprintf(
$this->view->translatePlural('%1$s hours ago', null, $hours),
$hours
);
Avoid using static access to class '\Laminas\Json\Json' in method 'loadManifest'. Open
$content = Json::decode($json, Json::TYPE_ARRAY);
- 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 '\Transliterator' in method 'filter'. Open
$tr = Transliterator::create('Any-Latin;Latin-ASCII;');
- 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
The method getRevUrl uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return $prefix . $file;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method __invoke() has an NPath complexity of 236196. The configured NPath complexity threshold is 200. Open
public function __invoke($time)
{
if (! $time instanceof DateTime) {
$dateTime = new DateTime();
$dateTime->setTimestamp($time);
- 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 __invoke() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): TransportInterface
{
$config = $container->has('config') ? $container->get('config') : [];
$mailConfig = $config['mail'] ?? [];
- 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
The method __invoke() has a Cyclomatic Complexity of 23. The configured cyclomatic complexity threshold is 10. Open
public function __invoke($time)
{
if (! $time instanceof DateTime) {
$dateTime = new DateTime();
$dateTime->setTimestamp($time);
- 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
Expected 1 newline at end of file; 0 found Open
];
- Exclude checks
syntax error, unexpected 'array' (T_ARRAY), expecting function (T_FUNCTION) or const (T_CONST)
Open
private array $manifests = [];
- Exclude checks
Parameter $requestedName
is never used Open
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): TableManager
- Exclude checks
Parameter $options
is never used Open
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): Helper
- Exclude checks