pug-php/pug-symfony

View on GitHub
src/Pug/PugSymfonyEngine.php

Summary

Maintainability
A
1 hr
Test Coverage

Function crawlDirectories has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    protected function crawlDirectories(string $srcDir, array &$assetsDirectories, array &$viewDirectories): ?string
    {
        $baseDir = file_exists($viewDirectories[0]) ? $viewDirectories[0] : null;

        if (file_exists($srcDir)) {
Severity: Minor
Found in src/Pug/PugSymfonyEngine.php - About 1 hr to fix

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 crawlDirectories() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
Open

    protected function crawlDirectories(string $srcDir, array &$assetsDirectories, array &$viewDirectories): ?string
    {
        $baseDir = file_exists($viewDirectories[0]) ? $viewDirectories[0] : null;

        if (file_exists($srcDir)) {
Severity: Minor
Found in src/Pug/PugSymfonyEngine.php by phpmd

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 16 to the 15 allowed.
Open

    protected function crawlDirectories(string $srcDir, array &$assetsDirectories, array &$viewDirectories): ?string
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by sonar-php

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 assigning values to variables in if clauses and the like (line '84', column '28').
Open

    protected function crawlDirectories(string $srcDir, array &$assetsDirectories, array &$viewDirectories): ?string
    {
        $baseDir = file_exists($viewDirectories[0]) ? $viewDirectories[0] : null;

        if (file_exists($srcDir)) {
Severity: Minor
Found in src/Pug/PugSymfonyEngine.php by phpmd

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 '110', column '17').
Open

    protected function getFileFromName(string $name, string $directory = null): string
    {
        $parts = explode(':', strval($name));

        if (count($parts) > 1) {
Severity: Minor
Found in src/Pug/PugSymfonyEngine.php by phpmd

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 "shared_variables" 3 times.
Open

        $variables = array_merge($this->getOptionDefault('shared_variables', []), $variables);
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by sonar-php

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.

Property \Pug\PugSymfonyEngine->assets has undeclared type \Pug\Assets
Open

    protected $assets;
Severity: Minor
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method getNode from undeclared class \Phug\Compiler\Event\NodeEvent
Open

        $node = $nodeEvent->getNode();
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Parameter $name has undeclared type \Symfony\Component\Templating\TemplateReferenceInterface
Open

    public function exists($name): bool
Severity: Minor
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method setValue from undeclared class \Phug\Parser\Node\TextNode
Open

            $code->setValue('$this->loadTemplate('.$path.', '.$template.', '.$line.')->display($context);');
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method get from undeclared class \Symfony\Component\DependencyInjection\ContainerInterface
Open

            $dispatcher = $container->get('event_dispatcher');
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method __construct from undeclared class \Phug\Parser\Node\TextNode
Open

            $code = new TextNode($node->getToken());
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method renderFile from undeclared class \Pug\Pug
Open

        return $this->getRenderer()->renderFile(
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method getContainer from undeclared class \Symfony\Component\HttpKernel\KernelInterface
Open

        $container = $kernel->getContainer();
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method getName from undeclared class \Phug\Parser\Node\ImportNode
Open

        if ($node instanceof ImportNode && $node->getName() === 'include') {
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Parameter $nodeEvent has undeclared type \Phug\Compiler\Event\NodeEvent
Open

    public function handleTwigInclude(NodeEvent $nodeEvent): void
Severity: Minor
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method getToken from undeclared class \Phug\Parser\Node\ImportNode
Open

            $code = new TextNode($node->getToken());
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method getToken from undeclared class \Phug\Parser\Node\ImportNode
Open

            $filter = new FilterNode($node->getToken());
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method getCacheDir from undeclared class \Symfony\Component\HttpKernel\Kernel
Open

        return $this->kernel->getCacheDir().DIRECTORY_SEPARATOR.'pug';
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method getParameter from undeclared class \Symfony\Component\DependencyInjection\ContainerInterface
Open

        $this->userOptions = ($this->container->hasParameter('pug') ? $this->container->getParameter('pug') : null) ?: [];
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Saw an @param annotation for name, but it was not found in the param list of function renderString($code, array $locals = null) : string
Open

     * @param string|\Symfony\Component\Templating\TemplateReferenceInterface $name
Severity: Info
Found in src/Pug/PugSymfonyEngine.php by phan

Parameter $name has undeclared type \Symfony\Component\Templating\TemplateReferenceInterface
Open

    public function supports($name): bool
Severity: Minor
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method has from undeclared class \Symfony\Component\DependencyInjection\ContainerInterface
Open

        if ($container->has('event_dispatcher')) {
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method get from undeclared class \Symfony\Component\DependencyInjection\ContainerInterface
Open

                return $container->get($interceptorClass);
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method getSourceLocation from undeclared class \Phug\Parser\Node\ImportNode
Open

            $location = $node->getSourceLocation();
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method setNode from undeclared class \Phug\Compiler\Event\NodeEvent
Open

            $nodeEvent->setNode($filter);
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Class implements undeclared interface \Symfony\Component\Templating\EngineInterface
Open

class PugSymfonyEngine implements EngineInterface, InstallerInterface
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method getPath from undeclared class \Phug\Parser\Node\ImportNode
Open

            $path = var_export($node->getPath(), true);
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Checking instanceof against undeclared class \Phug\Parser\Node\ImportNode
Open

        if ($node instanceof ImportNode && $node->getName() === 'include') {
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method __construct from undeclared class \Phug\Parser\Node\FilterNode
Open

            $filter = new FilterNode($node->getToken());
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method setName from undeclared class \Phug\Parser\Node\FilterNode
Open

            $filter->setName('php');
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Parameter $kernel has undeclared type \Symfony\Component\HttpKernel\KernelInterface
Open

    public function __construct(KernelInterface $kernel)
Severity: Minor
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method appendChild from undeclared class \Phug\Parser\Node\FilterNode
Open

            $filter->appendChild($code);
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method hasParameter from undeclared class \Symfony\Component\DependencyInjection\ContainerInterface
Open

        $this->userOptions = ($this->container->hasParameter('pug') ? $this->container->getParameter('pug') : null) ?: [];
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method getBundle from undeclared class \Symfony\Component\HttpKernel\Kernel
Open

            if ($bundle = $this->kernel->getBundle($parts[0])) {
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Parameter $name has undeclared type \Symfony\Component\Templating\TemplateReferenceInterface
Open

    public function render($name, array $parameters = []): string
Severity: Minor
Found in src/Pug/PugSymfonyEngine.php by phan

Call to method renderString from undeclared class \Pug\Pug
Open

        return $pug->$method(
Severity: Critical
Found in src/Pug/PugSymfonyEngine.php by phan

Property \Pug\PugSymfonyEngine->componentExtension has undeclared type \Phug\Component\ComponentExtension
Open

    protected $componentExtension;
Severity: Minor
Found in src/Pug/PugSymfonyEngine.php by phan

Avoid excessively long variable names like $defaultTemplateDirectory. Keep variable name length under 20.
Open

    protected $defaultTemplateDirectory;
Severity: Minor
Found in src/Pug/PugSymfonyEngine.php by phpmd

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

Line exceeds 120 characters; contains 122 characters
Open

        $this->userOptions = ($this->container->hasParameter('pug') ? $this->container->getParameter('pug') : null) ?: [];
Severity: Minor
Found in src/Pug/PugSymfonyEngine.php by phpcodesniffer

There are no issues that match your filters.

Category
Status