Completed
Push — master ( 2318a0...fcaf59 )
by Andrii
06:08
created

Helper   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 71
Duplicated Lines 25.35 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 6.9%
Metric Value
wmc 14
lcom 0
cbo 2
dl 18
loc 71
ccs 2
cts 29
cp 0.069
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A bad2sep() 0 4 1
A id2camel() 0 5 1
A camel2id() 0 4 1
A file2template() 0 4 1
A csplit() 9 9 2
A asplit() 9 9 2
A ksplit() 0 9 2
A getPublicVars() 0 4 2
A titleize() 0 4 1
A uniqueConfig() 0 4 1

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
/*
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 = '-')
0 ignored issues
show
Unused Code introduced by
The parameter $separator is not used and could be removed.

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

Loading history...
39
    {
40 1
        return trim($file, '.');
41
    }
42
43 View Code Duplication
    public static function csplit($input, $delimiter = ',')
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...
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)
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...
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