Skip to content

Commit 69ed3f0

Browse files
committed
[WIP] Update type hints and PHPDocs
1 parent 61f61a5 commit 69ed3f0

File tree

4 files changed

+84
-81
lines changed

4 files changed

+84
-81
lines changed

src/Attribute.php

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ class Attribute
88
/** @var array */
99
protected $rules = [];
1010

11-
/** @var mixed */
11+
/** @var string */
1212
protected $key;
1313

14-
/** @var mixed */
14+
/** @var string|null */
1515
protected $alias;
1616

17-
/** @var mixed */
17+
/** @var Rakit\Validation\Validation */
1818
protected $validation;
1919

2020
/** @var bool */
2121
protected $required = false;
2222

23-
/** @var Attribute */
23+
/** @var Rakit\Validation\Validation|null */
2424
protected $primaryAttribute = null;
2525

2626
/** @var array */
@@ -32,14 +32,18 @@ class Attribute
3232
/**
3333
* Constructor
3434
*
35-
* @param Validation $validation
36-
* @param mixed $key
37-
* @param mixed $alias
38-
* @param array $rules
35+
* @param Rakit\Validation\Validation $validation
36+
* @param string $key
37+
* @param string|null $alias
38+
* @param array $rules
3939
* @return void
4040
*/
41-
public function __construct(Validation $validation, $key, $alias = null, array $rules = [])
42-
{
41+
public function __construct(
42+
Validation $validation,
43+
string $key,
44+
$alias = null,
45+
array $rules = []
46+
) {
4347
$this->validation = $validation;
4448
$this->alias = $alias;
4549
$this->key = $key;
@@ -51,7 +55,7 @@ public function __construct(Validation $validation, $key, $alias = null, array $
5155
/**
5256
* Set the primary attribute
5357
*
54-
* @param Attribute $primaryAttribute
58+
* @param Rakit\Validation\Attribute $primaryAttribute
5559
* @return void
5660
*/
5761
public function setPrimaryAttribute(Attribute $primaryAttribute)
@@ -73,7 +77,7 @@ public function setKeyIndexes(array $keyIndexes)
7377
/**
7478
* Get primary attributes
7579
*
76-
* @return mixed
80+
* @return Rakit\Validation\Attribute|null
7781
*/
7882
public function getPrimaryAttribute()
7983
{
@@ -97,7 +101,7 @@ public function setOtherAttributes(array $otherAttributes)
97101
/**
98102
* Add other attributes
99103
*
100-
* @param Attribute $otherAttribute
104+
* @param Rakit\Validation\Attribute $otherAttribute
101105
* @return void
102106
*/
103107
public function addOtherAttribute(Attribute $otherAttribute)
@@ -118,7 +122,7 @@ public function getOtherAttributes(): array
118122
/**
119123
* Add rule
120124
*
121-
* @param Rule $rule
125+
* @param Rakit\Validation\Rule $rule
122126
* @return void
123127
*/
124128
public function addRule(Rule $rule)
@@ -131,10 +135,10 @@ public function addRule(Rule $rule)
131135
/**
132136
* Get rule
133137
*
134-
* @param mixed $ruleKey
138+
* @param string $ruleKey
135139
* @return void
136140
*/
137-
public function getRule($ruleKey)
141+
public function getRule(string $ruleKey)
138142
{
139143
return $this->hasRule($ruleKey)? $this->rules[$ruleKey] : null;
140144
}
@@ -152,21 +156,21 @@ public function getRules(): array
152156
/**
153157
* Check the $ruleKey has in the rule
154158
*
155-
* @param mixed $ruleKey
159+
* @param string $ruleKey
156160
* @return bool
157161
*/
158-
public function hasRule($ruleKey): bool
162+
public function hasRule(string $ruleKey): bool
159163
{
160164
return isset($this->rules[$ruleKey]);
161165
}
162166

163167
/**
164168
* Set required
165169
*
166-
* @param mixed $required
170+
* @param boolean $required
167171
* @return void
168172
*/
169-
public function setRequired($required)
173+
public function setRequired(bool $required)
170174
{
171175
$this->required = $required;
172176
}
@@ -204,10 +208,10 @@ public function getKeyIndexes(): array
204208
/**
205209
* Get value
206210
*
207-
* @param mixed $key
211+
* @param string|null $key
208212
* @return void
209213
*/
210-
public function getValue($key = null)
214+
public function getValue(string $key = null)
211215
{
212216
if ($key && $this->isArrayAttribute()) {
213217
$key = $this->resolveSiblingKey($key);
@@ -225,28 +229,28 @@ public function getValue($key = null)
225229
*
226230
* @return boolean
227231
*/
228-
public function isArrayAttribute()
232+
public function isArrayAttribute(): bool
229233
{
230234
return count($this->getKeyIndexes()) > 0;
231235
}
232236

233237
/**
234-
* Check that is using dot notation
238+
* Check this attribute is using dot notation
235239
*
236240
* @return boolean
237241
*/
238-
public function isUsingDotNotation()
242+
public function isUsingDotNotation(): bool
239243
{
240244
return strpos($this->getKey(), '.') !== false;
241245
}
242246

243247
/**
244248
* Resolve sibling key
245249
*
246-
* @param mixed $key
247-
* @return mixed
250+
* @param string $key
251+
* @return string
248252
*/
249-
public function resolveSiblingKey($key)
253+
public function resolveSiblingKey(string $key): string
250254
{
251255
$indexes = $this->getKeyIndexes();
252256
$keys = explode("*", $key);
@@ -285,18 +289,18 @@ public function getHumanizedKey()
285289
/**
286290
* Set alias
287291
*
288-
* @param mixed $alias
292+
* @param string $alias
289293
* @return void
290294
*/
291-
public function setAlias($alias)
295+
public function setAlias(string $alias)
292296
{
293297
$this->alias = $alias;
294298
}
295299

296300
/**
297301
* Get alias
298302
*
299-
* @return mixed
303+
* @return string|null
300304
*/
301305
public function getAlias()
302306
{

src/ErrorBag.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ public function __construct(array $messages = [])
2020
}
2121

2222
/**
23-
* Add key,rule and message
23+
* Add message for given key and rule
2424
*
25-
* @param mixed $key
26-
* @param mixed $rule
27-
* @param mixed $message
25+
* @param string $key
26+
* @param string $rule
27+
* @param string $message
2828
* @return void
2929
*/
30-
public function add($key, $rule, $message)
30+
public function add(string $key, string $rule, string $message)
3131
{
3232
if (!isset($this->messages[$key])) {
3333
$this->messages[$key] = [];
@@ -37,7 +37,7 @@ public function add($key, $rule, $message)
3737
}
3838

3939
/**
40-
* Get results count
40+
* Get messages count
4141
*
4242
* @return int
4343
*/
@@ -49,10 +49,10 @@ public function count(): int
4949
/**
5050
* Check given key is existed
5151
*
52-
* @param mixed $key
52+
* @param string $key
5353
* @return bool
5454
*/
55-
public function has($key): bool
55+
public function has(string $key): bool
5656
{
5757
list($key, $ruleName) = $this->parsekey($key);
5858
if ($this->isWildcardKey($key)) {
@@ -72,10 +72,10 @@ public function has($key): bool
7272
/**
7373
* Get the first value of array
7474
*
75-
* @param mixed $key
75+
* @param string $key
7676
* @return mixed
7777
*/
78-
public function first($key)
78+
public function first(string $key)
7979
{
8080
list($key, $ruleName) = $this->parsekey($key);
8181
if ($this->isWildcardKey($key)) {
@@ -98,13 +98,13 @@ public function first($key)
9898
}
9999

100100
/**
101-
* Given $key and $format then get the results
101+
* Get messages from given key, can be use custom format
102102
*
103-
* @param mixed $key
103+
* @param string $key
104104
* @param string $format
105105
* @return array
106106
*/
107-
public function get($key, string $format = ':message'): array
107+
public function get(string $key, string $format = ':message'): array
108108
{
109109
list($key, $ruleName) = $this->parsekey($key);
110110
$results = [];
@@ -129,7 +129,7 @@ public function get($key, string $format = ':message'): array
129129
}
130130

131131
/**
132-
* Get all results
132+
* Get all messages
133133
*
134134
* @param string $format
135135
* @return array
@@ -147,7 +147,7 @@ public function all(string $format = ':message'): array
147147
}
148148

149149
/**
150-
* Get the first result of results
150+
* Get the first message from existing keys
151151
*
152152
* @param string $format
153153
* @param boolean $dotNotation
@@ -168,7 +168,7 @@ public function firstOfAll(string $format = ':message', bool $dotNotation = fals
168168
}
169169

170170
/**
171-
* Get messagees
171+
* Get plain array messages
172172
*
173173
* @return array
174174
*/
@@ -180,10 +180,10 @@ public function toArray(): array
180180
/**
181181
* Parse $key to get the array of $key and $ruleName
182182
*
183-
* @param mixed $key
183+
* @param string $key
184184
* @return array
185185
*/
186-
protected function parseKey($key): array
186+
protected function parseKey(string $key): array
187187
{
188188
$expl = explode(':', $key, 2);
189189
$key = $expl[0];
@@ -197,19 +197,19 @@ protected function parseKey($key): array
197197
* @param mixed $key
198198
* @return bool
199199
*/
200-
protected function isWildcardKey($key): bool
200+
protected function isWildcardKey(string $key): bool
201201
{
202202
return false !== strpos($key, '*');
203203
}
204204

205205
/**
206206
* Filter messages with wildcard key
207207
*
208-
* @param mixed $key
209-
* @param mixed $ruleName
208+
* @param string $key
209+
* @param mixed $ruleName
210210
* @return array
211211
*/
212-
protected function filterMessagesForWildcardKey($key, $ruleName = null): array
212+
protected function filterMessagesForWildcardKey(string $key, $ruleName = null): array
213213
{
214214
$messages = $this->messages;
215215
$pattern = preg_quote($key, '#');
@@ -236,11 +236,11 @@ protected function filterMessagesForWildcardKey($key, $ruleName = null): array
236236
/**
237237
* Get formatted message
238238
*
239-
* @param mixed $message
240-
* @param mixed $format
239+
* @param string $message
240+
* @param string $format
241241
* @return string
242242
*/
243-
protected function formatMessage($message, $format): string
243+
protected function formatMessage(string $message, string $format): string
244244
{
245245
return str_replace(':message', $message, $format);
246246
}

0 commit comments

Comments
 (0)