KintBootup   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 261
Duplicated Lines 6.9 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 18
loc 261
ccs 0
cts 88
cp 0
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 1

12 Methods

Rating   Name   Duplication   Size   Complexity  
A hp ➔ d() 0 4 1
A hp ➔ dd() 9 9 2
A hp ➔ ddd() 9 9 2
A hp ➔ de() 0 9 1
B hp ➔ s() 0 21 5
B hp ➔ sd() 0 16 5
B hp ➔ se() 0 23 5
A hp ➔ j() 0 18 4
A hp ➔ jd() 0 14 4
A hp ➔ je() 0 20 4
B init() 0 23 5
B initFunctions() 18 230 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace kint;
4
5
/**
6
 * Class KintBootup
7
 *
8
 * @package kint
9
 */
10
class KintBootup
11
{
12
  /**
13
   * init
14
   */
15
  public static function init()
0 ignored issues
show
Coding Style introduced by
init uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
16
  {
17
    if (defined('KINT_DIR')) {
18
      return;
19
    }
20
21
    define('KINT_DIR', __DIR__ . '/');
22
23
    require KINT_DIR . 'config.default.php';
24
25
    # init settings
26
    if (!empty($GLOBALS['_kint_settings'])) {
27
      Kint::enabled($GLOBALS['_kint_settings']['enabled']);
28
29
      foreach ($GLOBALS['_kint_settings'] as $key => $val) {
30
        if (property_exists('Kint', $key)) {
31
          Kint::$$key = $val;
32
        }
33
      }
34
35
      unset($GLOBALS['_kint_settings'], $key, $val);
36
    }
37
  }
38
39
  public static function initFunctions()
40
  {
41
    /**
42
     * Alias of Kint::dump()
43
     *
44
     * @return string
45
     */
46
    function d()
47
    {
48
      return call_user_func_array(array('kint\Kint', 'dump'), func_get_args());
49
    }
50
51
52
    /**
53
     * Alias of Kint::dump()
54
     * [!!!] IMPORTANT: execution will halt after call to this function
55
     *
56
     * @return string
57
     */
58 View Code Duplication
    function dd()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This function 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...
59
    {
60
      if (!Kint::enabled()) {
61
        return '';
62
      }
63
64
      call_user_func_array(array('kint\Kint', 'dump'), func_get_args());
65
      exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function dd() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
66
    }
67
68
    /**
69
     * Alias of Kint::dump()
70
     * [!!!] IMPORTANT: execution will halt after call to this function
71
     *
72
     * @return string
73
     */
74 View Code Duplication
    function ddd()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This function 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...
75
    {
76
      if (!Kint::enabled()) {
77
        return '';
78
      }
79
80
      call_user_func_array(array('kint\Kint', 'dump'), func_get_args());
81
      exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function ddd() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
82
    }
83
84
    /**
85
     * Alias of Kint::dump(), however the output is delayed until the end of the script
86
     *
87
     * @see d();
88
     *
89
     * @return string
90
     */
91
    function de()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
92
    {
93
      $stash = Kint::settings();
94
      Kint::$delayedMode = true;
95
      $out = call_user_func_array(array('kint\Kint', 'dump'), func_get_args());
96
      Kint::settings($stash);
97
98
      return $out;
99
    }
100
101
    /**
102
     * Alias of Kint::dump(), however the output is in plain html-escaped text and some minor visibility enhancements
103
     * added. If run in CLI mode, output is pure whitespace.
104
     *
105
     * To force rendering mode without auto-detecting anything:
106
     *
107
     *  Kint::enabled( Kint::MODE_PLAIN );
108
     *  Kint::dump( $variable );
109
     *
110
     * [!!!] IMPORTANT: execution will halt after call to this function
111
     *
112
     * @return string
113
     */
114
    function s()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
115
    {
116
      if (!Kint::enabled()) {
117
        return '';
118
      }
119
120
      $stash = Kint::settings();
121
122
      if (Kint::enabled() !== Kint::MODE_WHITESPACE) {
123
        Kint::enabled(Kint::MODE_PLAIN);
124
        if (PHP_SAPI === 'cli' && Kint::$cliDetection === true) {
125
          Kint::enabled(Kint::MODE_CLI);
126
        }
127
      }
128
129
      $out = call_user_func_array(array('kint\Kint', 'dump'), func_get_args());
130
131
      Kint::settings($stash);
132
133
      return $out;
134
    }
135
136
    /**
137
     * @see s()
138
     *
139
     * [!!!] IMPORTANT: execution will halt after call to this function
140
     *
141
     * @return string
142
     */
143
    function sd()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
144
    {
145
      if (!Kint::enabled()) {
146
        return '';
147
      }
148
149
      if (Kint::enabled() !== Kint::MODE_WHITESPACE) {
150
        Kint::enabled(Kint::MODE_PLAIN);
151
        if (PHP_SAPI === 'cli' && Kint::$cliDetection === true) {
152
          Kint::enabled(Kint::MODE_CLI);
153
        }
154
      }
155
156
      call_user_func_array(array('kint\Kint', 'dump'), func_get_args());
157
      exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function sd() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
158
    }
159
160
    /**
161
     * @see s()
162
     * @see de()
163
     *
164
     * @return string
165
     */
166
    function se()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
167
    {
168
      if (!Kint::enabled()) {
169
        return '';
170
      }
171
172
      $stash = Kint::settings();
173
174
      Kint::$delayedMode = true;
175
176
      if (Kint::enabled() !== Kint::MODE_WHITESPACE) {
177
        Kint::enabled(Kint::MODE_PLAIN);
178
        if (PHP_SAPI === 'cli' && Kint::$cliDetection === true) {
179
          Kint::enabled(Kint::MODE_CLI);
180
        }
181
      }
182
183
      $out = call_user_func_array(array('kint\Kint', 'dump'), func_get_args());
184
185
      Kint::settings($stash);
186
187
      return $out;
188
    }
189
190
    /**
191
     * Alias of Kint::dump(), however the output is dumped to the javascript console and
192
     * added to the global array `kintDump`. If run in CLI mode, output is pure whitespace.
193
     *
194
     * To force rendering mode without autodetecting anything:
195
     *
196
     *  Kint::enabled( Kint::MODE_JS );
197
     *  Kint::dump( $variable );
198
     *
199
     * @return string
200
     */
201
    function j()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
202
    {
203
      if (!Kint::enabled()) {
204
        return '';
205
      }
206
207
      $stash = Kint::settings();
208
209
      Kint::enabled(
210
          PHP_SAPI === 'cli' && Kint::$cliDetection === true ? Kint::MODE_CLI : Kint::MODE_JS
211
      );
212
213
      $out = call_user_func_array(array('kint\Kint', 'dump'), func_get_args());
214
215
      Kint::settings($stash);
216
217
      return $out;
218
    }
219
220
    /**
221
     * @see j()
222
     *
223
     * [!!!] IMPORTANT: execution will halt after call to this function
224
     *
225
     * @return string
226
     */
227
    function jd()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
228
    {
229
      if (!Kint::enabled()) {
230
        return '';
231
      }
232
233
      Kint::enabled(
234
          PHP_SAPI === 'cli' && Kint::$cliDetection === true ? Kint::MODE_CLI : Kint::MODE_JS
235
      );
236
237
      call_user_func_array(array('kint\Kint', 'dump'), func_get_args());
238
239
      exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function jd() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
240
    }
241
242
    /**
243
     * @see j()
244
     * @see de()
245
     *
246
     * @return string
247
     */
248
    function je()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
249
    {
250
      if (!Kint::enabled()) {
251
        return '';
252
      }
253
254
      $stash = Kint::settings();
255
256
      Kint::$delayedMode = true;
257
258
      Kint::enabled(
259
          PHP_SAPI === 'cli' && Kint::$cliDetection === true ? Kint::MODE_CLI : Kint::MODE_JS
260
      );
261
262
      $out = call_user_func_array(array('kint\Kint', 'dump'), func_get_args());
263
264
      Kint::settings($stash);
265
266
      return $out;
267
    }
268
  }
269
270
}
271