Kint_Renderer_Plain::escape()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 21
Code Lines 10

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
cc 6
eloc 10
nc 8
nop 2
dl 21
loc 21
rs 8.7624
c 0
b 0
f 0
1
<?php
2
3
class Kint_Renderer_Plain extends Kint_Renderer_Text
0 ignored issues
show
Coding Style introduced by
Kint_Renderer_Plain 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...
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...
Coding Style introduced by
The property $mod_return 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 $file_link_format 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...
4
{
5
    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...
6
        'script' => array(),
7
        'style' => array(
8
            array('Kint_Renderer_Plain', 'renderCss'),
9
        ),
10
        'raw' => array(),
11
    );
12
13
    /**
14
     * Path to the CSS file to load by default.
15
     *
16
     * @var string
17
     */
18
    public static $theme = 'plain.css';
19
20
    /**
21
     * Output htmlentities instead of utf8.
22
     *
23
     * @var bool
24
     */
25
    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...
26
27
    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...
28
29
    protected $mod_return = false;
0 ignored issues
show
Coding Style introduced by
$mod_return 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...
30
    protected $file_link_format = false;
0 ignored issues
show
Coding Style introduced by
$file_link_format 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...
31
32
    public function __construct(array $params = array())
33
    {
34
        parent::__construct($params);
35
36
        if (isset($params['settings']['return'])) {
37
            $this->mod_return = $params['settings']['return'];
38
        }
39
40
        if (isset($params['settings']['file_link_format'])) {
41
            $this->file_link_format = $params['settings']['file_link_format'];
42
        }
43
    }
44
45 View Code Duplication
    protected function utf8_to_htmlentity($string)
0 ignored issues
show
Coding Style introduced by
function utf8_to_htmlentity() 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...
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...
46
    {
47
        return str_replace(
48
            array('┌', '═', '┐', '│', '└', '─', '┘'),
49
            array('&#9484;', '&#9552;', '&#9488;', '&#9474;', '&#9492;', '&#9472;', '&#9496;'),
50
            $string
51
        );
52
    }
53
54
    public function colorValue($string)
55
    {
56
        return '<i>'.$string.'</i>';
57
    }
58
59
    public function colorType($string)
60
    {
61
        return '<b>'.$string.'</b>';
62
    }
63
64
    public function colorTitle($string)
65
    {
66
        return '<u>'.$string.'</u>';
67
    }
68
69
    public function renderTitle(Kint_Object $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...
70
    {
71
        if (self::$disable_utf8) {
72
            return $this->utf8_to_htmlentity(parent::renderTitle($o));
73
        } else {
74
            return parent::renderTitle($o);
75
        }
76
    }
77
78 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...
79
    {
80
        if (file_exists(KINT_DIR.'/resources/compiled/'.self::$theme)) {
81
            return file_get_contents(KINT_DIR.'/resources/compiled/'.self::$theme);
82
        } else {
83
            return file_get_contents(self::$theme);
84
        }
85
    }
86
87 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...
88
    {
89
        $output = '';
90
91
        if (!self::$been_run || $this->mod_return) {
92
            foreach (self::$pre_render_sources as $type => $values) {
93
                $contents = '';
94
                foreach ($values as $v) {
95
                    if (is_callable($v)) {
96
                        $contents .= call_user_func($v, $this);
97
                    } elseif (is_string($v)) {
98
                        $contents .= $v;
99
                    }
100
                }
101
102
                if (!strlen($contents)) {
103
                    continue;
104
                }
105
106
                switch ($type) {
107
                    case 'script':
108
                        $output .= '<script class="kint-script">'.$contents.'</script>';
109
                        break;
110
                    case 'style':
111
                        $output .= '<style class="kint-style">'.$contents.'</style>';
112
                        break;
113
                    default:
114
                        $output .= $contents;
115
                }
116
            }
117
118
            if (!$this->mod_return) {
119
                self::$been_run = true;
120
            }
121
        }
122
123
        return $output.'<div class="kint-plain">';
124
    }
125
126
    public function postRender()
127
    {
128
        if (self::$disable_utf8) {
129
            return $this->utf8_to_htmlentity(parent::postRender()).'</div>';
130
        } else {
131
            return parent::postRender().'</div>';
132
        }
133
    }
134
135 View Code Duplication
    public function ideLink($file, $line)
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...
136
    {
137
        $shortenedPath = $this->escape(Kint::shortenPath($file));
138
        if (!$this->file_link_format) {
139
            return $shortenedPath.':'.$line;
140
        }
141
142
        $ideLink = Kint::getIdeLink($file, $line);
143
        $class = (strpos($ideLink, 'http://') === 0) ? 'class="kint-ide-link" ' : '';
144
145
        return "<a {$class}href=\"{$ideLink}\">{$shortenedPath}:{$line}</a>";
146
    }
147
148 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...
149
    {
150
        if ($encoding === false) {
151
            $encoding = Kint_Object_Blob::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...
152
        }
153
154
        $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...
155
156
        if ($encoding === false || $encoding === 'ASCII') {
157
            $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...
158
        }
159
160
        $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...
161
162
        // this call converts all non-ASCII characters into numeirc htmlentities
163
        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...
164
            $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...
165
        }
166
167
        return $string;
168
    }
169
}
170