Showing 23 of 23 total issues
Function fetch
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
public function fetch($template, array $data = [])
{
if (!method_exists($this->adapter, 'renderFile')) {
$file = $this->getTemplatePath();
$file = $file ? $file : '';
- 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
Parameter $app
has undeclared type ?\Slim\App
Open
Open
public static function create(App $app = null, $templatePath = null, array $options = [], array $attributes = [])
- Exclude checks
Reference to constant class
from undeclared class \Pug\Pug
Open
Open
$className = isset($options['renderer']) ? $options['renderer'] : Pug::class;
- Exclude checks
Return type of create()
is undeclared type \Slim\App
Open
Open
public static function create(App $app = null, $templatePath = null, array $options = [], array $attributes = [])
- Exclude checks
Call to method getBody
from undeclared class \Psr\Http\Message\ResponseInterface
Open
Open
$response->getBody()->write($output);
- Exclude checks
Parameter $response
has undeclared type \Psr\Http\Message\ResponseInterface
Open
Open
public function render(ResponseInterface $response, $template, array $data = [])
- Exclude checks
Checking instanceof against undeclared class \Tale\Pug\Renderer
Open
Open
if ($this->adapter instanceof \Tale\Pug\Renderer && !($this->adapter instanceof \Phug\Renderer)) {
- Exclude checks
Call to method share
from undeclared class \Pug\Pug
Open
Open
$this->adapter->share($attributes);
- Exclude checks
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
Open
* @param App $app
- Exclude checks
Checking instanceof against undeclared class \Phug\Renderer
Open
Open
if ($this->adapter instanceof \Tale\Pug\Renderer && !($this->adapter instanceof \Phug\Renderer)) {
- Exclude checks
Define a constant instead of duplicating this literal "renderer" 3 times. Open
Open
$className = isset($options['renderer']) ? $options['renderer'] : Pug::class;
- 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.
Call to method getContainer
from undeclared class \Slim\App
Open
Open
$container = $app->getContainer();
- Exclude checks
Return type of render()
is undeclared type \Psr\Http\Message\ResponseInterface
Open
Open
public function render(ResponseInterface $response, $template, array $data = [])
- Exclude checks
Call to method render
from undeclared class \Pug\Pug
Open
Open
return $this->adapter->render(file_get_contents($file), $file, $data);
- Exclude checks
Call to method share
from undeclared class \Pug\Pug
Open
Open
$this->adapter->share($key, $value);
- Exclude checks
Property \Slim\Pug\PugRenderer->adapter
has undeclared type \Pug\Pug
Open
Open
private $adapter;
- Exclude checks
Call to method share
from undeclared class \Pug\Pug
Open
Open
$this->adapter->share($attributes);
- Exclude checks
Call to method __construct
from undeclared class \Slim\App
Open
Open
$app = new App();
- Exclude checks
Call to method getOption
from undeclared class \Pug\Pug
Open
Open
: $this->adapter->getOption($name);
- Exclude checks
Call to method renderFile
from undeclared class \Pug\Pug
Open
Open
return $this->adapter->renderFile($template, $data);
- Exclude checks