Completed
Push — master ( 854d00...730952 )
by Edson
02:03
created

ElseifView   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A elseif() 0 8 3
A setElseifContent() 0 13 3
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 9 and the first side effect is on line 5.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Bonfim\Component\View;
4
5
trait ElseifView
0 ignored issues
show
Bug introduced by
Possible parse error: trait missing opening or closing brace
Loading history...
6
{
7
    private $elseif = array();
8
9 8
    private function setElseifContent()
10
    {
11 8
        $pattern = '/{\s?elseif (.*?)\s?([><!=])(=)?(=)?\s?(.*?)\s?}(.*?){end}/is';
12 8
        if (preg_match_all($pattern, $this->ifContent, $matches, PREG_SET_ORDER)) {
13 4
            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...
14 4
                $this->ifContent = str_replace($matches[$i][0], '', $this->ifContent);
0 ignored issues
show
Bug Best Practice introduced by
The property ifContent does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
15 4
                $this->elseif[$i]['firstCondition'] = $this->setCondition($matches[$i][1]);
0 ignored issues
show
Bug introduced by
It seems like setCondition() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

15
                /** @scrutinizer ignore-call */ 
16
                $this->elseif[$i]['firstCondition'] = $this->setCondition($matches[$i][1]);
Loading history...
16 4
                $this->elseif[$i]['secondCondition'] = $this->setCondition($matches[$i][5]);
17 4
                $this->elseif[$i]['operator'] = implode('', array_slice($matches[$i], 2, 3));
18 4
                $this->elseif[$i]['content'] = trim($matches[$i][6]);
19
            }
20
        }
21 8
        $this->ifContent = str_replace('{end}', '', $this->ifContent);
22 8
    }
23
24 8
    private function elseif(): void
25
    {
26 8
        if (count($this->elseif) != 0) {
27 4
            for ($i = 0; $i < count($this->elseif); $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...
28 4
                $this->replace .= "<?php elseif({$this->elseif[$i]['firstCondition']}";
0 ignored issues
show
Bug Best Practice introduced by
The property replace does not exist on Bonfim\Component\View\ElseifView. Did you maybe forget to declare it?
Loading history...
29 4
                $this->replace .= " {$this->elseif[$i]['operator']}";
30 4
                $this->replace .= " {$this->elseif[$i]['secondCondition']}): ?>";
31 4
                $this->replace .= trim($this->elseif[$i]['content']);
32
            }
33
        }
34 8
    }
35
}
36