pug-php/pug-symfony

View on GitHub
src/Pug/Twig/Environment.php

Summary

Maintainability
B
6 hrs
Test Coverage

Function compileSource has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

    public function compileSource(Source $source): string
    {
        $path = $source->getPath();

        if ($this->pugSymfonyEngine->supports($path)) {
Severity: Minor
Found in src/Pug/Twig/Environment.php - About 3 hrs 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

Method compileSource has 45 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function compileSource(Source $source): string
    {
        $path = $source->getPath();

        if ($this->pugSymfonyEngine->supports($path)) {
Severity: Minor
Found in src/Pug/Twig/Environment.php - About 1 hr to fix

    Method fromTwigEnvironment has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function fromTwigEnvironment(TwigEnvironment $baseTwig, PugSymfonyEngine $pugSymfonyEngine, ContainerInterface $container)
        {
            $twig = new static($baseTwig->getLoader(), [
                'debug'            => $baseTwig->isDebug(),
                'charset'          => $baseTwig->getCharset(),
    Severity: Minor
    Found in src/Pug/Twig/Environment.php - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

                                  if ($newLine > $templateLine) {
                                      $templateLine = $newLine;
                                      $debugInfo[$codeFirstLine + $index] = $newLine;
                                  }
      Severity: Major
      Found in src/Pug/Twig/Environment.php - About 45 mins to fix

        The method compileSource() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
        Open

            public function compileSource(Source $source): string
            {
                $path = $source->getPath();
        
                if ($this->pugSymfonyEngine->supports($path)) {
        Severity: Minor
        Found in src/Pug/Twig/Environment.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 29 to the 15 allowed.
        Open

            public function compileSource(Source $source): string
        Severity: Critical
        Found in src/Pug/Twig/Environment.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 using undefined variables such as '$arguments' which will lead to PHP notices.
        Open

                $arguments[] = $name;
        Severity: Minor
        Found in src/Pug/Twig/Environment.php by phpmd

        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

        Duplicated array key {{filename}}, first declared at line 177.
        Open

                    $replacements = [
                        $fileName               => $className,
                        '"{{filename}}"'        => var_export($name, true),
                        '{{filename}}'          => $name,
                        '"{{path}}"'            => var_export($path, true),
        Severity: Minor
        Found in src/Pug/Twig/Environment.php by phpmd

        DuplicatedArrayKey

        Defining another value for the same key in an array literal overrides the previous key/value, which makes it effectively an unused code. If it's known from the beginning that the key will have different value, there is usually no point in defining first one.

        Example

        function createArray() {
            return [
                'non-associative 0element', // not applied
                0 => 'associative 0-element', // applied
                false => 'associative 0-element', // applied
                'foo' => 'bar', // not applied
                "foo" => 'baz', // applied
            ];
        }

        Source http://phpmd.org/rules/cleancode.html#duplicatedarraykey

        Define and throw a dedicated exception instead of using a generic one.
        Open

                    throw new RuntimeException('Unable to compile '.$name.' function.');
        Severity: Major
        Found in src/Pug/Twig/Environment.php by sonar-php

        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

        Avoid unused local variables such as '$arguments'.
        Open

                $arguments[] = $name;
        Severity: Minor
        Found in src/Pug/Twig/Environment.php by phpmd

        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

        Call to method getCode from undeclared class \Twig\Source
        Open

                    $code = $source->getCode();
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to method __construct from undeclared class \Twig\Parser
        Open

                $parser = new Parser($this);
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to method __construct from undeclared class \Twig\Source
        Open

                $stream = $this->tokenize(new Source($code, $path, $path));
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Class extends undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

        class Environment extends TwigEnvironment
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Property \Pug\Twig\Environment->rootEnv has undeclared type \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

            public $rootEnv;
        Severity: Minor
        Found in src/Pug/Twig/Environment.php by phan

        Call to method getCache from undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                    'cache'            => $baseTwig->getCache(true),
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Reference to constant class from undeclared class \Twig\Extension\OptimizerExtension
        Open

                    'optimizations'    => static::getPrivateExtensionProperty($baseTwig, OptimizerExtension::class, 'optimizers'),
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to undeclared method \Pug\Twig\Environment::addFunction
        Open

                    $twig->addFunction($function);
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Parameter $source has undeclared type \Twig\Source (Did you mean resource)
        Open

            public function compileSource(Source $source): string
        Severity: Minor
        Found in src/Pug/Twig/Environment.php by phan

        Variable $arguments was undeclared, but array fields are being added to it.
        Open

                $arguments[] = $name;
        Severity: Info
        Found in src/Pug/Twig/Environment.php by phan

        Call to method parse from undeclared class \Twig\Parser
        Open

                $output = $this->compile($parser->parse($stream));
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Catching undeclared class \Twig\Error\RuntimeError
        Open

                } catch (RuntimeError $error) {
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

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

                    $php = $pug->compile($code, $path);
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to method getRuntime from undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                        return $this->rootEnv->getRuntime($class);
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to method getCharset from undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                    'charset'          => $baseTwig->getCharset(),
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Parameter $twig has undeclared type \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

            protected static function getPrivateExtensionProperty(TwigEnvironment $twig, string $extension, string $property)
        Severity: Minor
        Found in src/Pug/Twig/Environment.php by phan

        Call to undeclared method \Pug\Twig\Environment::addFilter
        Open

                    $twig->addFilter($filter);
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Reference to undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                $html = parent::compileSource($source);
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to undeclared method \Pug\Twig\Environment::tokenize
        Open

                $stream = $this->tokenize(new Source($code, $path, $path));
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to undeclared method \Pug\Twig\Environment::compile
        Open

                $output = $this->compile($parser->parse($stream));
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to method getExtensions from undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                $extensions = $baseTwig->getExtensions();
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to method getFilters from undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                foreach ($baseTwig->getFilters() as $filter) {
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Parameter $baseTwig has undeclared type \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

            public static function fromTwigEnvironment(TwigEnvironment $baseTwig, PugSymfonyEngine $pugSymfonyEngine, ContainerInterface $container)
        Severity: Minor
        Found in src/Pug/Twig/Environment.php by phan

        Call to undeclared method \Pug\Twig\Environment::getExtensions
        Open

                foreach (array_keys($twig->getExtensions()) as $key) {
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Reference to undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                parent::__construct($loader, $options);
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Parameter $container has undeclared type \Symfony\Component\DependencyInjection\ContainerInterface
        Open

            public static function fromTwigEnvironment(TwigEnvironment $baseTwig, PugSymfonyEngine $pugSymfonyEngine, ContainerInterface $container)
        Severity: Minor
        Found in src/Pug/Twig/Environment.php by phan

        Call to method isStrictVariables from undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                    'strict_variables' => $baseTwig->isStrictVariables(),
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to method getFunctions from undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                foreach ($baseTwig->getFunctions() as $function) {
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to method getName from undeclared class \Twig\TwigFunction
        Open

                $name = $function->getName();
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Parameter $container has undeclared type \Symfony\Component\DependencyInjection\ContainerInterface
        Open

            public function setContainer(ContainerInterface $container): void
        Severity: Minor
        Found in src/Pug/Twig/Environment.php by phan

        Call to undeclared method \Pug\Twig\Environment::isDebug
        Open

                    if ($this->isDebug()) {
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Catching undeclared class \Twig\Error\RuntimeError
        Open

                    } catch (RuntimeError $_) {
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to method getLoader from undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                $twig = new static($baseTwig->getLoader(), [
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to undeclared method \Pug\Twig\Environment::addGlobal
        Open

                    $twig->addGlobal($key, $value);
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to method getExtension from undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                return static::getPrivateProperty($twig->getExtension($extension), $property);
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Property \Pug\Twig\Environment->container has undeclared type \Symfony\Component\DependencyInjection\ContainerInterface
        Open

            protected $container;
        Severity: Minor
        Found in src/Pug/Twig/Environment.php by phan

        Call to method isDebug from undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                    'debug'            => $baseTwig->isDebug(),
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Reference to constant class from undeclared class \Twig\Extension\EscaperExtension
        Open

                    'autoescape'       => static::getPrivateExtensionProperty($baseTwig, EscaperExtension::class, 'defaultStrategy'),
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to undeclared method \Pug\Twig\Environment::isDebug
        Open

                    if ($this->isDebug()) {
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Reference to undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                return parent::loadTemplate($cls, $name, $index);
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Parameter $function has undeclared type \Twig\TwigFunction
        Open

            public function compileCode(TwigFunction $function, string $code)
        Severity: Minor
        Found in src/Pug/Twig/Environment.php by phan

        Call to undeclared method \Pug\Twig\Environment::getExtensions
        Open

                $this->extensions = $this->getExtensions();
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Reference to undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                    return parent::getRuntime($class);
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to method getPath from undeclared class \Twig\Source
        Open

                $path = $source->getPath();
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to undeclared method \Pug\Twig\Environment::isDebug
        Open

                    $codeFirstLine = $this->isDebug() ? 31 : 25;
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to undeclared method \Pug\Twig\Environment::isDebug
        Open

                    $fileName = $this->isDebug() ? 'PugDebugTemplateTemplate' : 'PugTemplateTemplate';
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Return type of loadTemplate() is undeclared type \Twig\Template
        Open

            public function loadTemplate(string $cls, string $name, int $index = null): Template
        Severity: Minor
        Found in src/Pug/Twig/Environment.php by phan

        Reference to undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                return parent::getTemplateClass($name, $index);
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Parameter $loader has undeclared type \Twig\Loader\LoaderInterface
        Open

            public function __construct(LoaderInterface $loader, $options = [])
        Severity: Minor
        Found in src/Pug/Twig/Environment.php by phan

        Call to method getGlobals from undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                foreach ($baseTwig->getGlobals() as $key => $value) {
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to undeclared method \Pug\Twig\Environment::setExtensions
        Open

                $twig->setExtensions($extensions);
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to method getName from undeclared class \Twig\Source
        Open

                    $name = $source->getName();
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Call to method isAutoReload from undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                    'auto_reload'      => $baseTwig->isAutoReload(),
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

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

                        $formatter = $pug->getCompiler()->getFormatter();
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Reference to undeclared class \Twig\Environment (Did you mean class \Pug\Twig\Environment)
        Open

                return parent::render($name, $context);
        Severity: Critical
        Found in src/Pug/Twig/Environment.php by phan

        Line exceeds 120 characters; contains 140 characters
        Open

            public static function fromTwigEnvironment(TwigEnvironment $baseTwig, PugSymfonyEngine $pugSymfonyEngine, ContainerInterface $container)
        Severity: Minor
        Found in src/Pug/Twig/Environment.php by phpcodesniffer

        Line exceeds 120 characters; contains 125 characters
        Open

                    'autoescape'       => static::getPrivateExtensionProperty($baseTwig, EscaperExtension::class, 'defaultStrategy'),
        Severity: Minor
        Found in src/Pug/Twig/Environment.php by phpcodesniffer

        Line exceeds 120 characters; contains 122 characters
        Open

                    'optimizations'    => static::getPrivateExtensionProperty($baseTwig, OptimizerExtension::class, 'optimizers'),
        Severity: Minor
        Found in src/Pug/Twig/Environment.php by phpcodesniffer

        The variable $_ is not named in camelCase.
        Open

            public function getRuntime(string $class)
            {
                try {
                    return parent::getRuntime($class);
                } catch (RuntimeError $error) {
        Severity: Minor
        Found in src/Pug/Twig/Environment.php by phpmd

        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

        There are no issues that match your filters.

        Category
        Status