pug-php/pug-slim

View on GitHub
src/PugRenderer.php

Summary

Maintainability
A
45 mins
Test Coverage

Function fetch has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    public function fetch($template, array $data = [])
    {
        if (!method_exists($this->adapter, 'renderFile')) {
            $file = $this->getTemplatePath();
            $file = $file ? $file : '';
Severity: Minor
Found in src/PugRenderer.php - About 45 mins 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

Reference to constant class from undeclared class \Pug\Pug
Open

        $className = isset($options['renderer']) ? $options['renderer'] : Pug::class;
Severity: Critical
Found in src/PugRenderer.php by phan

Doc-block of $app in create is phpdoc param type \Slim\App which is not a permitted replacement of the nullable param type ?\Slim\App declared in the signature ('?T' should be documented as 'T|null' or '?T')
Open

     * @param App    $app
Severity: Minor
Found in src/PugRenderer.php by phan

Call to method __construct from undeclared class \Slim\App
Open

            $app = new App();
Severity: Critical
Found in src/PugRenderer.php by phan

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

        $this->adapter->share($attributes);
Severity: Critical
Found in src/PugRenderer.php by phan

Parameter $response has undeclared type \Psr\Http\Message\ResponseInterface
Open

    public function render(ResponseInterface $response, $template, array $data = [])
Severity: Minor
Found in src/PugRenderer.php by phan

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

            return $this->adapter->render(file_get_contents($file), $file, $data);
Severity: Critical
Found in src/PugRenderer.php by phan

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

            return method_exists($this->adapter, 'hasOption') && !$this->adapter->hasOption($name)
Severity: Critical
Found in src/PugRenderer.php by phan

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

                : $this->adapter->getOption($name);
Severity: Critical
Found in src/PugRenderer.php by phan

Checking instanceof against undeclared class \Tale\Pug\Renderer
Open

        if ($this->adapter instanceof \Tale\Pug\Renderer && !($this->adapter instanceof \Phug\Renderer)) {
Severity: Critical
Found in src/PugRenderer.php by phan

Call to method getContainer from undeclared class \Slim\App
Open

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

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

        $this->adapter->share($key, $value);
Severity: Critical
Found in src/PugRenderer.php by phan

Return type of render() is undeclared type \Psr\Http\Message\ResponseInterface
Open

    public function render(ResponseInterface $response, $template, array $data = [])
Severity: Minor
Found in src/PugRenderer.php by phan

Return type of create() is undeclared type \Slim\App
Open

    public static function create(App $app = null, $templatePath = null, array $options = [], array $attributes = [])
Severity: Minor
Found in src/PugRenderer.php by phan

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

        return $this->adapter->renderFile($template, $data);
Severity: Critical
Found in src/PugRenderer.php by phan

Parameter $app has undeclared type ?\Slim\App
Open

    public static function create(App $app = null, $templatePath = null, array $options = [], array $attributes = [])
Severity: Minor
Found in src/PugRenderer.php by phan

Call to method getBody from undeclared class \Psr\Http\Message\ResponseInterface
Open

        $response->getBody()->write($output);
Severity: Critical
Found in src/PugRenderer.php by phan

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

            $this->adapter->compile(''); // Init ->files
Severity: Critical
Found in src/PugRenderer.php by phan

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

        $this->adapter->share($attributes);
Severity: Critical
Found in src/PugRenderer.php by phan

Checking instanceof against undeclared class \Phug\Renderer
Open

        if ($this->adapter instanceof \Tale\Pug\Renderer && !($this->adapter instanceof \Phug\Renderer)) {
Severity: Critical
Found in src/PugRenderer.php by phan

Property \Slim\Pug\PugRenderer->adapter has undeclared type \Pug\Pug
Open

    private $adapter;
Severity: Minor
Found in src/PugRenderer.php by phan

Define a constant instead of duplicating this literal "renderer" 3 times.
Open

        $className = isset($options['renderer']) ? $options['renderer'] : Pug::class;
Severity: Critical
Found in src/PugRenderer.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.

Define a constant instead of duplicating this literal "templates.path" 4 times.
Open

            $templatePath = isset($options['templates.path']) ? $options['templates.path'] : null;
Severity: Critical
Found in src/PugRenderer.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.

There are no issues that match your filters.

Category
Status