Functions   F
last analyzed

Complexity

Total Complexity 99

Size/Duplication

Total Lines 640
Duplicated Lines 9.84 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 63
loc 640
rs 1.4525
c 0
b 0
f 0
wmc 99
lcom 0
cbo 0

24 Methods

Rating   Name   Duplication   Size   Complexity  
A globRecursive() 0 15 3
A inString() 0 8 4
B findKeyInArray() 0 18 5
A arrayFlatten() 0 9 2
A formatSecondsToShortstring() 0 11 2
A getServerLoad() 0 22 3
A ensurePrefixedWith() 0 12 3
A dropNumericKeys() 0 10 3
A issetOrDefault() 0 4 2
A issetArrayKeyOrDefault() 0 4 2
A toUnderscoredUpperCamelCase() 0 6 1
A cutStringBackwards() 0 10 2
A strReplaceCount() 0 21 3
C arrayCompare() 4 44 11
B arrayUnequalCombine() 0 23 4
A mapArrayKeysToValues() 0 9 2
C distanceOfTimeInWords() 6 55 17
C dateToWord() 10 42 15
A vname() 0 21 4
A removeCommentsFromTemplate() 0 4 1
A shortenString() 0 21 3
A utf8ToHtml() 0 7 1
A __callStatic() 20 20 3
A __call() 23 23 3

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Functions often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Functions, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * Koch Framework
5
 * Jens-André Koch © 2005 - onwards.
6
 *
7
 * This file is part of "Koch Framework".
8
 *
9
 * License: GNU/GPL v2 or any later version, see LICENSE file.
10
 *
11
 * This program is free software; you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation; either version 2 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
namespace Koch\Functions;
26
27
/**
28
 * Koch Framework - Class Library for various static helper Functions.
29
 */
30
class Functions
31
{
32
    /**
33
     * @var array This array contains the names of the loaded functions from directory /core/functions.
34
     */
35
    public static $alreadyLoaded = [];
36
37
    /**
38
     * Recursive glob.
39
     *
40
     * @param string $pattern
41
     * @param int    $flags
42
     *
43
     * @return type
0 ignored issues
show
Documentation introduced by
Should the return type not be array? Also, consider making the array more specific, something like array<String>, or String[].

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

If the return type contains the type array, this check recommends the use of a more specific type like String[] or array<String>.

Loading history...
44
     */
45
    public static function globRecursive($pattern, $flags = 0)
46
    {
47
        $files = glob($pattern, $flags);
48
49
        foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
50
            $files = array_merge($files, self::globRecursive($dir . '/' . basename($pattern), $flags));
51
        }
52
53
        // slash fix
54
        foreach ($files as $key => $value) {
55
            $files[$key] = realpath($value);
56
        }
57
58
        return $files;
59
    }
60
61
    public static function getServerLoad()
62
    {
63
        if (stristr(PHP_OS, 'win')) {
64
            $wmi  = new COM('Winmgmts://');
65
            $cpus = $wmi->execquery('SELECT LoadPercentage FROM Win32_Processor');
66
67
            $cpu_num    = 0;
0 ignored issues
show
Coding Style introduced by
$cpu_num 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...
68
            $load_total = 0;
0 ignored issues
show
Coding Style introduced by
$load_total 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...
69
70
            foreach ($cpus as $cpu) {
71
                ++$cpu_num;
0 ignored issues
show
Coding Style introduced by
$cpu_num 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...
72
                $load_total += $cpu->loadpercentage;
0 ignored issues
show
Coding Style introduced by
$load_total 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...
73
            }
74
75
            $load = round($load_total / $cpu_num);
0 ignored issues
show
Coding Style introduced by
$load_total 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...
76
        } else {
77
            $sys_load = sys_getloadavg();
0 ignored issues
show
Coding Style introduced by
$sys_load 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...
78
            $load     = $sys_load[0];
0 ignored issues
show
Coding Style introduced by
$sys_load 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...
79
        }
80
81
        return (int) $load;
82
    }
83
84
    public static function inString($needle, $haystack, $insensitive = false)
0 ignored issues
show
Coding Style introduced by
function inString() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

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...
85
    {
86
        if ($insensitive === true) {
87
            return (false !== stristr($haystack, $needle)) ? true : false;
88
        } else {
89
            return (false !== strpos($haystack, $needle)) ? true : false;
90
        }
91
    }
92
93
    /**
94
     * Checks a string for a certain prefix or adds it, if missing.
95
     *
96
     * @param string $string
97
     * @param string $prefix
98
     *
99
     * @return string prefixed classname
100
     */
101
    public static function ensurePrefixedWith($string, $prefix)
102
    {
103
        $pos = null;
0 ignored issues
show
Unused Code introduced by
$pos is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
104
105
        $pos = mb_strpos($string, $prefix);
106
107
        if (is_int($pos) && ($pos === 0)) {
108
            return $string;
109
        } else {
110
            return $prefix . $string;
111
        }
112
    }
113
114
    public function dropNumericKeys(array $array)
115
    {
116
        foreach ($array as $key => $value) {
117
            if (is_int($key)) {
118
                unset($array[$key]);
119
            }
120
        }
121
122
        return $array;
123
    }
124
125
    public function issetOrDefault($var, $defaultValue = null)
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...
126
    {
127
        return isset($var) ? $var : $defaultValue;
128
    }
129
130
    public function issetArrayKeyOrDefault(array $array, $key, $defaultValue = null)
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...
131
    {
132
        return isset($array[$key]) ? $array[$key] : $defaultValue;
133
    }
134
135
    /**
136
     * Transforms a string from underscored_lower_case to Underscored_Upper_Camel_Case.
137
     *
138
     * @param string $string String in underscored_lower_case format.
139
     *
140
     * @return $string String in Upper_Camel_Case.
0 ignored issues
show
Documentation introduced by
The doc-type $string could not be parsed: Unknown type name "$string" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
141
     */
142
    public static function toUnderscoredUpperCamelCase($string)
143
    {
144
        $upperCamelCase = str_replace(' ', '_', ucwords(str_replace('_', ' ', strtolower($string))));
145
146
        return $upperCamelCase;
147
    }
148
149
    /**
150
     * cut_string_backwards.
151
     *
152
     * haystack = abc_def
153
     * needle = _def
154
     * result = abc
155
     *
156
     * In PHP6
157
     * abc = $string = mb_strstr('abc_def', '_def');
158
     *
159
     * @param $haystack string
160
     * @param $needle string
161
     *
162
     * @return string
163
     */
164
    public static function cutStringBackwards($haystack, $needle)
165
    {
166
        $needle_length = mb_strlen($needle);
0 ignored issues
show
Coding Style introduced by
$needle_length 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...
167
168
        if (($i = mb_strpos($haystack, $needle) !== false)) {
0 ignored issues
show
Unused Code introduced by
$i is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
169
            return mb_substr($haystack, 0, -$needle_length);
0 ignored issues
show
Coding Style introduced by
$needle_length 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...
170
        }
171
172
        return $haystack;
173
    }
174
175
    /**
176
     * @param string $haystack
177
     * @param string $replace
178
     * @param string $needle
179
     * @param int    $times
180
     *
181
     * @return $needle
0 ignored issues
show
Documentation introduced by
The doc-type $needle could not be parsed: Unknown type name "$needle" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
182
     */
183
    public static function strReplaceCount($haystack, $replace, $needle, $times)
184
    {
185
        $subject_original = $needle;
0 ignored issues
show
Coding Style introduced by
$subject_original 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...
186
        $length           = mb_strlen($haystack);
187
        $pos              = 0;
188
189
        for ($i = 1; $i <= $times; ++$i) {
190
            $pos = mb_strpos($needle, $haystack, $pos);
191
192
            if ($pos !== false) {
193
                $needle = mb_substr($subject_original, 0, $pos);
0 ignored issues
show
Coding Style introduced by
$subject_original 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...
194
                $needle .= $replace;
195
                $needle .= mb_substr($subject_original, $pos + $length);
0 ignored issues
show
Coding Style introduced by
$subject_original 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...
196
                $subject_original = $needle;
0 ignored issues
show
Coding Style introduced by
$subject_original 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...
197
            } else {
198
                break;
199
            }
200
        }
201
202
        return $needle;
203
    }
204
205
    /**
206
     * Takes a needle and multi-dimensional haystack array and does a search on it's values.
207
     *
208
     * @param string $needle   Needle to find
209
     * @param array  $haystack Haystack to look through
210
     * @result array Returns the elements that the $string was found in
211
     *
212
     * array_values_recursive
213
     */
214
    public static function findKeyInArray($needle, array $haystack)
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...
215
    {
216
        // take a look for the needle
217
        if (isset($haystack[$needle]) or array_key_exists($needle, $haystack)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
218
            // if found, return it
219
            return $haystack[$needle];
220
        }
221
222
        // dig a little bit deeper in the array structure
223
        foreach ($haystack as $k => $v) {
224
            if (is_array($v)) {
225
                // recursion
226
                return self::findKeyInArray($needle, $v);
227
            }
228
        }
229
230
        return false;
231
    }
232
233
    /**
234
     * array_compare.
235
     *
236
     * @author  55 dot php at imars dot com
237
     * @author  dwarven dot co dot uk
238
     *
239
     * @link    http://www.php.net/manual/de/function.array-diff-assoc.php#89635
240
     *
241
     * @param $array1
242
     * @param $array2
243
     */
244
    public static function arrayCompare($array1, $array2)
0 ignored issues
show
Coding Style introduced by
function arrayCompare() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

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...
245
    {
246
        $diff = false;
247
248
        // Left-to-right
249
        foreach ($array1 as $key => $value) {
250
            if (array_key_exists($key, $array2) === false) {
251
                $diff[0][$key] = $value;
252
            } elseif (is_array($value)) {
253
                if (is_array($array2[$key]) === false) {
254
                    $diff[0][$key] = $value;
255
                    $diff[1][$key] = $array2[$key];
256
                } else {
257
                    $new = self::array_compare($value, $array2[$key]);
258
259
                    if ($new !== false) {
260 View Code Duplication
                        if ($new[0] !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
261
                            $diff[0][$key] = $new[0];
262
                        }
263 View Code Duplication
                        if ($new[1] !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
264
                            $diff[1][$key] = $new[1];
265
                        }
266
                    }
267
                }
268
            } elseif ($array2[$key] !== $value) {
269
                $diff[0][$key] = $value;
270
                $diff[1][$key] = $array2[$key];
271
            }
272
        }
273
274
        // Right-to-left
275
        foreach ($array2 as $key => $value) {
276
            if (array_key_exists($key, $array1) === false) {
277
                $diff[1][$key] = $value;
278
            }
279
280
            /*
281
             * No direct comparsion because matching keys were compared in the
282
             * left-to-right loop earlier, recursively.
283
             */
284
        }
285
286
        return $diff;
287
    }
288
289
    /**
290
     * Combines two arrays by using $keyArray as key providing array
291
     * an $valueArray as value providing array.
292
     * In case the valueArray is greater than the keyArray,
293
     * the keyArray determines the maximum number of values returned.
294
     * In case the valueArray is smaller than the keyArray,
295
     * those keys are returned for which values exist.
296
     *
297
     * @example
298
     * $keys = array('mod', 'sub', 'action', 'id');
299
     * $values = array('news', 'admin');
300
     * $combined = self::array_unequal_combine($keys, $values);
301
     * Results in: array('mod'=>'news', 'sub'=>'admin');
302
     *
303
     * @param array $keyArray
304
     * @param array $valueArray
305
     *
306
     * @return array Combined Array
307
     */
308
    public static function arrayUnequalCombine($keyArray, $valueArray)
309
    {
310
        $returnArray = [];
311
        $key         = '';
312
        $index       = 0;
313
314
        // more keys than values, reduce keys array
315
        while (count($keyArray) > count($valueArray)) {
316
            array_pop($keyArray);
317
        }
318
319
        // @todo more values than keys ?
320
        // add pseudo keys a la "key-0"
321
322
        foreach ($keyArray as $key) {
323
            if ($valueArray[$index] !== null) {
324
                // index is used, then incremented for the next turn in foreach (post-increment-operator)
325
                $returnArray[$key] = $valueArray[$index++];
326
            }
327
        }
328
329
        return $returnArray;
330
    }
331
332
    /**
333
     * Remaps multi-dim array (k1=>v1, k2=>v2, k(n) => v(n)) to the values of key1=>key2 (v1 => v2).
334
     * The array might have several keys, so you might map value of key2 to value of key5 ;)
335
     * Simple, but impressive!
336
     *
337
     * @param type $array
338
     * @param type $map_value_of_key1
339
     * @param type $to_value_of_key2
340
     *
341
     * @return type array
0 ignored issues
show
Documentation introduced by
Should the return type not be array? Also, consider making the array more specific, something like array<String>, or String[].

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

If the return type contains the type array, this check recommends the use of a more specific type like String[] or array<String>.

Loading history...
342
     */
343
    public static function mapArrayKeysToValues($array, $map_value_of_key1, $to_value_of_key2)
0 ignored issues
show
Coding Style introduced by
$map_value_of_key1 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...
344
    {
345
        $new_array = [];
0 ignored issues
show
Coding Style introduced by
$new_array 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...
346
        foreach ($array as $inner_array) {
0 ignored issues
show
Coding Style introduced by
$inner_array 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...
347
            $new_array[$inner_array[$map_value_of_key1]] = $inner_array[$to_value_of_key2];
0 ignored issues
show
Coding Style introduced by
$new_array 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...
348
        }
349
350
        return $new_array;
0 ignored issues
show
Coding Style introduced by
$new_array 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...
351
    }
352
353
    /**
354
     * flatten multi-dimensional array.
355
     *
356
     * @param array $array
357
     *
358
     * @return array
359
     */
360
    public static function arrayFlatten(array $array)
361
    {
362
        $flatened_array = [];
0 ignored issues
show
Coding Style introduced by
$flatened_array 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...
363
        foreach (new \RecursiveIteratorIterator(new \RecursiveArrayIterator($array)) as $value) {
364
            $flatened_array[] = $value;
0 ignored issues
show
Coding Style introduced by
$flatened_array 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...
365
        }
366
367
        return $flatened_array;
0 ignored issues
show
Coding Style introduced by
$flatened_array 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...
368
    }
369
370
    /**
371
     * distanceOfTimeInWords.
372
     *
373
     * @author: anon
374
     * @link: http://www.php.net/manual/de/function.time.php#85481
375
     *
376
     * @param int $fromTime starttime
377
     * @param $toTime endtime
378
     * @param $showLessThanAMinute boolean
379
     *
380
     * @return string
381
     */
382
    public static function distanceOfTimeInWords($fromTime, $toTime = 0, $showLessThanAMinute = false)
383
    {
384
        $distanceInSeconds = round(abs($toTime - $fromTime));
385
        $distanceInMinutes = round($distanceInSeconds / 60);
386
387
        if ($distanceInMinutes <= 1) {
388
            if ($showLessThanAMinute === false) {
389
                return ($distanceInMinutes === 0) ? 'less than a minute' : '1 minute';
390
            } else {
391
                if ($distanceInSeconds < 5) {
392
                    return 'less than 5 seconds';
393
                }
394
                if ($distanceInSeconds < 10) {
395
                    return 'less than 10 seconds';
396
                }
397
                if ($distanceInSeconds < 20) {
398
                    return 'less than 20 seconds';
399
                }
400
                if ($distanceInSeconds < 40) {
401
                    return 'about half a minute';
402
                }
403
                if ($distanceInSeconds < 60) {
404
                    return 'less than a minute';
405
                }
406
407
                return '1 minute';
408
            }
409
        }
410
        if ($distanceInMinutes < 45) {
411
            return $distanceInMinutes . ' minutes';
412
        }
413
        if ($distanceInMinutes < 90) {
414
            return 'about 1 hour';
415
        }
416 View Code Duplication
        if ($distanceInMinutes < 1440) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
417
            return 'about ' . round(floatval($distanceInMinutes) / 60.0) . ' hours';
418
        }
419
        if ($distanceInMinutes < 2880) {
420
            return '1 day';
421
        }
422 View Code Duplication
        if ($distanceInMinutes < 43200) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
423
            return 'about ' . round(floatval($distanceInMinutes) / 1440) . ' days';
424
        }
425
        if ($distanceInMinutes < 86400) {
426
            return 'about 1 month';
427
        }
428
        if ($distanceInMinutes < 525600) {
429
            return round(floatval($distanceInMinutes) / 43200) . ' months';
430
        }
431
        if ($distanceInMinutes < 1051199) {
432
            return 'about 1 year';
433
        }
434
435
        return 'over ' . round(floatval($distanceInMinutes) / 525600) . ' years';
436
    }
437
438
    /**
439
     * Performs a dateToWord transformation via gettext.
440
     * uses idate() to format a local time/date as integer and gettext functions _n(), _t().
441
     *
442
     * @see http://www.php.net/idate
443
     *
444
     * @param string $from
445
     * @param string $now
0 ignored issues
show
Documentation introduced by
Should the type for parameter $now not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
446
     *
447
     * @return string Word representation of
448
     */
449
    public static function dateToWord($from, $now = null)
450
    {
451
        if ($now === null) {
452
            $now = time();
453
        }
454
455
        $between = $now - $from;
456
457
        if ($between < 86400 and idate('d', $from) === idate('d', $now)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
458
            if ($between < 3600 and idate('H', $from) === idate('H', $now)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
459 View Code Duplication
                if ($between < 60 and idate('i', $from) === idate('i', $now)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
460
                    $second = idate('s', $now) - idate('s', $from);
461
462
                    return sprintf(_n('%d', '%d', $second), $second);
463
                }
464
465
                $min = idate('i', $now) - idate('i', $from);
466
467
                return sprintf(_n('%d', '%d', $min), $min);
468
            }
469
470
            $hour = idate('H', $now) - idate('H', $from);
471
472
            return sprintf(_n('%d', '%d', $hour), $hour);
473
        }
474
475
        if ($between < 172800 && (idate('z', $from) + 1 === idate('z', $now) or idate('z', $from) > 2 + idate('z', $now))) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
476
            return _t('.. %s', date('H:i', $from));
477
        }
478
479 View Code Duplication
        if ($between < 604800 and idate('W', $from) === idate('W', $now)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
480
            $day = intval($between / (3600 * 24));
481
482
            return sprintf(_n('...', '...', $day), $day);
483
        }
484
485
        if ($between < 31622400 and idate('Y', $from) === idate('Y', $now)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
486
            return date(_t('...'), $from);
487
        }
488
489
        return date(_t('...'), $from);
490
    }
491
492
    /**
493
     * Get the variable name as string.
494
     *
495
     * @author http://us2.php.net/manual/en/language.variables.php#76245
496
     *
497
     * @param $var variable as reference
498
     * @param $scope scope
499
     *
500
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|string|false?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
501
     */
502
    public static function vname($var, $scope = false, $prefix = 'unique', $suffix = 'value')
503
    {
504
        $values = '';
505
506
        if ($scope === true) {
507
            $values = $scope;
508
        }
509
510
        $old   = $var;
511
        $var   = $new   = $prefix . rand() . $suffix;
0 ignored issues
show
Unused Code introduced by
$var is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
512
        $vname = false;
513
514
        foreach ($values as $key => $val) {
0 ignored issues
show
Bug introduced by
The expression $values of type boolean|string is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
515
            if ($val === $new) {
516
                $vname = $key;
517
            }
518
        }
519
        $var = $old;
0 ignored issues
show
Unused Code introduced by
$var is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
520
521
        return $vname;
522
    }
523
524
    /**
525
     * format_seconds_to_shortstring.
526
     *
527
     * @param $seconds int
528
     *
529
     * @return string Ouput: 4D 10:12:20
530
     */
531
    public static function formatSecondsToShortstring($seconds = 0)
532
    {
533
        $time = '';
0 ignored issues
show
Unused Code introduced by
$time is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
534
        if ($seconds !== null) {
535
            $time = sprintf('%dD %02d:%02d:%02dh', $seconds / 60 / 60 / 24, ($seconds / 60 / 60) % 24, ($seconds / 60) % 60, $seconds % 60);
536
        } else {
537
            return '00:00:00';
538
        }
539
540
        return $time;
541
    }
542
543
    /**
544
     * Remove comments prefilter.
545
     *
546
     * @param $html A String with HTML Comments.
547
     *
548
     * @return string $html String without Comments.
549
     */
550
    public function removeCommentsFromTemplate($html)
551
    {
552
        return preg_replace('/<!--.*-->/U', '', $html);
553
    }
554
555
    /**
556
     * @param string $string
557
     */
558
    public static function shortenString($string, $maxlength = 50, $append_string = '[...]')
0 ignored issues
show
Coding Style introduced by
$append_string 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...
559
    {
560
        // already way too short...
561
        if (mb_strlen($string) < $maxlength) {
562
            return $string;
563
        }
564
565
        // ok, lets shorten
566
        if (mb_strlen($string) > $maxlength) {
567
            /*
568
             * do not short the string, when maxlength would split a word!
569
             * that would make things unreadable.
570
             * so search for the next space after the requested maxlength.
571
             */
572
            $next_space_after_maxlength = mb_strpos($string, ' ', $maxlength);
0 ignored issues
show
Coding Style introduced by
$next_space_after_maxlength 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...
573
574
            $shortened_string = mb_substr($string, 0, $next_space_after_maxlength);
0 ignored issues
show
Coding Style introduced by
$shortened_string 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...
575
576
            return $shortened_string . $append_string;
0 ignored issues
show
Coding Style introduced by
$shortened_string 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...
577
        }
578
    }
579
580
    /**
581
     * Converts a UTF8-string into HTML entities.
582
     *
583
     * When using UTF-8 as a charset you want to convert multi-byte characters.
584
     * This function takes multi-byte characters up to level 4 into account.
585
     * Htmlentities will only convert 1-byte and 2-byte characters.
586
     * Use this function if you want to convert 3-byte and 4-byte characters also.
587
     *
588
     * @author silverbeat gmx  at
589
     *
590
     * @link http://www.php.net/manual/de/function.htmlentities.php#96648
591
     *
592
     * @param $utf8 string The UTF8-string to convert
593
     * @param $encodeTags booloean TRUE will convert "<" to "&lt;", Default = false
594
     *
595
     * @return string the converted HTML-string
596
     */
597
    public static function utf8ToHtml($utf8, $encodeTags = false)
598
    {
599
        include_once __DIR__ . '/Pool/UTF8_to_HTML.php';
600
601
        // calling the loaded function
602
        return UTF8_to_HTML($utf8, $encodeTags);
603
    }
604
605
    /**
606
     * The Magic Call __callStatic() is triggered when invoking inaccessible methods in a static context.
607
     * Method overloading.
608
     * Available from PHP 5.3 onwards.
609
     *
610
     * @param $name string The $name argument is the name of the method being called.
611
     * @param $arguments arra The $arguments argument is an enumerated array containing the parameters passed to the $name'ed method.
612
     */
613 View Code Duplication
    public static function __callStatic($method, $arguments)
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...
614
    {
615
        // Debug message for Method Overloading
616
        // Making it easier to see which static method is called magically
617
        //\Koch\Debug\Debug::firebug('DEBUG (Overloading): Calling static method "'.$method.'" '. implode(', ', $arguments). "\n");
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
618
        // construct the filename of the command
619
        $filename = __DIR__ . '/Pool/' . $method . '.php';
620
621
        // check if name is valid
622
        if (is_file($filename) && is_readable($filename)) {
623
            // dynamically include the command
624
            include_once $filename;
625
626
            return call_user_func_array($method, $arguments);
627
        } else {
628
            throw new \RuntimeException(
629
                sprintf('Koch Framework Function not found: "%s".', $filename)
630
            );
631
        }
632
    }
633
634
    /**
635
     * The Magic Call __call() is triggered when invoking inaccessible methods in an object context.
636
     * Method overloading.
637
     *
638
     * This method takes care of loading the function command files.
639
     *
640
     * This means that a currently non-existing methods or properties of this class are dynamically "created".
641
     * Overloading methods are always in the "public" scope.
642
     *
643
     * @param $name string The $name argument is the name of the method being called.
644
     * @param $arguments array The $arguments  argument is an enumerated array containing the parameters passed to the $name'ed method.
645
     */
646 View Code Duplication
    public function __call($method, $arguments)
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...
647
    {
648
        // Because value of $name is case sensitive, its forced to be lowercase.
649
        $method = mb_strtolower($method);
650
651
        // Debug message for Method Overloading
652
        // Making it easier to see which method is called magically
653
        // \Koch\Debug\Debug::fbg('DEBUG (Overloading): Calling object method "'.$method.'" '. implode(', ', $arguments). "\n");
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
654
        // construct the filename of the command
655
        $filename = __DIR__ . '/pool/' . $method . '.php';
656
657
        // check if name is valid
658
        if (is_file($filename) && is_readable($filename)) {
659
            // dynamically include the command
660
            include_once $filename;
661
662
            return call_user_func_array($method, $arguments);
663
        } else {
664
            throw new \RuntimeException(
665
                sprintf('Koch Framework Function not found: "%s".', $filename)
666
            );
667
        }
668
    }
669
}
670