Test Setup Failed
Push — test ( dd7d7c...b3915a )
by Jonathan
03:06
created

PlainRenderer::preRender()   D

Complexity

Conditions 9
Paths 3

Size

Total Lines 34
Code Lines 21

Duplication

Lines 34
Ratio 100 %

Importance

Changes 0
Metric Value
cc 9
eloc 21
nc 3
nop 0
dl 34
loc 34
rs 4.909
c 0
b 0
f 0
1
<?php
2
3
namespace Kint\Renderer;
4
5
use Kint\Kint;
6
use Kint\Object\BasicObject;
7
use Kint\Object\BlobObject;
8
9
class PlainRenderer extends TextRenderer
0 ignored issues
show
Coding Style introduced by
The property $pre_render_sources is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $disable_utf8 is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $been_run is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
10
{
11
    public static $pre_render_sources = array(
0 ignored issues
show
Coding Style introduced by
$pre_render_sources does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
12
        'script' => array(),
13
        'style' => array(
14
            array('Kint\\Renderer\\PlainRenderer', 'renderCss'),
15
        ),
16
        'raw' => array(),
17
    );
18
19
    /**
20
     * Path to the CSS file to load by default.
21
     *
22
     * @var string
23
     */
24
    public static $theme = 'plain.css';
25
26
    /**
27
     * Output htmlentities instead of utf8.
28
     *
29
     * @var bool
30
     */
31
    public static $disable_utf8 = false;
0 ignored issues
show
Coding Style introduced by
$disable_utf8 does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
32
33
    protected static $been_run = false;
0 ignored issues
show
Coding Style introduced by
$been_run does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
34
35 View Code Duplication
    protected function utf8ToHtmlentity($string)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        return str_replace(
38
            array('┌', '═', '┐', '│', '└', '─', '┘'),
39
            array('&#9484;', '&#9552;', '&#9488;', '&#9474;', '&#9492;', '&#9472;', '&#9496;'),
40
            $string
41
        );
42
    }
43
44
    public function colorValue($string)
45
    {
46
        return '<i>'.$string.'</i>';
47
    }
48
49
    public function colorType($string)
50
    {
51
        return '<b>'.$string.'</b>';
52
    }
53
54
    public function colorTitle($string)
55
    {
56
        return '<u>'.$string.'</u>';
57
    }
58
59
    public function renderTitle(BasicObject $o)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $o. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
60
    {
61
        if (self::$disable_utf8) {
62
            return $this->utf8ToHtmlentity(parent::renderTitle($o));
63
        } else {
64
            return parent::renderTitle($o);
65
        }
66
    }
67
68 View Code Duplication
    protected static function renderCss()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        if (file_exists(KINT_DIR.'/resources/compiled/'.self::$theme)) {
71
            return file_get_contents(KINT_DIR.'/resources/compiled/'.self::$theme);
72
        } else {
73
            return file_get_contents(self::$theme);
74
        }
75
    }
76
77 View Code Duplication
    public function preRender()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
    {
79
        $output = '';
80
81
        if (!self::$been_run || $this->return_mode) {
82
            foreach (self::$pre_render_sources as $type => $values) {
83
                $contents = '';
84
                foreach ($values as $v) {
85
                    $contents .= call_user_func($v, $this);
86
                }
87
88
                if (!strlen($contents)) {
89
                    continue;
90
                }
91
92
                switch ($type) {
93
                    case 'script':
94
                        $output .= '<script class="kint-script">'.$contents.'</script>';
95
                        break;
96
                    case 'style':
97
                        $output .= '<style class="kint-style">'.$contents.'</style>';
98
                        break;
99
                    default:
100
                        $output .= $contents;
101
                }
102
            }
103
104
            if (!$this->return_mode) {
105
                self::$been_run = true;
106
            }
107
        }
108
109
        return $output.'<div class="kint-plain">';
110
    }
111
112
    public function postRender()
113
    {
114
        if (self::$disable_utf8) {
115
            return $this->utf8ToHtmlentity(parent::postRender()).'</div>';
116
        } else {
117
            return parent::postRender().'</div>';
118
        }
119
    }
120
121 View Code Duplication
    public function ideLink($file, $line)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
122
    {
123
        $path = $this->escape(Kint::shortenPath($file)).':'.$line;
124
        $ideLink = Kint::getIdeLink($file, $line);
125
126
        if (!$ideLink) {
127
            return $path;
128
        }
129
130
        $class = '';
131
132
        if (preg_match($ideLink, '/https?:\/\//i')) {
133
            $class = 'class="kint-ide-link" ';
134
        }
135
136
        return '<a '.$class.'href="'.$this->escape($ideLink).'">'.$path.'</a>';
137
    }
138
139 View Code Duplication
    public function escape($string, $encoding = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
140
    {
141
        if ($encoding === false) {
142
            $encoding = BlobObject::detectEncoding($string);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $encoding. This often makes code more readable.
Loading history...
143
        }
144
145
        $original_encoding = $encoding;
0 ignored issues
show
Coding Style introduced by
$original_encoding does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
146
147
        if ($encoding === false || $encoding === 'ASCII') {
148
            $encoding = 'UTF-8';
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $encoding. This often makes code more readable.
Loading history...
149
        }
150
151
        $string = htmlspecialchars($string, ENT_NOQUOTES, $encoding);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $string. This often makes code more readable.
Loading history...
152
153
        // this call converts all non-ASCII characters into numeirc htmlentities
154
        if (extension_loaded('mbstring') && $original_encoding !== 'ASCII') {
0 ignored issues
show
Coding Style introduced by
$original_encoding does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
155
            $string = mb_encode_numericentity($string, array(0x80, 0xffff, 0, 0xffff), $encoding);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $string. This often makes code more readable.
Loading history...
156
        }
157
158
        return $string;
159
    }
160
}
161