Function interpolateTwigFunctions
has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring. Open
protected function interpolateTwigFunctions(string $code): string
{
$tokens = array_slice(token_get_all('<?php '.$code), 1);
$output = '';
$count = count($tokens);
- 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 HelpersHandler.php
has 272 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace Pug\Symfony\Traits;
use Closure;
Method interpolateTwigFunctions
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function interpolateTwigFunctions(string $code): string
{
$tokens = array_slice(token_get_all('<?php '.$code), 1);
$output = '';
$count = count($tokens);
Method getRendererOptions
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function getRendererOptions(): array
{
if ($this->options === null) {
$environment = $this->kernel->getEnvironment();
$projectDirectory = $this->kernel->getProjectDir();
Method copyTwigFunctions
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function copyTwigFunctions(): void
{
$this->twigHelpers = [];
$twig = $this->getTwig();
$twig->env = $twig;
Function getRendererOptions
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
protected function getRendererOptions(): array
{
if ($this->options === null) {
$environment = $this->kernel->getEnvironment();
$projectDirectory = $this->kernel->getProjectDir();
- 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 deeply nested control flow statements. Open
switch ($tokens[$index]) {
case '(':
$opening++;
$argumentNeedInterpolation = true;
$argument .= '(';
Function copyTwigFunctions
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function copyTwigFunctions(): void
{
$this->twigHelpers = [];
$twig = $this->getTwig();
$twig->env = $twig;
- 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 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
The method getRendererOptions() has a Cyclomatic Complexity of 12. 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
Refactor this function to reduce its Cognitive Complexity from 39 to the 15 allowed. Open
protected function interpolateTwigFunctions(string $code): 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
Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed. Open
protected function getRendererOptions(): array
- 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
Avoid using undefined variables such as '$propertyAccessor' which will lead to PHP notices. Open
$propertyAccessor->setValue($this->container, $services);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$propertyAccessor' which will lead to PHP notices. Open
$services = static::getPrivateProperty($this->container, 'services', $propertyAccessor);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid assigning values to variables in if clauses and the like (line '103', 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 '104', 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
Define a constant instead of duplicating this literal "paths" 5 times. Open
$this->setOption('paths', array_unique($this->getOptionDefault('paths', [])));
- 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.
Refactor the code to avoid updating the loop counter "$index" within the loop body. Open
for ($opening = 1; $opening !== 0; $index++) {
- Read upRead up
- Exclude checks
A for
loop stop condition should test the loop counter against an invariant value (i.e. one that is true at both the beginning and
ending of every loop iteration). Ideally, this means that the stop condition is set to a local variable just before the loop begins.
Stop conditions that are not invariant are slightly less efficient, as well as being difficult to understand and maintain, and likely lead to the introduction of errors in the future.
This rule tracks three types of non-invariant stop conditions:
- When the loop counters are updated in the body of the
for
loop - When the stop condition depend upon a method call
- When the stop condition depends on an object property, since such properties could change during the execution of the loop.
Noncompliant Code Example
for ($i = 0; $i < 10; $i++) { echo $i; if(condition) { $i = 20; } }
Compliant Solution
for ($i = 0; $i < 10; $i++) { echo $i; }
See
- MISRA C:2004, 13.6 - Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loop.
- MISRA C++:2008, 6-5-3 - The loop-counter shall not be modified within condition or statement.
Define a constant instead of duplicating this literal "baseDir" 3 times. Open
$baseDir = isset($this->userOptions['baseDir'])
- 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 and throw a dedicated exception instead of using a generic one. Open
throw new RuntimeException('Twig needs to be configured.');
- Read upRead up
- Exclude checks
If you throw a general exception type, such as ErrorException, RuntimeException, or Exception in a library or framework, it forces consumers to catch all exceptions, including unknown exceptions that they do not know how to handle.
Instead, either throw a subtype that already exists in the Standard PHP Library, or create your own type that derives from Exception.
Noncompliant Code Example
throw new Exception(); // Noncompliant
Compliant Solution
throw new InvalidArgumentException(); // or throw new UnexpectedValueException();
See
- MITRE, CWE-397 - Declaration of Throws for Generic Exception
- CERT, ERR07-J. - Do not throw RuntimeException, Exception, or Throwable
Rename "$pug" which has the same name as the field declared at line 55. Open
$pug = new Pug($options);
- 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
Refactor the code to avoid updating the loop counter "$index" within the loop body. Open
$index += 3;
- Read upRead up
- Exclude checks
A for
loop stop condition should test the loop counter against an invariant value (i.e. one that is true at both the beginning and
ending of every loop iteration). Ideally, this means that the stop condition is set to a local variable just before the loop begins.
Stop conditions that are not invariant are slightly less efficient, as well as being difficult to understand and maintain, and likely lead to the introduction of errors in the future.
This rule tracks three types of non-invariant stop conditions:
- When the loop counters are updated in the body of the
for
loop - When the stop condition depend upon a method call
- When the stop condition depends on an object property, since such properties could change during the execution of the loop.
Noncompliant Code Example
for ($i = 0; $i < 10; $i++) { echo $i; if(condition) { $i = 20; } }
Compliant Solution
for ($i = 0; $i < 10; $i++) { echo $i; }
See
- MISRA C:2004, 13.6 - Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loop.
- MISRA C++:2008, 6-5-3 - The loop-counter shall not be modified within condition or statement.
Rename "$pug" which has the same name as the field declared at line 55. Open
$pug = $this->getRenderer();
- 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
Refactor the code to avoid updating the loop counter "$opening" within the loop body. Open
if ((--$opening) !== 0) {
- Read upRead up
- Exclude checks
A for
loop stop condition should test the loop counter against an invariant value (i.e. one that is true at both the beginning and
ending of every loop iteration). Ideally, this means that the stop condition is set to a local variable just before the loop begins.
Stop conditions that are not invariant are slightly less efficient, as well as being difficult to understand and maintain, and likely lead to the introduction of errors in the future.
This rule tracks three types of non-invariant stop conditions:
- When the loop counters are updated in the body of the
for
loop - When the stop condition depend upon a method call
- When the stop condition depends on an object property, since such properties could change during the execution of the loop.
Noncompliant Code Example
for ($i = 0; $i < 10; $i++) { echo $i; if(condition) { $i = 20; } }
Compliant Solution
for ($i = 0; $i < 10; $i++) { echo $i; }
See
- MISRA C:2004, 13.6 - Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loop.
- MISRA C++:2008, 6-5-3 - The loop-counter shall not be modified within condition or statement.
Refactor the code to avoid updating the loop counter "$index" within the loop body. Open
$index += 2;
- Read upRead up
- Exclude checks
A for
loop stop condition should test the loop counter against an invariant value (i.e. one that is true at both the beginning and
ending of every loop iteration). Ideally, this means that the stop condition is set to a local variable just before the loop begins.
Stop conditions that are not invariant are slightly less efficient, as well as being difficult to understand and maintain, and likely lead to the introduction of errors in the future.
This rule tracks three types of non-invariant stop conditions:
- When the loop counters are updated in the body of the
for
loop - When the stop condition depend upon a method call
- When the stop condition depends on an object property, since such properties could change during the execution of the loop.
Noncompliant Code Example
for ($i = 0; $i < 10; $i++) { echo $i; if(condition) { $i = 20; } }
Compliant Solution
for ($i = 0; $i < 10; $i++) { echo $i; }
See
- MISRA C:2004, 13.6 - Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loop.
- MISRA C++:2008, 6-5-3 - The loop-counter shall not be modified within condition or statement.
Rename "$twig" which has the same name as the field declared at line 45. Open
$twig = $this->getTwig();
- 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 "patterns" 3 times. Open
$transformation = $pug->hasOption('patterns')
- 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.
Refactor the code to avoid updating the loop counter "$opening" within the loop body. Open
$opening++;
- Read upRead up
- Exclude checks
A for
loop stop condition should test the loop counter against an invariant value (i.e. one that is true at both the beginning and
ending of every loop iteration). Ideally, this means that the stop condition is set to a local variable just before the loop begins.
Stop conditions that are not invariant are slightly less efficient, as well as being difficult to understand and maintain, and likely lead to the introduction of errors in the future.
This rule tracks three types of non-invariant stop conditions:
- When the loop counters are updated in the body of the
for
loop - When the stop condition depend upon a method call
- When the stop condition depends on an object property, since such properties could change during the execution of the loop.
Noncompliant Code Example
for ($i = 0; $i < 10; $i++) { echo $i; if(condition) { $i = 20; } }
Compliant Solution
for ($i = 0; $i < 10; $i++) { echo $i; }
See
- MISRA C:2004, 13.6 - Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loop.
- MISRA C++:2008, 6-5-3 - The loop-counter shall not be modified within condition or statement.
Call to method get
from undeclared class \Symfony\Component\DependencyInjection\ContainerInterface
Open
$this->twig = $this->container->has('twig') ? $this->container->get('twig') : null;
- Exclude checks
Call to method getCompiler
from undeclared class \Pug\Pug
Open
$pug->getCompiler()->setOption('mixin_keyword', $pug->getOption('mixin_keyword'));
- Exclude checks
Call to method mkdir
from undeclared class \Symfony\Component\Filesystem\Filesystem
Open
(new Filesystem())->mkdir($cache);
- Exclude checks
Call to undeclared method \Pug\Twig\Environment::setLoader
Open
$twig->setLoader($loader);
- Exclude checks
Property \Pug\Symfony\Traits\HelpersHandler->kernel
has undeclared type \Symfony\Component\HttpKernel\Kernel
Open
protected $kernel;
- Exclude checks
Return type of getHttpFoundationExtension()
is undeclared type \Symfony\Bridge\Twig\Extension\HttpFoundationExtension
Open
protected function getHttpFoundationExtension(): HttpFoundationExtension
- Exclude checks
Call to method __construct
from undeclared class \Symfony\Bridge\Twig\Extension\HttpFoundationExtension
Open
return new HttpFoundationExtension(new UrlHelper($stack, $context));
- Exclude checks
Call to method get
from undeclared class \Symfony\Component\DependencyInjection\ContainerInterface
Open
$stack = $this->container->get('request_stack');
- Exclude checks
Argument 2 (pugSymfonyEngine)
is \Pug\Symfony\Traits\HelpersHandler|\Pug\Symfony\Traits\PrivatePropertyAccessor
but \Pug\Twig\Environment::fromTwigEnvironment()
takes \Pug\PugSymfonyEngine
defined at src/Pug/Twig/Environment.php:82
Open
$this->twig = Environment::fromTwigEnvironment($this->twig, $this, $this->container);
- Exclude checks
Call to method enable
from undeclared class \Phug\Component\ComponentExtension
Open
ComponentExtension::enable($pug);
- Exclude checks
Checking instanceof against undeclared class \Twig\Loader\FilesystemLoader
Open
if (($loader = $this->getTwig()->getLoader()) instanceof FilesystemLoader &&
- Exclude checks
Call to undeclared method \Pug\Twig\Environment::addExtension
Open
$twig->addExtension($assetExtension);
- Exclude checks
Call to method getName
from undeclared class \Twig\TwigFunction
Open
$name = $function->getName();
- Exclude checks
Call to undeclared method \Pug\Symfony\Traits\HelpersHandler::crawlDirectories
Open
: $this->crawlDirectories($srcDir, $assetsDirectories, $viewDirectories);
- Exclude checks
Static call to undeclared method \Pug\Symfony\Traits\HelpersHandler::extractUniquePaths
Open
'assetDirectory' => static::extractUniquePaths($assetsDirectories),
- Exclude checks
Call to method isDebug
from undeclared class \Symfony\Component\HttpKernel\Kernel
Open
$debug = $this->kernel->isDebug();
- Exclude checks
Call to method setOptionsRecursive
from undeclared class \Pug\Pug
Open
$pug->setOptionsRecursive([
- Exclude checks
Call to undeclared method \Pug\Symfony\Traits\HelpersHandler::getOptionDefault
Open
$this->setOption('paths', array_unique($this->getOptionDefault('paths', [])));
- Exclude checks
Call to method getEnvironment
from undeclared class \Symfony\Component\HttpKernel\Kernel
Open
$environment = $this->kernel->getEnvironment();
- Exclude checks
Call to method __construct
from undeclared class \Symfony\Component\Asset\Packages
Open
$assetExtension = new AssetExtension(new Packages(new Package(new EmptyVersionStrategy())));
- Exclude checks
Call to undeclared method \Pug\Symfony\Traits\HelpersHandler::share
Open
$this->share($this->getTwig()->getGlobals());
- Exclude checks
Property \Pug\Symfony\Traits\HelpersHandler->pug
has undeclared type \Pug\Pug
Open
protected $pug;
- Exclude checks
Possibly zero references to use statement for classlike/namespace RequestContext
(\Symfony\Component\Routing\RequestContext)
Open
use Symfony\Component\Routing\RequestContext;
- Exclude checks
Reference to undeclared property \Pug\Symfony\Traits\HelpersHandler->componentExtension
Open
$this->componentExtension = $pug->getModule(ComponentExtension::class);
- Exclude checks
Return type of createEngine()
is undeclared type \Pug\Pug
Open
protected function createEngine(array $options): Pug
- Exclude checks
Call to method __construct
from undeclared class \Symfony\Component\Filesystem\Filesystem
Open
(new Filesystem())->mkdir($cache);
- Exclude checks
Property \Pug\Symfony\Traits\HelpersHandler->kernel
has undeclared type \Symfony\Component\HttpKernel\KernelInterface
Open
protected $kernel;
- Exclude checks
Reference to undeclared property \Pug\Symfony\Traits\HelpersHandler->assets
Open
$this->assets = new Assets($pug);
- Exclude checks
Call to method getModule
from undeclared class \Pug\Pug
Open
$this->componentExtension = $pug->getModule(ComponentExtension::class);
- Exclude checks
Call to method __construct
from undeclared class \Symfony\Bridge\Twig\Extension\AssetExtension
Open
$assetExtension = new AssetExtension(new Packages(new Package(new EmptyVersionStrategy())));
- Exclude checks
Call to method getProjectDir
from undeclared class \Symfony\Component\HttpKernel\Kernel
Open
$projectDirectory = $this->kernel->getProjectDir();
- Exclude checks
Call to undeclared method \Pug\Twig\Environment::getLoader
Open
if (($loader = $this->getTwig()->getLoader()) instanceof FilesystemLoader &&
- Exclude checks
Call to undeclared method \Pug\Symfony\Traits\HelpersHandler::share
Open
$this->share('twig', $twig);
- Exclude checks
Reference to undeclared property \Pug\Symfony\Traits\HelpersHandler->defaultTemplateDirectory
Open
$this->defaultTemplateDirectory = $baseDir;
- Exclude checks
Return type of getRenderer()
is undeclared type \Pug\Pug
Open
public function getRenderer(): Pug
- Exclude checks
Call to undeclared method \Pug\Twig\Environment::getGlobals
Open
$this->share($this->getTwig()->getGlobals());
- Exclude checks
Possibly zero references to use statement for classlike/namespace RequestStack
(\Symfony\Component\HttpFoundation\RequestStack)
Open
use Symfony\Component\HttpFoundation\RequestStack;
- Exclude checks
Call to method __construct
from undeclared class \Symfony\Component\HttpFoundation\UrlHelper
Open
return new HttpFoundationExtension(new UrlHelper($stack, $context));
- Exclude checks
Call to undeclared method \Pug\Symfony\Traits\HelpersHandler::getCacheDir
Open
'cache' => $debug ? false : $this->getCacheDir(),
- Exclude checks
Call to method __construct
from undeclared class \Pug\Assets
Open
$this->assets = new Assets($pug);
- Exclude checks
Call to method getFunctions
from undeclared class \Symfony\Bridge\Twig\Extension\AssetExtension
Open
foreach ($extension->getFunctions() as $function) {
- Exclude checks
Call to undeclared method \Pug\Twig\Environment::addExtension
Open
$twig->addExtension($helper);
- Exclude checks
Checking instanceof against undeclared class \Twig\Environment
(Did you mean class \Pug\Twig\Environment) Open
if (!($this->twig instanceof TwigEnvironment)) {
- Exclude checks
Property \Pug\Symfony\Traits\HelpersHandler->container
has undeclared type \Symfony\Component\DependencyInjection\ContainerInterface
Open
protected $container;
- Exclude checks
Reference to undeclared property \Pug\Twig\Environment->env
(Did you mean $_ENV) Open
$twig->env = $twig;
- Exclude checks
Call to method __construct
from undeclared class \Symfony\Component\Asset\Package
Open
$assetExtension = new AssetExtension(new Packages(new Package(new EmptyVersionStrategy())));
- Exclude checks
Reference to constant class
from undeclared class \Phug\Component\ComponentExtension
Open
$this->componentExtension = $pug->getModule(ComponentExtension::class);
- Exclude checks
Call to method get
from undeclared class \Symfony\Component\DependencyInjection\ContainerInterface
Open
: $this->container->get('router')->getContext();
- Exclude checks
Possibly zero references to use statement for classlike/namespace ExtensionInterface
(\Twig\Extension\ExtensionInterface)
Open
use Twig\Extension\ExtensionInterface;
- Exclude checks
Call to undeclared method \Pug\Twig\Environment::getExtensions
Open
$twig->extensions = $twig->getExtensions();
- Exclude checks
Reference to constant class
from undeclared class \Symfony\Bridge\Twig\Extension\AssetExtension
Open
$assetExtension = $twig->extensions[AssetExtension::class] ?? null;
- Exclude checks
Parameter $function
has undeclared type \Twig\TwigFunction
Open
protected function copyTwigFunction(TwigFunction $function): void
- Exclude checks
Reference to undeclared property \Pug\Symfony\Traits\HelpersHandler->options
Open
if ($this->options === null) {
- Exclude checks
Call to method getOption
from undeclared class \Pug\Pug
Open
? ($pug->getOption('patterns')['transform_expression'] ?? null)
- Exclude checks
Static call to undeclared method \Pug\Symfony\Traits\HelpersHandler::extractUniquePaths
Open
'viewDirectories' => static::extractUniquePaths($viewDirectories),
- Exclude checks
Call to method __construct
from undeclared class \Pug\Pug
Open
$pug = new Pug($options);
- Exclude checks
Call to method __construct
from undeclared class \Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy
Open
$assetExtension = new AssetExtension(new Packages(new Package(new EmptyVersionStrategy())));
- Exclude checks
Reference to undeclared property \Pug\Symfony\Traits\HelpersHandler->options
(Did you mean $options) Open
$this->options = $options;
- Exclude checks
Call to method getOption
from undeclared class \Pug\Pug
Open
$pug->getCompiler()->setOption('mixin_keyword', $pug->getOption('mixin_keyword'));
- Exclude checks
Call to method has
from undeclared class \Symfony\Component\DependencyInjection\ContainerInterface
Open
$context = $this->container->has('router.request_context')
- Exclude checks
Call to method get
from undeclared class \Symfony\Component\DependencyInjection\ContainerInterface
Open
? $this->container->get('router.request_context')
- Exclude checks
Call to method hasOption
from undeclared class \Pug\Pug
Open
$transformation = $pug->hasOption('patterns')
- Exclude checks
Call to undeclared method \Pug\Twig\Environment::getLoader
Open
$loader = new MixedLoader($twig->getLoader());
- Exclude checks
Call to undeclared method \Pug\Symfony\Traits\HelpersHandler::setOption
Open
$this->setOption('paths', array_unique($this->getOptionDefault('paths', [])));
- Exclude checks
Call to method has
from undeclared class \Symfony\Component\DependencyInjection\ContainerInterface
Open
$this->twig = $this->container->has('twig') ? $this->container->get('twig') : null;
- Exclude checks
Reference to constant class
from undeclared class \Symfony\Bridge\Twig\Extension\AssetExtension
Open
$twig->extensions[AssetExtension::class] = $assetExtension;
- Exclude checks
Reference to undeclared property \Pug\Symfony\Traits\HelpersHandler->options
(Did you mean $options) Open
return $this->options;
- Exclude checks
Avoid excessively long variable names like $argumentNeedInterpolation. Keep variable name length under 20. Open
protected function pushArgument(array &$arguments, string &$argument, bool &$argumentNeedInterpolation)
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $argumentNeedInterpolation. Keep variable name length under 20. Open
$argumentNeedInterpolation = false;
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}