1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Automation tool mixed with code generator for easier continuous development |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hidev |
6
|
|
|
* @package hidev |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2018, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hidev\helpers; |
12
|
|
|
|
13
|
|
|
use hiqdev\php\collection\ArrayHelper; |
14
|
|
|
use Yii; |
15
|
|
|
use yii\helpers\Inflector; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Hidev Helper. |
19
|
|
|
*/ |
20
|
|
|
class Helper |
21
|
|
|
{ |
22
|
3 |
|
public static function isYii20() |
23
|
|
|
{ |
24
|
3 |
|
return method_exists(Yii::class, 'autoload'); |
25
|
|
|
} |
26
|
|
|
|
27
|
4 |
|
public static function bad2sep($str, $separator = '-') |
28
|
|
|
{ |
29
|
4 |
|
return preg_replace('/[^a-zA-Z0-9-]/', $separator, $str); |
30
|
|
|
} |
31
|
|
|
|
32
|
4 |
|
public static function id2camel($id, $separator = '-') |
33
|
|
|
{ |
34
|
4 |
|
return Inflector::id2camel(self::bad2sep($id, $separator), $separator); |
35
|
|
|
//return Inflector::id2camel(strtolower(self::bad2sep($id,$separator)), $separator); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
1 |
|
public static function camel2id($name, $separator = '-', $strict = false) |
39
|
|
|
{ |
40
|
1 |
|
return str_replace('--', '-', Inflector::camel2id(str_replace(' ', '', ucwords($name)), $separator, $strict)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public static function file2template($file, $separator = '-') |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
return trim($file, '.'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
View Code Duplication |
public static function csplit($input, $delimiter = ',') |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
if (is_array($input)) { |
51
|
|
|
return $input; |
52
|
|
|
} |
53
|
|
|
$res = explode($delimiter, $input); |
54
|
|
|
|
55
|
|
|
return array_values(array_filter(array_map('trim', $res))); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
View Code Duplication |
public static function asplit($input) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
if (is_array($input)) { |
61
|
|
|
return $input; |
62
|
|
|
} |
63
|
|
|
$res = preg_split('/[\s,]+/', $input); |
64
|
|
|
|
65
|
|
|
return array_values(array_filter(array_map('trim', $res))); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public static function ksplit($input, $delimiter = ',') |
69
|
|
|
{ |
70
|
|
|
if (is_array($input)) { |
71
|
|
|
return $input; |
72
|
|
|
} |
73
|
|
|
$res = self::csplit($input, $delimiter); |
74
|
|
|
|
75
|
|
|
return array_combine($res, $res); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public static function getPublicVars($subj) |
79
|
|
|
{ |
80
|
|
|
return is_object($subj) ? get_object_vars($subj) : get_class_vars($subj); |
81
|
|
|
} |
82
|
|
|
|
83
|
2 |
|
public static function titleize($str, $ucAll = true) |
84
|
|
|
{ |
85
|
2 |
|
return Inflector::titleize(strtr($str, '-', ' '), $ucAll); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Recursively removes duplicate values from non-associative arrays. |
90
|
|
|
*/ |
91
|
|
|
public static function uniqueConfig($array) |
92
|
|
|
{ |
93
|
|
|
return ArrayHelper::unique($array); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
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.