1 | <?php |
||
29 | class Length implements \Caridea\Validate\Rule |
||
30 | { |
||
31 | /** |
||
32 | * @var string The operator type |
||
33 | */ |
||
34 | private $operator; |
||
35 | /** |
||
36 | * @var int|int[] The length comparison |
||
37 | */ |
||
38 | private $length; |
||
39 | /** |
||
40 | * @var string The encoding to pass to `mb_strlen` |
||
41 | */ |
||
42 | private $encoding; |
||
43 | |||
44 | /** |
||
45 | * Creates a new LengthRule. |
||
46 | * |
||
47 | * @param string $operator The operator type |
||
48 | * @param int|int[] $length The length comparison |
||
49 | * @param string $encoding The encoding to pass to `mb_strlen` |
||
50 | */ |
||
51 | 4 | protected function __construct(string $operator, $length, string $encoding = 'UTF-8') |
|
57 | |||
58 | /** |
||
59 | * {@inheritDoc} |
||
60 | */ |
||
61 | 4 | public function apply($value, $data = []): ?array |
|
88 | |||
89 | /** |
||
90 | * Gets a rule that requires strings to be no longer than the limit. |
||
91 | * |
||
92 | * @param int $length The maximum length |
||
93 | * @param string $encoding The string encoding |
||
94 | * @return \Caridea\Validate\Rule\Length the created rule |
||
95 | */ |
||
96 | 1 | public static function max(int $length, string $encoding = 'UTF-8'): Length |
|
100 | |||
101 | /** |
||
102 | * Gets a rule that requires strings to be no shorter than the limit. |
||
103 | * |
||
104 | * @param int $length The minimum length |
||
105 | * @param string $encoding The string encoding |
||
106 | * @return \Caridea\Validate\Rule\Length the created rule |
||
107 | */ |
||
108 | 1 | public static function min(int $length, string $encoding = 'UTF-8'): Length |
|
112 | |||
113 | /** |
||
114 | * Gets a rule that requires strings to be exactly the length of the limit. |
||
115 | * |
||
116 | * @param int $length The required length |
||
117 | * @param string $encoding The string encoding |
||
118 | * @return \Caridea\Validate\Rule\Length the created rule |
||
119 | */ |
||
120 | 1 | public static function equal(int $length, string $encoding = 'UTF-8'): Length |
|
124 | |||
125 | /** |
||
126 | * Gets a rule that requires strings to have a minimum and maximum length. |
||
127 | * |
||
128 | * @param int $min The minimum length, inclusive |
||
129 | * @param int $max The maximum length, inclusive |
||
130 | * @param string $encoding The string encoding |
||
131 | * @return \Caridea\Validate\Rule\Length the created rule |
||
132 | */ |
||
133 | 1 | public static function between(int $min, int $max, string $encoding = 'UTF-8'): Length |
|
139 | } |
||
140 |
As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next
break
.There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.