Passed
Branch master (f0263d)
by Alexey
09:06
created
src/Validator.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -23,20 +23,20 @@  discard block
 block discarded – undo
23 23
         $this->validated = [];
24 24
         $this->errors = [];
25 25
 
26
-        foreach ($rules as $dataKey => $rule){
26
+        foreach ($rules as $dataKey => $rule) {
27 27
             $testedValue = $data[$dataKey] ?? null;
28
-            $validations = explode(" ",$rule);
28
+            $validations = explode(" ", $rule);
29 29
 
30 30
             $valueIsValid = true;
31
-            foreach ($validations as $validation){
31
+            foreach ($validations as $validation) {
32 32
                 $validation = $this->validationFactory->get($validation);
33
-                if(!$validation->validate($data, $dataKey)){
33
+                if (!$validation->validate($data, $dataKey)) {
34 34
                     $this->errors[$dataKey][] = $validation->error();
35 35
                     $valueIsValid = false;
36 36
                 }
37 37
             }
38 38
 
39
-            if($valueIsValid) {
39
+            if ($valueIsValid) {
40 40
                 $this->validated[$dataKey] = $testedValue;
41 41
             } else {
42 42
                 $validationResult = false;
@@ -46,21 +46,21 @@  discard block
 block discarded – undo
46 46
         return $validationResult;
47 47
     }
48 48
 
49
-    public function errors(){
49
+    public function errors() {
50 50
         return $this->errors;
51 51
     }
52 52
 
53
-    public function validated(){
53
+    public function validated() {
54 54
         return $this->validated;
55 55
     }
56 56
 
57
-    protected function isIntValue($value){
58
-        if(is_bool($value)) return false;
59
-        return  is_int($value) || preg_match('/^\d+$/',$value);
57
+    protected function isIntValue($value) {
58
+        if (is_bool($value)) return false;
59
+        return  is_int($value) || preg_match('/^\d+$/', $value);
60 60
     }
61 61
 
62
-    protected function isBool($value){
63
-        return is_bool($value) ||in_array($value,[0,1], true);
62
+    protected function isBool($value) {
63
+        return is_bool($value) || in_array($value, [0, 1], true);
64 64
     }
65 65
 
66 66
     protected function isEmail($value)
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -55,7 +55,9 @@
 block discarded – undo
55 55
     }
56 56
 
57 57
     protected function isIntValue($value){
58
-        if(is_bool($value)) return false;
58
+        if(is_bool($value)) {
59
+            return false;
60
+        }
59 61
         return  is_int($value) || preg_match('/^\d+$/',$value);
60 62
     }
61 63
 
Please login to merge, or discard this patch.
src/ValueObject.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -22,48 +22,48 @@
 block discarded – undo
22 22
     public function __construct($value, $type = null)
23 23
     {
24 24
         $this->value = $value;
25
-        if(!in_array($type, $this->types())) throw new ValueObjectInvalidTypeException('Wrong type: '. $type);
25
+        if (!in_array($type, $this->types())) throw new ValueObjectInvalidTypeException('Wrong type: '.$type);
26 26
         $this->type = $type;
27 27
     }
28 28
 
29
-    public function __invoke(){
29
+    public function __invoke() {
30 30
         return $this->value;
31 31
     }
32 32
 
33
-    public function value(){
33
+    public function value() {
34 34
         return $this->value;
35 35
     }
36 36
 
37
-    public function type(){
37
+    public function type() {
38 38
         return $this->type;
39 39
     }
40 40
 
41
-    public function isInt(){
41
+    public function isInt() {
42 42
         return $this->type === self::INT;
43 43
     }
44 44
 
45 45
 
46
-    public function isString(){
46
+    public function isString() {
47 47
         return $this->type === self::STRING;
48 48
     }
49 49
 
50
-    public function isBool(){
50
+    public function isBool() {
51 51
         return $this->type === self::BOOL;
52 52
     }
53 53
 
54
-    public function isFloat(){
54
+    public function isFloat() {
55 55
         return $this->type === self::FLOAT;
56 56
     }
57 57
 
58
-    public function isUndefinedType(){
58
+    public function isUndefinedType() {
59 59
         return is_null($this->type);
60 60
     }
61 61
 
62
-    protected function types(){
62
+    protected function types() {
63 63
         return [null, self::BOOL, self::FLOAT, self::INT, self::STRING];
64 64
     }
65 65
 
66
-    public static function get($value, $type = null){
66
+    public static function get($value, $type = null) {
67 67
         return new static($value, $type);
68 68
     }
69 69
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,9 @@
 block discarded – undo
22 22
     public function __construct($value, $type = null)
23 23
     {
24 24
         $this->value = $value;
25
-        if(!in_array($type, $this->types())) throw new ValueObjectInvalidTypeException('Wrong type: '. $type);
25
+        if(!in_array($type, $this->types())) {
26
+            throw new ValueObjectInvalidTypeException('Wrong type: '. $type);
27
+        }
26 28
         $this->type = $type;
27 29
     }
28 30
 
Please login to merge, or discard this patch.
src/Validations/RequiredValidation.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
     public function validate($data, $key)
12 12
     {
13 13
         $testedValue = $data[$key] ?? null;
14
-        if(! isset($testedValue)) {
14
+        if (!isset($testedValue)) {
15 15
             $this->error = "$key must be specified";
16 16
             return false;
17 17
         }
Please login to merge, or discard this patch.
src/Validations/IntValidation.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
     public function validate($data, $key)
11 11
     {
12 12
         $testedValue = $data[$key] ?? null;
13
-        if(! $this->isIntValue($testedValue)) {
13
+        if (!$this->isIntValue($testedValue)) {
14 14
             $this->error = "$key must be integer";
15 15
             return false;
16 16
         }
@@ -22,8 +22,8 @@  discard block
 block discarded – undo
22 22
         return $this->error;
23 23
     }
24 24
 
25
-    protected function isIntValue($value){
26
-        if(is_bool($value)) return false;
27
-        return  is_int($value) || preg_match('/^\d+$/',$value);
25
+    protected function isIntValue($value) {
26
+        if (is_bool($value)) return false;
27
+        return  is_int($value) || preg_match('/^\d+$/', $value);
28 28
     }
29 29
 }
30 30
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,9 @@
 block discarded – undo
23 23
     }
24 24
 
25 25
     protected function isIntValue($value){
26
-        if(is_bool($value)) return false;
26
+        if(is_bool($value)) {
27
+            return false;
28
+        }
27 29
         return  is_int($value) || preg_match('/^\d+$/',$value);
28 30
     }
29 31
 }
30 32
\ No newline at end of file
Please login to merge, or discard this patch.
src/Validations/BoolValidation.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
     public function validate($data, $key)
12 12
     {
13 13
         $testedValue = $data[$key] ?? null;
14
-        if(! $this->isBool($testedValue)) {
14
+        if (!$this->isBool($testedValue)) {
15 15
             $this->error = "$key must be bool";
16 16
             return false;
17 17
         }
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
         return $this->error;
24 24
     }
25 25
 
26
-    protected function isBool($value){
27
-        return is_bool($value) ||in_array($value,[0,1], true);
26
+    protected function isBool($value) {
27
+        return is_bool($value) || in_array($value, [0, 1], true);
28 28
     }
29 29
 }
30 30
\ No newline at end of file
Please login to merge, or discard this patch.
src/Validations/ValidationFactory.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -27,11 +27,11 @@
 block discarded – undo
27 27
      * @param $validation
28 28
      * @return ValidationInterface
29 29
      */
30
-    public function get($validation){
30
+    public function get($validation) {
31 31
         $options = explode(':', $validation);
32 32
         $validationName = array_shift($options);
33
-        if(!array_key_exists($validationName, $this->map)){
34
-            throw new InvalidValidationNameException('unknowk validation name '. $validationName);
33
+        if (!array_key_exists($validationName, $this->map)) {
34
+            throw new InvalidValidationNameException('unknowk validation name '.$validationName);
35 35
         }
36 36
         return new $this->map[$validationName]($options);
37 37
     }
Please login to merge, or discard this patch.
src/Validations/EmailValidation.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
     public function validate($data, $key)
11 11
     {
12 12
         $testedValue = $data[$key] ?? null;
13
-        if(! $this->isEmail($testedValue)) {
13
+        if (!$this->isEmail($testedValue)) {
14 14
             $this->error = "incorrect email address in $key";
15 15
             return false;
16 16
         }
Please login to merge, or discard this patch.
src/Validations/MaxValidation.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
     public function validate($data, $key)
17 17
     {
18 18
         $testedValue = $data[$key] ?? null;
19
-        if(mb_strlen($testedValue) > $this->options[0]) {
19
+        if (mb_strlen($testedValue) > $this->options[0]) {
20 20
             $this->error = "is too long (maximum {$this->options[0]} characters";
21 21
             return false;
22 22
         }
Please login to merge, or discard this patch.
src/Validation.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -17,17 +17,17 @@
 block discarded – undo
17 17
         $this->name = $name;
18 18
         $this->closure = $closure;
19 19
     }
20
-    public function check($data){
21
-        if (! $data instanceof ValueObject) $data = ValueObject::get($data);
20
+    public function check($data) {
21
+        if (!$data instanceof ValueObject) $data = ValueObject::get($data);
22 22
         try {
23
-            return call_user_func($this->closure,$data);
24
-        } catch (\Exception $exception){
23
+            return call_user_func($this->closure, $data);
24
+        } catch (\Exception $exception) {
25 25
             return false;
26 26
         }
27 27
 
28 28
     }
29 29
 
30
-    public function name(){
30
+    public function name() {
31 31
         return $this->name;
32 32
     }
33 33
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,9 @@
 block discarded – undo
18 18
         $this->closure = $closure;
19 19
     }
20 20
     public function check($data){
21
-        if (! $data instanceof ValueObject) $data = ValueObject::get($data);
21
+        if (! $data instanceof ValueObject) {
22
+            $data = ValueObject::get($data);
23
+        }
22 24
         try {
23 25
             return call_user_func($this->closure,$data);
24 26
         } catch (\Exception $exception){
Please login to merge, or discard this patch.