Completed
Push — master ( 2d3cdd...c9e6e0 )
by Babak
04:15
created

StringHelper::plural()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: alive
5
 * Date: 9/28/17
6
 * Time: 12:35 PM
7
 */
8
9
namespace Alive2212\LaravelStringHelper;
10
11
class StringHelper
12
{
13
    /**
14
     * upper letters
15
     *
16
     * @var string
17
     */
18
    protected $upperLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
19
20
21
    public function plural($value)
0 ignored issues
show
Unused Code introduced by
The parameter $value 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...
22
    {
23
        // TODO must be implementing
24
    }
25
26
    /**
27
     * @param $string
28
     * @param string $separator
29
     * @return mixed
30
     */
31 1
    public function toTag($string, $separator = '_')
32
    {
33 1
        $string[0] = strtolower($string[0]);
34 1
        foreach (str_split($this->upperLetters) as $upperLetter) {
35 1
            $string = str_replace($upperLetter, $separator . strtolower($upperLetter), $string);
36
        }
37 1
        return $string;
38
    }
39
40
    /**
41
     * @param $string
42
     * @return mixed
43
     */
44 1
    public function upperFirstLetter($string)
45
    {
46 1
        $string[0] = strtoupper($string[0]);
47 1
        return $string;
48
    }
49
50
    /**
51
     * @param $string
52
     * @return mixed
53
     */
54 1
    public function lowerFirstLetter($string)
55
    {
56 1
        $string[0] = strtolower($string[0]);
57 1
        return $string;
58
    }
59
60
    /**
61
     * @param $string
62
     * @return mixed
63
     */
64 1 View Code Duplication
    public function toCamel($string)
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...
65
    {
66 1
        $stringArray = explode('_', $string);
67 1
        for ($i = 1; $i < count($stringArray);$i++){
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
68 1
            $stringArray[$i] = $this->upperFirstLetter($stringArray[$i]);
69
        }
70 1
        return implode('', $stringArray);
71
    }
72
73
    /**
74
     * @param $string
75
     * @return mixed
76
     */
77 1 View Code Duplication
    public function toPascal($string)
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...
78
    {
79 1
        $stringArray = explode('_', $string);
80 1
        for ($i = 0; $i < count($stringArray);$i++){
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
81 1
            $stringArray[$i] = $this->upperFirstLetter($stringArray[$i]);
82
        }
83 1
        return implode('', $stringArray);
84
    }
85
}