@@ -42,11 +42,11 @@ discard block |
||
42 | 42 | public function exists($value, string $role, ?string $field = null, bool $ignoreCase = false): bool |
43 | 43 | { |
44 | 44 | $repository = $this->orm->getRepository($role); |
45 | - if ($field === null) { |
|
45 | + if ($field === null){ |
|
46 | 46 | return $repository->findByPK($value) !== null; |
47 | 47 | } |
48 | 48 | |
49 | - if ($ignoreCase && $repository instanceof Repository) { |
|
49 | + if ($ignoreCase && $repository instanceof Repository){ |
|
50 | 50 | return $this |
51 | 51 | ->addCaseInsensitiveWhere($repository->select(), $field, $value) |
52 | 52 | ->fetchOne() !== null; |
@@ -68,16 +68,16 @@ discard block |
||
68 | 68 | $values = $this->withValues($withFields); |
69 | 69 | $values[$field] = $value; |
70 | 70 | |
71 | - if ($this->isProvidedByContext($role, $values)) { |
|
71 | + if ($this->isProvidedByContext($role, $values)){ |
|
72 | 72 | return true; |
73 | 73 | } |
74 | 74 | |
75 | 75 | $repository = $this->orm->getRepository($role); |
76 | 76 | |
77 | - if ($ignoreCase && $repository instanceof Repository) { |
|
77 | + if ($ignoreCase && $repository instanceof Repository){ |
|
78 | 78 | $select = $repository->select(); |
79 | 79 | |
80 | - foreach ($values as $field => $fieldValue) { |
|
80 | + foreach ($values as $field => $fieldValue){ |
|
81 | 81 | $this->addCaseInsensitiveWhere($select, $field, $fieldValue); |
82 | 82 | } |
83 | 83 | |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | private function withValues(array $fields): array |
95 | 95 | { |
96 | 96 | $values = []; |
97 | - foreach ($fields as $field) { |
|
98 | - if ($this->getValidator()->hasValue($field)) { |
|
97 | + foreach ($fields as $field){ |
|
98 | + if ($this->getValidator()->hasValue($field)){ |
|
99 | 99 | $values[$field] = $this->getValidator()->getValue($field); |
100 | 100 | } |
101 | 101 | } |
@@ -111,13 +111,13 @@ discard block |
||
111 | 111 | private function isProvidedByContext(string $role, array $values): bool |
112 | 112 | { |
113 | 113 | $entity = $this->getValidator()->getContext(); |
114 | - if (!is_object($entity) || !$this->orm->getHeap()->has($entity)) { |
|
114 | + if (!is_object($entity) || !$this->orm->getHeap()->has($entity)){ |
|
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
118 | 118 | $extract = $this->orm->getMapper($role)->extract($entity); |
119 | - foreach ($values as $field => $value) { |
|
120 | - if (!isset($extract[$field]) || $extract[$field] !== $value) { |
|
119 | + foreach ($values as $field => $value){ |
|
120 | + if (!isset($extract[$field]) || $extract[$field] !== $value){ |
|
121 | 121 | return false; |
122 | 122 | } |
123 | 123 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | private function addCaseInsensitiveWhere(Select $select, string $field, $value): Select |
135 | 135 | { |
136 | - if (!is_string($value)) { |
|
136 | + if (!is_string($value)){ |
|
137 | 137 | return $select->where($field, $value); |
138 | 138 | } |
139 | 139 |
@@ -42,11 +42,13 @@ discard block |
||
42 | 42 | public function exists($value, string $role, ?string $field = null, bool $ignoreCase = false): bool |
43 | 43 | { |
44 | 44 | $repository = $this->orm->getRepository($role); |
45 | - if ($field === null) { |
|
45 | + if ($field === null) |
|
46 | + { |
|
46 | 47 | return $repository->findByPK($value) !== null; |
47 | 48 | } |
48 | 49 | |
49 | - if ($ignoreCase && $repository instanceof Repository) { |
|
50 | + if ($ignoreCase && $repository instanceof Repository) |
|
51 | + { |
|
50 | 52 | return $this |
51 | 53 | ->addCaseInsensitiveWhere($repository->select(), $field, $value) |
52 | 54 | ->fetchOne() !== null; |
@@ -68,16 +70,19 @@ discard block |
||
68 | 70 | $values = $this->withValues($withFields); |
69 | 71 | $values[$field] = $value; |
70 | 72 | |
71 | - if ($this->isProvidedByContext($role, $values)) { |
|
73 | + if ($this->isProvidedByContext($role, $values)) |
|
74 | + { |
|
72 | 75 | return true; |
73 | 76 | } |
74 | 77 | |
75 | 78 | $repository = $this->orm->getRepository($role); |
76 | 79 | |
77 | - if ($ignoreCase && $repository instanceof Repository) { |
|
80 | + if ($ignoreCase && $repository instanceof Repository) |
|
81 | + { |
|
78 | 82 | $select = $repository->select(); |
79 | 83 | |
80 | - foreach ($values as $field => $fieldValue) { |
|
84 | + foreach ($values as $field => $fieldValue) |
|
85 | + { |
|
81 | 86 | $this->addCaseInsensitiveWhere($select, $field, $fieldValue); |
82 | 87 | } |
83 | 88 | |
@@ -94,8 +99,10 @@ discard block |
||
94 | 99 | private function withValues(array $fields): array |
95 | 100 | { |
96 | 101 | $values = []; |
97 | - foreach ($fields as $field) { |
|
98 | - if ($this->getValidator()->hasValue($field)) { |
|
102 | + foreach ($fields as $field) |
|
103 | + { |
|
104 | + if ($this->getValidator()->hasValue($field)) |
|
105 | + { |
|
99 | 106 | $values[$field] = $this->getValidator()->getValue($field); |
100 | 107 | } |
101 | 108 | } |
@@ -111,13 +118,16 @@ discard block |
||
111 | 118 | private function isProvidedByContext(string $role, array $values): bool |
112 | 119 | { |
113 | 120 | $entity = $this->getValidator()->getContext(); |
114 | - if (!is_object($entity) || !$this->orm->getHeap()->has($entity)) { |
|
121 | + if (!is_object($entity) || !$this->orm->getHeap()->has($entity)) |
|
122 | + { |
|
115 | 123 | return false; |
116 | 124 | } |
117 | 125 | |
118 | 126 | $extract = $this->orm->getMapper($role)->extract($entity); |
119 | - foreach ($values as $field => $value) { |
|
120 | - if (!isset($extract[$field]) || $extract[$field] !== $value) { |
|
127 | + foreach ($values as $field => $value) |
|
128 | + { |
|
129 | + if (!isset($extract[$field]) || $extract[$field] !== $value) |
|
130 | + { |
|
121 | 131 | return false; |
122 | 132 | } |
123 | 133 | } |
@@ -133,7 +143,8 @@ discard block |
||
133 | 143 | */ |
134 | 144 | private function addCaseInsensitiveWhere(Select $select, string $field, $value): Select |
135 | 145 | { |
136 | - if (!is_string($value)) { |
|
146 | + if (!is_string($value)) |
|
147 | + { |
|
137 | 148 | return $select->where($field, $value); |
138 | 149 | } |
139 | 150 |