@@ -36,7 +36,7 @@ |
||
36 | 36 | |
37 | 37 | public function getFirstError() : Error |
38 | 38 | { |
39 | - return $this->errors[0]; |
|
39 | + return $this->errors[ 0 ]; |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | } |
43 | 43 | \ No newline at end of file |
@@ -7,7 +7,7 @@ |
||
7 | 7 | abstract class Result |
8 | 8 | { |
9 | 9 | private $valid; |
10 | - protected $errors = []; |
|
10 | + protected $errors = [ ]; |
|
11 | 11 | |
12 | 12 | public function __construct(bool $valid, Error... $errors) |
13 | 13 | { |
@@ -30,9 +30,9 @@ |
||
30 | 30 | /** |
31 | 31 | * @var array $allowedChars |
32 | 32 | */ |
33 | - private $allowedSpecialChars = []; |
|
33 | + private $allowedSpecialChars = [ ]; |
|
34 | 34 | |
35 | - public function __construct(int $minLength = 4, int $maxLength = 12, $allowedSpecialChars = []) |
|
35 | + public function __construct(int $minLength = 4, int $maxLength = 12, $allowedSpecialChars = [ ]) |
|
36 | 36 | { |
37 | 37 | $this->minLength = $minLength; |
38 | 38 | $this->maxLength = $maxLength; |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | /** |
25 | 25 | * @var array $rules |
26 | 26 | */ |
27 | - private $rules = []; |
|
27 | + private $rules = [ ]; |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * ForAll constructor. |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | /** |
49 | 49 | * @var Error $errors[] |
50 | 50 | */ |
51 | - $errors = []; |
|
51 | + $errors = [ ]; |
|
52 | 52 | foreach ($this->rules as $rule) { |
53 | 53 | |
54 | 54 | $result = $rule->validate($data); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @var Error $error |
60 | 60 | */ |
61 | 61 | foreach ($result->getErrors() as $error) { |
62 | - $errors[] = $error; |
|
62 | + $errors[ ] = $error; |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 |
@@ -33,8 +33,9 @@ discard block |
||
33 | 33 | */ |
34 | 34 | public function __construct(Rule... $rules) |
35 | 35 | { |
36 | - if (empty($rules)) |
|
37 | - throw new InvalidAggregateRule("No rules specified for aggregate rule", ForAll::class); |
|
36 | + if (empty($rules)) { |
|
37 | + throw new InvalidAggregateRule("No rules specified for aggregate rule", ForAll::class); |
|
38 | + } |
|
38 | 39 | $this->rules = $rules; |
39 | 40 | } |
40 | 41 | |
@@ -65,9 +66,9 @@ discard block |
||
65 | 66 | |
66 | 67 | } |
67 | 68 | |
68 | - if (!($errors)) |
|
69 | - return new Success(); |
|
70 | - else { |
|
69 | + if (!($errors)) { |
|
70 | + return new Success(); |
|
71 | + } else { |
|
71 | 72 | return new Failure(...$errors); // Use the splat operator |
72 | 73 | |
73 | 74 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | /** |
36 | 36 | * @var array|Rule[] $rules |
37 | 37 | */ |
38 | - private $rules = []; |
|
38 | + private $rules = [ ]; |
|
39 | 39 | /** |
40 | 40 | * ForAtLeast constructor. |
41 | 41 | * @param int $numOfRules |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | /** |
61 | 61 | * @var array|Error[] $errors |
62 | 62 | */ |
63 | - $errors = []; |
|
63 | + $errors = [ ]; |
|
64 | 64 | $passed = 0; |
65 | 65 | |
66 | 66 | foreach ($this->rules as $rule) { |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * @var Error $error |
73 | 73 | */ |
74 | 74 | foreach ($result->getErrors() as $error) { |
75 | - $errors[] = $error; |
|
75 | + $errors[ ] = $error; |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | else { |
@@ -44,12 +44,14 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function __construct(int $numOfRules, Rule... $rules) |
46 | 46 | { |
47 | - if (empty($rules)) |
|
48 | - throw new InvalidAggregateRule("No rules specified for aggregate rule", ForAtLeast::class); |
|
47 | + if (empty($rules)) { |
|
48 | + throw new InvalidAggregateRule("No rules specified for aggregate rule", ForAtLeast::class); |
|
49 | + } |
|
49 | 50 | |
50 | - if (count($rules) < $numOfRules) |
|
51 | - throw new InvalidAggregateRule('Minimum passing rule number is greater than supplied rules', |
|
51 | + if (count($rules) < $numOfRules) { |
|
52 | + throw new InvalidAggregateRule('Minimum passing rule number is greater than supplied rules', |
|
52 | 53 | ForAtLeast::class); |
54 | + } |
|
53 | 55 | |
54 | 56 | $this->rules = $rules; |
55 | 57 | $this->minimum = $numOfRules; |
@@ -74,13 +76,13 @@ discard block |
||
74 | 76 | foreach ($result->getErrors() as $error) { |
75 | 77 | $errors[] = $error; |
76 | 78 | } |
77 | - } |
|
78 | - else { |
|
79 | + } else { |
|
79 | 80 | $passed++; |
80 | 81 | } |
81 | 82 | |
82 | - if ($passed >= $this->minimum) |
|
83 | - return new Success(); |
|
83 | + if ($passed >= $this->minimum) { |
|
84 | + return new Success(); |
|
85 | + } |
|
84 | 86 | } |
85 | 87 | return new Failure(...$errors); |
86 | 88 | } |
@@ -39,8 +39,9 @@ |
||
39 | 39 | |
40 | 40 | $result = $rule->validate($password); |
41 | 41 | |
42 | - if ($result->isValid()) |
|
43 | - return new Success(); |
|
42 | + if ($result->isValid()) { |
|
43 | + return new Success(); |
|
44 | + } |
|
44 | 45 | /** |
45 | 46 | * @var Failure $result |
46 | 47 | */ |
@@ -38,8 +38,9 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function __construct(int $patternType) |
40 | 40 | { |
41 | - if ($patternType < 0 || $patternType > 3) |
|
42 | - throw new InvalidRuleOption($patternType); |
|
41 | + if ($patternType < 0 || $patternType > 3) { |
|
42 | + throw new InvalidRuleOption($patternType); |
|
43 | + } |
|
43 | 44 | |
44 | 45 | $this->pattern = $patternType; |
45 | 46 | } |
@@ -63,10 +64,11 @@ discard block |
||
63 | 64 | break; |
64 | 65 | } |
65 | 66 | |
66 | - if ($isValid) |
|
67 | - return new Success(); |
|
68 | - else |
|
69 | - return new Failure(new RuleError(RuleErrorCode::PATTERN_MISMATCH, |
|
67 | + if ($isValid) { |
|
68 | + return new Success(); |
|
69 | + } else { |
|
70 | + return new Failure(new RuleError(RuleErrorCode::PATTERN_MISMATCH, |
|
70 | 71 | "The string doesn't contain the required pattern")); |
72 | + } |
|
71 | 73 | } |
72 | 74 | } |
73 | 75 | \ No newline at end of file |
@@ -33,9 +33,10 @@ |
||
33 | 33 | |
34 | 34 | public function validate($data): Result |
35 | 35 | { |
36 | - if (strpos($data, $this->keyword) !== false) |
|
37 | - return new Success(); |
|
38 | - else |
|
39 | - return new Failure(new RuleError(RuleErrorCode::PATTERN_MISMATCH, "String does not contain keyword")); |
|
36 | + if (strpos($data, $this->keyword) !== false) { |
|
37 | + return new Success(); |
|
38 | + } else { |
|
39 | + return new Failure(new RuleError(RuleErrorCode::PATTERN_MISMATCH, "String does not contain keyword")); |
|
40 | + } |
|
40 | 41 | } |
41 | 42 | } |
42 | 43 | \ No newline at end of file |
@@ -17,5 +17,5 @@ |
||
17 | 17 | * @return mixed |
18 | 18 | */ |
19 | 19 | function getOptionalValue(int $key, array $arr, $default) { |
20 | - return isset($arr[$key]) ? $arr[$key]: $default; |
|
20 | + return isset($arr[ $key ]) ? $arr[ $key ] : $default; |
|
21 | 21 | } |
22 | 22 | \ No newline at end of file |