Test Setup Failed
Pull Request — master (#19)
by Flo
03:33
created

CodeBlock   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 44
rs 10
c 1
b 0
f 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 32 5
1
<?php
2
/**
3
 * Class CodeBlock | CodeBlock.php
4
 * @package Faulancer\View\Helper
5
 * @author  Florian Knapp <[email protected]>
6
 */
7
namespace Faulancer\View\Helper;
8
9
use Faulancer\View\AbstractViewHelper;
10
use Faulancer\View\ViewController;
11
12
/**
13
 * Class CodeBlock
14
 */
15
class CodeBlock extends AbstractViewHelper
16
{
17
18
    /**
19
     * @param ViewController $view
20
     * @param                $filename
21
     * @param int            $actualLine
22
     * @return string
23
     * @codeCoverageIgnore
24
     */
25
    public function __invoke(ViewController $view, $filename, $actualLine = 0)
26
    {
27
28
        $lineNr = 0;
29
        $lines  = '';
30
        $file   = fopen($filename, 'r');
31
32
        $tabChar = '&nbsp;&nbsp;&nbsp;&nbsp;';
33
        $regularChar = '&nbsp;';
34
35
        while ($line = fgets($file)) {
36
37
            $lineNr++;
38
39
            if ($lineNr >= $actualLine - 6 && $lineNr <= $actualLine + 3) {
40
41
                $l = str_replace("\t", $tabChar, $line);
42
                $l = str_replace(" ", $regularChar, $l);
43
44
                if ($lineNr === $actualLine) {
45
                    $lines .= '<span class="line highlight"><span class="line-nr">' . $lineNr . '</span>' . $view->highlighter($l, 'php') . '</span>';
0 ignored issues
show
Documentation Bug introduced by
The method highlighter does not exist on object<Faulancer\View\ViewController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
46
                } else {
47
                    $lines .= '<span class="line"><span class="line-nr">' . $lineNr . '</span>' . $view->highlighter($l, 'php') . '</span>';
0 ignored issues
show
Documentation Bug introduced by
The method highlighter does not exist on object<Faulancer\View\ViewController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
48
                }
49
50
            }
51
52
        }
53
54
        return $lines;
55
56
    }
57
58
}