1 | <?php |
||
5 | class Randstring |
||
6 | { |
||
7 | public $combinations = []; |
||
8 | public $adjective; |
||
9 | public $animal; |
||
10 | public $number; |
||
11 | private $adjectives; |
||
12 | private $animals; |
||
13 | private $min; |
||
14 | private $max; |
||
15 | private $case; |
||
16 | private $maxLength; |
||
17 | private $string; |
||
18 | private $first; |
||
19 | private $second; |
||
20 | |||
21 | /** |
||
22 | * Randstring constructor. |
||
23 | * |
||
24 | * @param null $case (ucwords, ucfirst|sentence, camel) |
||
25 | * @param int $maxLength |
||
26 | * @param int $min |
||
27 | * @param int $max |
||
28 | */ |
||
29 | public function __construct($case = null, $maxLength = 100, $min = 1, $max = 99) |
||
38 | |||
39 | /** |
||
40 | * @return mixed |
||
41 | */ |
||
42 | public function generate() |
||
51 | |||
52 | /** |
||
53 | * Generate a string. |
||
54 | */ |
||
55 | private function generateString() |
||
56 | { |
||
57 | $this->generateNumbers(); |
||
58 | $this->adjective = $this->adjectives[$this->first]; |
||
59 | $this->animal = $this->animals[$this->second]; |
||
60 | switch ($this->case) { |
||
61 | case 'ucfirst': |
||
|
|||
62 | $this->string = ucfirst($this->adjective . $this->animal . $this->number); |
||
63 | break; |
||
64 | case 'ucwords': |
||
65 | case 'sentence': |
||
66 | $this->string = ucfirst($this->adjective) . ucfirst($this->animal) . ucfirst($this->number); |
||
67 | break; |
||
68 | case 'camel': |
||
69 | $this->string = $this->adjective . ucfirst($this->animal) . $this->number; |
||
70 | break; |
||
71 | default: |
||
72 | $this->string = $this->adjective . $this->animal . $this->number; |
||
73 | break; |
||
74 | } |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @param null $first |
||
79 | * @param null $second |
||
80 | */ |
||
81 | private function generateNumbers($first = null, $second = null) |
||
91 | } |
||
92 |
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.