Passed
Push — master ( e244ce...d9f030 )
by Fran
06:26
created
src/NOSQL/Dto/Model/NOSQLModelDto.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function setPk(string $id)
53 53
     {
54
-        if(!empty($this->_id)) {
54
+        if (!empty($this->_id)) {
55 55
             throw new NOSQLValidationException(t('Primary key already defined'), NOSQLValidationException::NOSQL_VALIDATION_ID_ALREADY_DEFINED);
56 56
         }
57 57
         $this->_id = $id;
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     public function getLastUpdate($format = null)
65 65
     {
66 66
         $value = $this->_last_update;
67
-        if(null !== $format) {
67
+        if (null !== $format) {
68 68
 
69 69
         }
70 70
         return $value;
@@ -104,11 +104,11 @@  discard block
 block discarded – undo
104 104
     public function validate($throwException = false) {
105 105
         $errors = [];
106 106
         $reflection = new \ReflectionClass(get_called_class());
107
-        foreach($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
107
+        foreach ($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
108 108
             $required = InjectorHelper::checkIsRequired($property->getDocComment());
109 109
             $value = $property->getValue($this);
110
-            if($required && $this->checkEmpty($value)) {
111
-                if($throwException) {
110
+            if ($required && $this->checkEmpty($value)) {
111
+                if ($throwException) {
112 112
                     throw new NOSQLValidationException(t('Empty value for property ') . $property->getName(), NOSQLValidationException::NOSQL_VALIDATION_REQUIRED);
113 113
                 } else {
114 114
                     $errors[] = $property->getName();
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
     public function toArray()
128 128
     {
129 129
         $array = parent::toArray();
130
-        if(null !== $this->getPk()) {
130
+        if (null !== $this->getPk()) {
131 131
             $array['_id'] = $this->getPk();
132 132
         }
133
-        if(null !== $this->getName()) {
133
+        if (null !== $this->getName()) {
134 134
             $array[Api::API_LIST_NAME_FIELD] = $this->getName();
135 135
         }
136 136
         $array['_last_update'] = $this->getLastUpdate(\DateTime::ATOM);
@@ -154,10 +154,10 @@  discard block
 block discarded – undo
154 154
                 if (!is_numeric($value)) {
155 155
                     $errors[] = $property->getName();
156 156
                 } else {
157
-                    if(NOSQLBase::NOSQL_TYPE_INTEGER === strtolower($type)) {
158
-                        $property->setValue($this, (integer)$value);
157
+                    if (NOSQLBase::NOSQL_TYPE_INTEGER === strtolower($type)) {
158
+                        $property->setValue($this, (integer) $value);
159 159
                     } else {
160
-                        $property->setValue($this, (float)$value);
160
+                        $property->setValue($this, (float) $value);
161 161
                     }
162 162
                 }
163 163
                 break;
@@ -179,16 +179,16 @@  discard block
 block discarded – undo
179 179
                 if (!in_array($value, [true, false, 0, 1])) {
180 180
                     $errors[] = $property->getName();
181 181
                 }
182
-                $property->setValue($this, (bool)$value);
182
+                $property->setValue($this, (bool) $value);
183 183
                 break;
184 184
             case NOSQLBase::NOSQL_TYPE_DATE:
185 185
             case NOSQLBase::NOSQL_TYPE_TIMESTAMP:
186 186
                 $dateTime = new \DateTime($value, new \DateTimeZone('UTC'));
187
-                if(!$dateTime) {
187
+                if (!$dateTime) {
188 188
                     $errors[] = $property->getName();
189 189
                 } else {
190 190
                     $dateTime->setTimezone(new \DateTimeZone(date_default_timezone_get()));
191
-                    $property->setValue($this, new UTCDateTime($dateTime->getTimestamp()*1000));
191
+                    $property->setValue($this, new UTCDateTime($dateTime->getTimestamp() * 1000));
192 192
                 }
193 193
                 break;
194 194
         }
Please login to merge, or discard this patch.
src/NOSQL/Models/base/NOSQLModelTrait.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
     public function __get($name)
25 25
     {
26 26
         $value = null;
27
-        if(null !== $this->dto && property_exists($this->dto, $name)) {
27
+        if (null !== $this->dto && property_exists($this->dto, $name)) {
28 28
             $value = $this->dto->$name;
29 29
         }
30 30
         return $value;
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public function __set($name, $value)
38 38
     {
39
-        if(null !== $this->dto && property_exists($this->dto, $name)) {
39
+        if (null !== $this->dto && property_exists($this->dto, $name)) {
40 40
             $this->dto->$name = $value;
41 41
             $this->addChanges($name);
42 42
         }
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
 
46 46
     public function __call($name, $arguments)
47 47
     {
48
-        if(preg_match('/^(set|get)/', $name)) {
48
+        if (preg_match('/^(set|get)/', $name)) {
49 49
             $property = lcfirst(str_replace(['set', 'Set', 'get', 'Get'], '', $name));
50
-            if(false !== stripos($name, 'set')) {
50
+            if (false !== stripos($name, 'set')) {
51 51
                 $this->dto->$property = $arguments[0];
52 52
             } else {
53 53
                 return $this->dto->$property;
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
     public function feed(array $data, $withName = false) {
65 65
         $name = '';
66 66
         $sep = '';
67
-        foreach($data as $key => $value) {
68
-            if($value instanceof ObjectId) {
67
+        foreach ($data as $key => $value) {
68
+            if ($value instanceof ObjectId) {
69 69
                 $this->dto->setPk($value->jsonSerialize()['$oid']);
70 70
                 $name = $this->dto->getPk();
71
-            } elseif($key === '_last_update') {
71
+            } elseif ($key === '_last_update') {
72 72
                 $this->dto->setLastUpdate($value instanceof UTCDateTime ? $value : null);
73 73
             } else {
74 74
                 if (is_object($value)) {
@@ -79,13 +79,13 @@  discard block
 block discarded – undo
79 79
                     }
80 80
                 }
81 81
                 $this->$key = $value;
82
-                if(in_array(strtolower($key), ['name', 'label', 'title', 'method'])) {
82
+                if (in_array(strtolower($key), ['name', 'label', 'title', 'method'])) {
83 83
                     $name .= $sep . $value;
84 84
                     $sep = ' ';
85 85
                 }
86 86
             }
87 87
         }
88
-        if($withName) {
88
+        if ($withName) {
89 89
             $this->dto->setName($name);
90 90
         }
91 91
     }
Please login to merge, or discard this patch.
src/NOSQL/Services/ParserService.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -28,11 +28,11 @@  discard block
 block discarded – undo
28 28
         $dns .= '@' . Config::getParam('nosql.host', 'localhost', $lowerDomain);
29 29
 
30 30
         $database = Config::getParam('nosql.database', 'nosql', $lowerDomain);
31
-        if(null !== Config::getParam('nosql.replicaset')) {
31
+        if (null !== Config::getParam('nosql.replicaset')) {
32 32
             $dns .= '/' . $database . '?ssl=true&replicaSet=' . Config::getParam('nosql.replicaset', null, $lowerDomain);
33 33
             $dns .= '&authSource=admin&serverSelectionTryOnce=false&serverSelectionTimeoutMS=15000';
34 34
         } else {
35
-            if(strtolower($protocol) !== 'mongodb+srv') {
35
+            if (strtolower($protocol) !== 'mongodb+srv') {
36 36
                 $dns .= ':' . Config::getParam('nosql.port', '27017', $lowerDomain);
37 37
             }
38 38
             $dns .= '/' . $database . "?authSource=admin";
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      */
53 53
     public function checkAndSave($domain, $collection, NOSQLModelDto $dto) {
54 54
         $errors = $dto->validate();
55
-        if(empty($errors)) {
55
+        if (empty($errors)) {
56 56
 
57 57
         } else {
58 58
             throw new ApiException(t('Dto not valid'), 400);
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
     public function hydrateModelFromRequest(array $data, $className) {
70 70
         $model = null;
71 71
         $reflectionClass = new \ReflectionClass($className);
72
-        if($reflectionClass->isSubclassOf(NOSQLBase::class)) {
72
+        if ($reflectionClass->isSubclassOf(NOSQLBase::class)) {
73 73
             /** @var NOSQLActiveRecord $modelName */
74 74
             $modelName = $className::MODEL_CLASS;
75 75
             $model = $modelName::fromArray($data);
Please login to merge, or discard this patch.
src/NOSQL/Models/NOSQLQuery.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
         $con = NOSQLParserTrait::initConnection($model, $con);
28 28
         $collection = $con->selectCollection($model->getSchema()->name);
29 29
         $result = $collection->findOne(['_id' => new ObjectId($pk)]);
30
-        if(null !== $result) {
30
+        if (null !== $result) {
31 31
             $model->feed($result->getArrayCopy());
32 32
         } else {
33 33
             throw new ApiException(t('Document not found'), 404);
@@ -54,21 +54,21 @@  discard block
 block discarded – undo
54 54
 
55 55
         $resultSet->count = $collection->countDocuments($filters, $nosqlOptions);
56 56
 
57
-        $nosqlOptions["limit"] = (integer)(array_key_exists(Api::API_LIMIT_FIELD, $criteria) ? $criteria[Api::API_LIMIT_FIELD] : Config::getParam('pagination.limit', 50));
58
-        $page = (integer)(array_key_exists(Api::API_PAGE_FIELD, $criteria) ? $criteria[Api::API_PAGE_FIELD] : 1);
57
+        $nosqlOptions["limit"] = (integer) (array_key_exists(Api::API_LIMIT_FIELD, $criteria) ? $criteria[Api::API_LIMIT_FIELD] : Config::getParam('pagination.limit', 50));
58
+        $page = (integer) (array_key_exists(Api::API_PAGE_FIELD, $criteria) ? $criteria[Api::API_PAGE_FIELD] : 1);
59 59
         $nosqlOptions["skip"] = ($page === 1) ? 0 : ($page - 1) * $nosqlOptions["limit"];
60 60
 
61 61
         if ((array_key_exists(Api::API_ORDER_FIELD, $criteria)) && (is_array($criteria[Api::API_ORDER_FIELD]))) {
62 62
             $nosqlOptions["sort"] = [];
63 63
             foreach ($criteria[Api::API_ORDER_FIELD] as $field => $direction) {
64
-                $nosqlOptions["sort"][$field] = (abs($direction) === 1)  ? $direction : 1;
64
+                $nosqlOptions["sort"][$field] = (abs($direction) === 1) ? $direction : 1;
65 65
             }
66 66
         }
67 67
 
68 68
         $results = $collection->find($filters, $nosqlOptions);
69 69
         /** @var  $result */
70 70
         $items = $results->toArray();
71
-        foreach($items as $item) {
71
+        foreach ($items as $item) {
72 72
             $model->feed($item->getArrayCopy(), true);
73 73
             $resultSet->items[] = $model->getDtoCopy(true);
74 74
         }
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
         // Check index collation
98 98
         $options = [];
99 99
         $indexes = $collection->listIndexes();
100
-        foreach($indexes as $index) {
100
+        foreach ($indexes as $index) {
101 101
             $indexInfo = $index->__debugInfo();
102 102
             if (empty(array_diff(array_keys($index["key"]), array_keys($filters)))) {
103 103
                 if (array_key_exists("collation", $indexInfo)) {
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
         }
110 110
 
111 111
         if (array_key_exists("collation", $options)) {
112
-            foreach($filters as $key=>$filter) {
112
+            foreach ($filters as $key=>$filter) {
113 113
                 if (is_string($criteria[$key])) {
114 114
                     $filters[$key] = $criteria[$key];
115 115
                 }
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
     {
128 128
         $filterValue = $criteria[$property->name];
129 129
         if (is_array($filterValue)) {
130
-            if(in_array($filterValue[0], [
130
+            if (in_array($filterValue[0], [
131 131
                 self::NOSQL_NOT_NULL_OPERATOR,
132 132
                 self::NOSQL_IN_OPERATOR,
133 133
             ])) {
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
                     self::NOSQL_IN_OPERATOR => $filterValue,
143 143
                 ];
144 144
             }
145
-        } elseif(in_array($filterValue, [
145
+        } elseif (in_array($filterValue, [
146 146
             self::NOSQL_NOT_NULL_OPERATOR,
147 147
         ])) {
148 148
             $filterValue = [
@@ -166,9 +166,9 @@  discard block
 block discarded – undo
166 166
                         break;
167 167
                 }
168 168
             } elseif (NOSQLBase::NOSQL_TYPE_INTEGER === $property->type) {
169
-                $filterValue = (integer)$filterValue;
169
+                $filterValue = (integer) $filterValue;
170 170
             } else {
171
-                $filterValue = (float)$filterValue;
171
+                $filterValue = (float) $filterValue;
172 172
             }
173 173
             $filterValue = [
174 174
                 '$eq' => $filterValue,
Please login to merge, or discard this patch.