Passed
Push — master ( 67cfc6...1f1489 )
by Edson
01:18
created

IncludeTag   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 7 3
1
<?php
2
3
namespace Sketch\Tpl;
4
5
class IncludeTag extends Tag
0 ignored issues
show
Bug introduced by
The type Sketch\Tpl\Tag was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
{
7
    private $pattern = '/{\s?include \'?"?(.*?)"?\'?\s?}/is';
8
9
    public function handle(): void
10
    {
11
        if (preg_match_all($this->pattern, self::$content, $matches, PREG_SET_ORDER)) {
12
            for ($i = 0; $i < count($matches); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
13
                $match = $matches[$i];
14
                $replace = file_get_contents(self::$config['template_dir'] . "/{$match[1]}.html");
15
                self::$content = str_replace($matches[$i][0], $replace, self::$content);
0 ignored issues
show
Bug Best Practice introduced by
The property content does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
16
            };
17
        }
18
    }
19
}
20