Completed
Push — master ( ff6e90...57ee5c )
by Andrii
03:56
created

Helper::id2camel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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);
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% 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...
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 = '-')
0 ignored issues
show
Unused Code introduced by
The parameter $separator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

43
    public static function file2template($file, /** @scrutinizer ignore-unused */ $separator = '-')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
    {
45
        return trim($file, '.');
46
    }
47
48
    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
    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)));
0 ignored issues
show
Bug introduced by
It seems like $res can also be of type false; however, parameter $arr1 of array_map() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
        return array_values(array_filter(array_map('trim', /** @scrutinizer ignore-type */ $res)));
Loading history...
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
    public static function readline($prompt)
97
    {
98
        return readline($prompt);
99
    }
100
101
    public static function readpassword($prompt)
102
    {
103
        echo $prompt;
104
        system('stty -echo');
105
        $password = rtrim(fgets(STDIN), PHP_EOL);
106
        system('stty echo');
107
        echo "\n";
108
109
        return $password;
110
    }
111
112
    /**
113
     * Is response Ok.
114
     * @param Response|int $response
0 ignored issues
show
Bug introduced by
The type hidev\helpers\Response was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
115
     * @return bool
116
     */
117
    public static function isResponseOk($response)
118
    {
119
        return !(is_object($response) ? $response->exitStatus : $response);
120
    }
121
}
122