1 | <?php |
||
5 | trait Generators |
||
6 | { |
||
7 | protected $fakerString; |
||
8 | |||
9 | /** |
||
10 | * Generate a random string. |
||
11 | * |
||
12 | * @return string |
||
13 | */ |
||
14 | 12 | protected function generate() |
|
28 | |||
29 | /** |
||
30 | * Generate a ramdom integer. |
||
31 | * |
||
32 | * @return int |
||
33 | */ |
||
34 | 1 | protected function generateInteger() |
|
38 | |||
39 | /** |
||
40 | * Generate a random integer. |
||
41 | * |
||
42 | * @return int |
||
43 | */ |
||
44 | 2 | protected function generateRandomInt($start, $end) |
|
48 | |||
49 | /** |
||
50 | * Generate a random string. |
||
51 | * |
||
52 | * @param \Closure $generator |
||
53 | * @return mixed |
||
54 | */ |
||
55 | 10 | protected function generateString($generator) |
|
65 | |||
66 | /** |
||
67 | * Get the alpha generator. |
||
68 | * |
||
69 | * @return mixed |
||
70 | */ |
||
71 | protected function getAlphaGenerator() |
||
77 | |||
78 | /** |
||
79 | * Get the alpha generator. |
||
80 | * |
||
81 | * @return mixed |
||
82 | */ |
||
83 | protected function getNumericGenerator() |
||
89 | |||
90 | /** |
||
91 | * Generate a random string. |
||
92 | * |
||
93 | * @return int|string |
||
94 | */ |
||
95 | 9 | protected function generateAlpha() |
|
99 | |||
100 | /** |
||
101 | * Generate random array elements. |
||
102 | * |
||
103 | * @return array |
||
104 | */ |
||
105 | 1 | protected function generateArray() |
|
121 | |||
122 | /** |
||
123 | * Generate a numeric random value. |
||
124 | * |
||
125 | * @return int|string |
||
126 | */ |
||
127 | 3 | protected function generateNumeric() |
|
135 | } |
||
136 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: