@@ -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 | } |
@@ -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 |
@@ -66,8 +66,9 @@ |
||
66 | 66 | |
67 | 67 | $result = $rule->validate($name); |
68 | 68 | |
69 | - if ($result->isValid()) |
|
70 | - return new Success(); |
|
69 | + if ($result->isValid()) { |
|
70 | + return new Success(); |
|
71 | + } |
|
71 | 72 | /** |
72 | 73 | * @var Failure $result |
73 | 74 | */ |
@@ -36,11 +36,13 @@ |
||
36 | 36 | { |
37 | 37 | $numericResult = (new NumericType())->validate($value); |
38 | 38 | |
39 | - if (!$numericResult->isValid()) |
|
40 | - return new $numericResult; |
|
39 | + if (!$numericResult->isValid()) { |
|
40 | + return new $numericResult; |
|
41 | + } |
|
41 | 42 | |
42 | - if ($value == $this->expected) |
|
43 | - return new Success(); |
|
43 | + if ($value == $this->expected) { |
|
44 | + return new Success(); |
|
45 | + } |
|
44 | 46 | |
45 | 47 | return new Failure(new RuleError(RuleErrorCode::LESS_THAN_MINIMUM, |
46 | 48 | 'The supplied number is less than the expectedimum value')); |
@@ -36,11 +36,13 @@ |
||
36 | 36 | { |
37 | 37 | $numericResult = (new NumericType())->validate($value); |
38 | 38 | |
39 | - if (!$numericResult->isValid()) |
|
40 | - return new $numericResult; |
|
39 | + if (!$numericResult->isValid()) { |
|
40 | + return new $numericResult; |
|
41 | + } |
|
41 | 42 | |
42 | - if ($value >= $this->min) |
|
43 | - return new Success(); |
|
43 | + if ($value >= $this->min) { |
|
44 | + return new Success(); |
|
45 | + } |
|
44 | 46 | |
45 | 47 | return new Failure(new RuleError(RuleErrorCode::LESS_THAN_MINIMUM, |
46 | 48 | 'The supplied number is less than the minimum value')); |
@@ -27,11 +27,13 @@ |
||
27 | 27 | { |
28 | 28 | $numericResult = (new NumericType())->validate($value); |
29 | 29 | |
30 | - if (!$numericResult->isValid()) |
|
31 | - return new $numericResult; |
|
30 | + if (!$numericResult->isValid()) { |
|
31 | + return new $numericResult; |
|
32 | + } |
|
32 | 33 | |
33 | - if ($value < 0) |
|
34 | - return new Success(); |
|
34 | + if ($value < 0) { |
|
35 | + return new Success(); |
|
36 | + } |
|
35 | 37 | |
36 | 38 | return new Failure(new RuleError(RuleErrorCode::NOT_NEGATIVE, 'The supplied number is not negative')); |
37 | 39 | } |