Showing 102 of 102 total issues
Avoid deeply nested control flow statements. Open
switch ($tokens[$index]) {
case '(':
$opening++;
$argumentNeedInterpolation = true;
$argument .= '(';
Method installSymfonyBundle
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
IOInterface $io,
string $dir,
string $bundle,
string $bundleClass,
callable $proceedTask,
Method proceedTask
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function proceedTask(&$flags, $io, $taskResult, $flag, $successMessage, $message)
The class PugSymfonyEngine has a coupling between objects value of 18. Consider to reduce the number of dependencies under 13. Open
class PugSymfonyEngine implements EngineInterface, InstallerInterface
{
use Installer;
use HelpersHandler;
use Filters;
- 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 installInSymfony5 uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$flags |= InstallerInterface::KERNEL_OK;
}
- 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
Avoid assigning values to variables in if clauses and the like (line '88', column '18'). Open
protected function getRendererOptions(): array
{
if ($this->options === null) {
$environment = $this->kernel->getEnvironment();
$projectDirectory = $this->kernel->getProjectDir();
- 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
Avoid assigning values to variables in if clauses and the like (line '89', column '26'). Open
protected function getRendererOptions(): array
{
if ($this->options === null) {
$environment = $this->kernel->getEnvironment();
$projectDirectory = $this->kernel->getProjectDir();
- 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
Avoid assigning values to variables in if clauses and the like (line '121', column '17'). Open
protected function getFileFromName(string $name, string $directory = null): string
{
$parts = explode(':', $name);
if (count($parts) > 1) {
- 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
The method getRendererOptions() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
protected function getRendererOptions(): array
{
if ($this->options === null) {
$environment = $this->kernel->getEnvironment();
$projectDirectory = $this->kernel->getProjectDir();
- 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 compileSource() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public function compileSource(Source $source): string
{
$path = $source->getPath();
if ($this->pugSymfonyEngine->supports($path)) {
- 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 interpolateTwigFunctions() has a Cyclomatic Complexity of 18. The configured cyclomatic complexity threshold is 10. Open
protected function interpolateTwigFunctions(string $code): string
{
$tokens = array_slice(token_get_all('<?php '.$code), 1);
$output = '';
$count = count($tokens);
- 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
Line exceeds 120 characters; contains 125 characters Open
'autoescape' => static::getPrivateExtensionProperty($baseTwig, EscaperExtension::class, 'defaultStrategy'),
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
'optimizations' => static::getPrivateExtensionProperty($baseTwig, OptimizerExtension::class, 'optimizers'),
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
[$directories, $success, $errors, $errorDetails] = $this->cacheTemplates($this->pugSymfonyEngine->getRenderer());
- Exclude checks
Line exceeds 120 characters; contains 142 characters Open
$addBundle = static::askConfirmation($io, 'Would you like us to add automatically the pug bundle in your config/bundles.php? [Y/N] ');
- Exclude checks
Line exceeds 120 characters; contains 127 characters Open
$output->writeln($count.' '.($count === 1 ? 'directory' : 'directories').' scanned: '.implode(', ', $directories).'.');
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
$this->userOptions = ($this->container->hasParameter('pug') ? $this->container->getParameter('pug') : null) ?: [];
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
private readonly ?RequestStack $stack = null,
- Exclude checks
Space before opening parenthesis of function call prohibited Open
static fn ($path) => $path !== $baseDir,
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
protected readonly KernelInterface $kernel,
- Exclude checks