Completed
Push — master ( 43ed69...84af45 )
by Andrii
06:07
created

src/helpers/Helper.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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