Passed
Branch master (336aa4)
by Fran
04:08
created
src/NOSQL/autoload.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -5,25 +5,25 @@  discard block
 block discarded – undo
5 5
  * @version 1.0
6 6
  * Autogenerated autoloader [2019-01-03 15:23:58]
7 7
  */
8
-if(!defined("BASE_DIR"))
9
-define("BASE_DIR", dirname( dirname(__DIR__) ) );
8
+if (!defined("BASE_DIR"))
9
+define("BASE_DIR", dirname(dirname(__DIR__)));
10 10
 
11 11
 require_once __DIR__ . DIRECTORY_SEPARATOR . 'Config' . DIRECTORY_SEPARATOR . 'config.php';
12 12
 
13
-if(!function_exists("NOSQL_Autoloader")) {
13
+if (!function_exists("NOSQL_Autoloader")) {
14 14
     // autoloader
15
-    function NOSQL_Autoloader( $class ) {
15
+    function NOSQL_Autoloader($class) {
16 16
         // it only autoload class into the Rain scope
17 17
         if (false !== preg_match('/^\\\?NOSQL/', $class)) {
18 18
             // Change order src
19 19
             $class = preg_replace('/^\\\?NOSQL/', 'NOSQL', $class);
20 20
             // transform the namespace in path
21
-            $path = str_replace("\\", DIRECTORY_SEPARATOR, $class );
21
+            $path = str_replace("\\", DIRECTORY_SEPARATOR, $class);
22 22
             // filepath
23 23
             $abs_path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $path . ".php";
24 24
 
25 25
             // require the file
26
-            if(file_exists($abs_path)) {
26
+            if (file_exists($abs_path)) {
27 27
                 require_once $abs_path;
28 28
             }
29 29
         }
@@ -31,5 +31,5 @@  discard block
 block discarded – undo
31 31
     }
32 32
 
33 33
     // register the autoloader
34
-    spl_autoload_register( "NOSQL_Autoloader" );
34
+    spl_autoload_register("NOSQL_Autoloader");
35 35
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,8 +5,9 @@
 block discarded – undo
5 5
  * @version 1.0
6 6
  * Autogenerated autoloader [2019-01-03 15:23:58]
7 7
  */
8
-if(!defined("BASE_DIR"))
9
-define("BASE_DIR", dirname( dirname(__DIR__) ) );
8
+if(!defined("BASE_DIR")) {
9
+    define("BASE_DIR", dirname( dirname(__DIR__) ) );
10
+}
10 11
 
11 12
 require_once __DIR__ . DIRECTORY_SEPARATOR . 'Config' . DIRECTORY_SEPARATOR . 'config.php';
12 13
 
Please login to merge, or discard this patch.
src/NOSQL/Api/NOSQL.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
         $code = 200;
58 58
         try {
59 59
             $this->srv->setCollections($module, $this->getRequest()->getRawData());
60
-        } catch(\Exception $exception) {
60
+        } catch (\Exception $exception) {
61 61
             $success = false;
62 62
             $code = 400;
63 63
             Logger::log($exception->getMessage(), LOG_WARNING);
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
         $code = 200;
76 76
         try {
77 77
             $success = $this->srv->syncCollections($module);
78
-        } catch(\Exception $exception) {
78
+        } catch (\Exception $exception) {
79 79
             $success = false;
80 80
             $code = 400;
81 81
             Logger::log($exception->getMessage(), LOG_WARNING);
Please login to merge, or discard this patch.
src/NOSQL/Services/NOSQLService.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
      */
56 56
     private function extractTypes() {
57 57
         $baseClass = new \ReflectionClass(NOSQLBase::class);
58
-        if(null !== $baseClass) {
58
+        if (null !== $baseClass) {
59 59
             $types = [];
60
-            foreach($baseClass->getConstants() as $constant) {
60
+            foreach ($baseClass->getConstants() as $constant) {
61 61
                 $types[] = $constant;
62 62
             }
63 63
             $this->setTypes($types);
@@ -79,10 +79,10 @@  discard block
 block discarded – undo
79 79
     public function getDomains() {
80 80
         $domains = [];
81 81
         $storedDomains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', Cache::JSON, TRUE);
82
-        if(!empty($storedDomains)) {
83
-            foreach($storedDomains as $domain => $data) {
82
+        if (!empty($storedDomains)) {
83
+            foreach ($storedDomains as $domain => $data) {
84 84
                 $domainLabel = str_replace(['@', '/'], '', $domain);
85
-                if('ROOT' !== $domainLabel) {
85
+                if ('ROOT' !== $domainLabel) {
86 86
                     $domains[] = $domainLabel;
87 87
                 }
88 88
             }
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
     public function getCollections($module) {
98 98
         $collections = [];
99 99
         $schemaFilename = CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Config' . DIRECTORY_SEPARATOR . 'schema.json';
100
-        if(file_exists($schemaFilename)) {
100
+        if (file_exists($schemaFilename)) {
101 101
             $collections = $this->cache->getDataFromFile($schemaFilename, Cache::JSON, TRUE);
102 102
         }
103 103
         return $collections;
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
             '@NOSQL/generator/api.base.php.twig' => CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Api' . DIRECTORY_SEPARATOR . 'base',
121 121
             '@NOSQL/generator/dto.php.twig' => CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Dto' . DIRECTORY_SEPARATOR . 'Models',
122 122
         ];
123
-        foreach($collections as $raw) {
123
+        foreach ($collections as $raw) {
124 124
             $collection = new CollectionDto(false);
125 125
             $collection->fromArray($raw);
126
-            foreach($files as $template => $path) {
126
+            foreach ($files as $template => $path) {
127 127
                 GeneratorHelper::createDir($path);
128 128
                 $templateDump = $tpl->dump($template, [
129 129
                     'domain' => $module,
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
                     'properties' => $collection->properties,
132 132
                 ]);
133 133
                 $force = false;
134
-                if(false !== strpos($template, 'dto') || false !== strpos($template, 'base')) {
134
+                if (false !== strpos($template, 'dto') || false !== strpos($template, 'base')) {
135 135
                     $force = true;
136 136
                 }
137 137
                 $this->writeTemplateToFile($templateDump, $path . DIRECTORY_SEPARATOR . $collection->name . '.php', $force);
@@ -170,10 +170,10 @@  discard block
 block discarded – undo
170 170
         $db = ParserService::getInstance()->createConnection($module);
171 171
         $collections = $this->getCollections($module);
172 172
         $success = true;
173
-        foreach($collections as $raw) {
173
+        foreach ($collections as $raw) {
174 174
             $jsonSchema = new JsonSchemaDto(false);
175
-            foreach($raw['properties'] as $rawProperty) {
176
-                switch($rawProperty['type']) {
175
+            foreach ($raw['properties'] as $rawProperty) {
176
+                switch ($rawProperty['type']) {
177 177
                     case NOSQLBase::NOSQL_TYPE_INTEGER:
178 178
                     case NOSQLBase::NOSQL_TYPE_DOUBLE:
179 179
                     case NOSQLBase::NOSQL_TYPE_LONG:
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
                 }
190 190
                 $property->bsonType = $rawProperty['type'];
191 191
                 $property->description = $rawProperty['description'];
192
-                if($rawProperty['required']) {
192
+                if ($rawProperty['required']) {
193 193
                     $jsonSchema->required[] = $rawProperty['name'];
194 194
                 }
195 195
                 $jsonSchema->properties[$rawProperty['name']] = $property->toArray();
@@ -202,11 +202,11 @@  discard block
 block discarded – undo
202 202
                     ]
203 203
                 ]);
204 204
                 $stdClass = $result->bsonSerialize();
205
-                if(!property_exists($stdClass, 'ok') && $stdClass->ok < 1) {
205
+                if (!property_exists($stdClass, 'ok') && $stdClass->ok < 1) {
206 206
                     $success = false;
207 207
                 }
208
-            } catch(\Exception $exception) {
209
-                if($exception->getCode() !== 48) {
208
+            } catch (\Exception $exception) {
209
+                if ($exception->getCode() !== 48) {
210 210
                     $success = false;
211 211
                 }
212 212
             }
Please login to merge, or discard this patch.
src/NOSQL/Services/ParserService.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function checkAndSave($domain, $collection, NOSQLModelDto $dto) {
44 44
         $errors = $dto->validate();
45
-        if(empty($errors)) {
45
+        if (empty($errors)) {
46 46
 
47 47
         } else {
48 48
             throw new ApiException(t('Dto not valid'), 400);
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     public function hydrateModelFromRequest(array $data, $className) {
59 59
         $model = null;
60 60
         $reflectionClass = new \ReflectionClass($className);
61
-        if($reflectionClass->isSubclassOf(NOSQLBase::class)) {
61
+        if ($reflectionClass->isSubclassOf(NOSQLBase::class)) {
62 62
             /** @var NOSQLActiveRecord $modelName */
63 63
             $modelName = $className::MODEL_CLASS;
64 64
             $model = $modelName::fromArray($data);
Please login to merge, or discard this patch.
src/NOSQL/Models/NOSQLActiveRecord.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -41,14 +41,14 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public function save(Database $con = null) {
43 43
         $saved = false;
44
-        if(null === $con) {
44
+        if (null === $con) {
45 45
             $con = ParserService::getInstance()->createConnection($this->getDomain());
46 46
         }
47 47
         $collection = $con->selectCollection($this->getSchema()->name);
48 48
         try {
49 49
             $isInsert = $isUpdate = false;
50 50
             $this->dto->setLastUpdate(new \DateTime());
51
-            if($this->isNew()) {
51
+            if ($this->isNew()) {
52 52
                 $this->preInsert($con);
53 53
                 $isInsert = true;
54 54
             } elseif ($this->isModified()) {
@@ -56,17 +56,17 @@  discard block
 block discarded – undo
56 56
                 $isUpdate = true;
57 57
             }
58 58
             $result = $collection->insertOne($this->toArray());
59
-            if($result->getInsertedCount() > 0) {
59
+            if ($result->getInsertedCount() > 0) {
60 60
                 $id = $result->getInsertedId();
61 61
                 $this->dto->setPk($id->jsonSerialize()['$oid']);
62
-                if($isInsert) {
62
+                if ($isInsert) {
63 63
                     $this->postInsert($con);
64
-                } elseif($isUpdate) {
64
+                } elseif ($isUpdate) {
65 65
                     $this->postUpdate($con);
66 66
                 }
67 67
                 $saved = true;
68 68
             }
69
-        } catch(\Exception $exception) {
69
+        } catch (\Exception $exception) {
70 70
             Logger::log($exception, LOG_CRIT, $this->toArray());
71 71
         }
72 72
         return $saved;
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
      */
79 79
     public function update(Database $con = null) {
80 80
         $updated = false;
81
-        if(null === $con) {
81
+        if (null === $con) {
82 82
             $con = ParserService::getInstance()->createConnection($this->getDomain());
83 83
         }
84 84
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
             $collection->findOneAndReplace(['_id' => new ObjectId($this->dto->getPk())], $data);
91 91
             $this->postUpdate($con);
92 92
             $updated = true;
93
-        } catch(\Exception $exception) {
93
+        } catch (\Exception $exception) {
94 94
             Logger::log($exception, LOG_CRIT, $this->toArray());
95 95
         }
96 96
         return $updated;
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 
101 101
     public function delete(Database $con = null) {
102 102
         $deleted = false;
103
-        if(null === $con) {
103
+        if (null === $con) {
104 104
             $con = ParserService::getInstance()->createConnection($this->getDomain());
105 105
         }
106 106
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
             $this->postDelete($con);
111 111
             $deleted = true;
112 112
             $this->dto = null;
113
-        } catch(\Exception $exception) {
113
+        } catch (\Exception $exception) {
114 114
             Logger::log($exception, LOG_CRIT, $this->toArray());
115 115
         }
116 116
         return $deleted;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
     public static function findPk($pk, Database $con = null) {
125 125
         $modelName = get_called_class();
126 126
         $model = new $modelName();
127
-        if(null === $con) {
127
+        if (null === $con) {
128 128
             $con = ParserService::getInstance()->createConnection($model->getDomain());
129 129
         }
130 130
         $collection = $con->selectCollection($model->getSchema()->name);
Please login to merge, or discard this patch.
src/NOSQL/Models/base/NOSQLModelTrait.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
     public function __get($name)
24 24
     {
25 25
         $value = null;
26
-        if(null !== $this->dto && property_exists($this->dto, $name)) {
26
+        if (null !== $this->dto && property_exists($this->dto, $name)) {
27 27
             $value = $this->dto->$name;
28 28
         }
29 29
         return $value;
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
      */
36 36
     public function __set($name, $value)
37 37
     {
38
-        if(null !== $this->dto && property_exists($this->dto, $name)) {
38
+        if (null !== $this->dto && property_exists($this->dto, $name)) {
39 39
             $this->dto->$name = $value;
40 40
             $this->addChanges($name);
41 41
         }
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
 
45 45
     public function __call($name, $arguments)
46 46
     {
47
-        if(preg_match('/^(set|get)/', $name)) {
47
+        if (preg_match('/^(set|get)/', $name)) {
48 48
             $property = str_replace(['set', 'Set', 'get', 'Get'], '', $name);
49
-            if(false !== stripos($name, 'set')) {
49
+            if (false !== stripos($name, 'set')) {
50 50
                 $this->$property = $arguments[0];
51 51
             } else {
52 52
                 return $this->$property;
@@ -60,10 +60,10 @@  discard block
 block discarded – undo
60 60
      * @throws \NOSQL\Exceptions\NOSQLValidationException
61 61
      */
62 62
     public function feed(array $data) {
63
-        foreach($data as $key => $value) {
64
-            if($value instanceof ObjectId) {
63
+        foreach ($data as $key => $value) {
64
+            if ($value instanceof ObjectId) {
65 65
                 $this->dto->setPk($value->jsonSerialize()['$oid']);
66
-            } elseif($key === '_last_update') {
66
+            } elseif ($key === '_last_update') {
67 67
                 $this->dto->setLastUpdate(\DateTime::createFromFormat(\DateTime::ATOM, $value));
68 68
             } else {
69 69
                 $this->$key = $value;
Please login to merge, or discard this patch.
src/NOSQL/Models/base/NOSQLStatusTrait.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@
 block discarded – undo
71 71
      * @param string $property
72 72
      */
73 73
     public function addChanges($property) {
74
-        if(!in_array($property, $this->changes)) {
74
+        if (!in_array($property, $this->changes)) {
75 75
             $this->changes[] = $property;
76 76
         }
77 77
     }
Please login to merge, or discard this patch.
src/NOSQL/Models/base/NOSQLParserTrait.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -69,17 +69,17 @@
 block discarded – undo
69 69
      * @throws \PSFS\base\exception\GeneratorException
70 70
      */
71 71
     protected function hydrate() {
72
-        if(empty($this->domain)) {
72
+        if (empty($this->domain)) {
73 73
             throw new NOSQLParserException(t('Domain not defined'), NOSQLParserException::NOSQL_PARSER_DOMAIN_NOT_DEFINED);
74 74
         }
75 75
         $schemaFilename = CORE_DIR . DIRECTORY_SEPARATOR . $this->domain . DIRECTORY_SEPARATOR . 'Config' . DIRECTORY_SEPARATOR . 'schema.json';
76
-        if(file_exists($schemaFilename)) {
76
+        if (file_exists($schemaFilename)) {
77 77
             $schema = Cache::getInstance()->getDataFromFile($schemaFilename, Cache::JSON, true);
78 78
             $class = get_called_class();
79 79
             $this->schema = new CollectionDto(false);
80
-            foreach($schema as $collection) {
80
+            foreach ($schema as $collection) {
81 81
                 $collectionName = $collection['name'];
82
-                if(false !== strpos($class, $collectionName)) {
82
+                if (false !== strpos($class, $collectionName)) {
83 83
                     $this->schema->fromArray($collection);
84 84
                     break;
85 85
                 }
Please login to merge, or discard this patch.
src/NOSQL/Dto/Model/NOSQLModelDto.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
      */
32 32
     public function setPk(string $id)
33 33
     {
34
-        if(!empty($this->_id)) {
34
+        if (!empty($this->_id)) {
35 35
             throw new NOSQLValidationException(t('Primary key already defined'), NOSQLValidationException::NOSQL_VALIDATION_ID_ALREADY_DEFINED);
36 36
         }
37 37
         $this->_id = $id;
@@ -69,43 +69,43 @@  discard block
 block discarded – undo
69 69
     public function validate($throwException = false) {
70 70
         $errors = [];
71 71
         $reflection = new \ReflectionClass(self::class);
72
-        foreach($reflection->getProperties() as $property) {
72
+        foreach ($reflection->getProperties() as $property) {
73 73
             $type = InjectorHelper::extractVarType($property->getDocComment());
74 74
             $required = InjectorHelper::checkIsRequired($property->getDocComment());
75 75
             $value = $property->getValue($this);
76
-            if($required && empty($value)) {
77
-                if($throwException) {
76
+            if ($required && empty($value)) {
77
+                if ($throwException) {
78 78
                     throw new NOSQLValidationException(t('Empty value for property ') . $property->getName(), NOSQLValidationException::NOSQL_VALIDATION_REQUIRED);
79 79
                 } else {
80 80
                     $errors[] = $property->getName();
81 81
                 }
82 82
             } else {
83
-                switch(strtolower($type)) {
83
+                switch (strtolower($type)) {
84 84
                     case NOSQLBase::NOSQL_TYPE_LONG:
85 85
                     case NOSQLBase::NOSQL_TYPE_INTEGER:
86 86
                     case NOSQLBase::NOSQL_TYPE_DOUBLE:
87
-                        if(!is_numeric($value)) {
87
+                        if (!is_numeric($value)) {
88 88
                             $errors[] = $property->getName();
89 89
                         }
90 90
                     break;
91 91
                     case NOSQLBase::NOSQL_TYPE_ENUM:
92 92
                         $values = explode('|', InjectorHelper::getValues($property->getDocComment()));
93
-                        if(!in_array($value, $values)) {
93
+                        if (!in_array($value, $values)) {
94 94
                             $errors[] = $property->getName();
95 95
                         }
96 96
                     break;
97 97
                     case NOSQLBase::NOSQL_TYPE_ARRAY:
98
-                        if(!is_array($value)) {
98
+                        if (!is_array($value)) {
99 99
                             $errors[] = $property->getName();
100 100
                         }
101 101
                     break;
102 102
                     case NOSQLBase::NOSQL_TYPE_BOOLEAN:
103
-                        if(!in_array($value, [true, false, 0, 1])) {
103
+                        if (!in_array($value, [true, false, 0, 1])) {
104 104
                             $errors[] = $property->getName();
105 105
                         }
106 106
                     break;
107 107
                 }
108
-                if(in_array($property->getName(), $errors) && $throwException) {
108
+                if (in_array($property->getName(), $errors) && $throwException) {
109 109
                     throw new NOSQLValidationException(t('Format not valid for property ') . $property->getName(), NOSQLValidationException::NOSQL_VALIDATION_NOT_VALID);
110 110
                 }
111 111
             }
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
     public function toArray()
117 117
     {
118 118
         $array = parent::toArray();
119
-        if(null !== $this->getPk()) {
119
+        if (null !== $this->getPk()) {
120 120
             $array['_id'] = $this->getPk();
121 121
         }
122 122
         $array['_last_update'] = $this->getLastUpdate(\DateTime::ATOM);
Please login to merge, or discard this patch.