Completed
Push — master ( 957a77...d1fc9e )
by Fran
02:04
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/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/Controller/base/NOSQLBaseController.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,14 +14,14 @@
 block discarded – undo
14 14
     const DOMAIN = 'NOSQL';
15 15
 
16 16
     /**
17
-    * @Autoload
18
-    * @var \NOSQL\Services\NOSQLService
19
-    */
17
+     * @Autoload
18
+     * @var \NOSQL\Services\NOSQLService
19
+     */
20 20
     protected $srv;
21 21
 
22 22
     /**
23
-    * Constructor por defecto
24
-    */
23
+     * Constructor por defecto
24
+     */
25 25
     function __construct() {
26 26
         $this->init();
27 27
         $this->setDomain('NOSQL')
Please login to merge, or discard this patch.
src/NOSQL/Controller/NOSQLController.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -14,14 +14,14 @@
 block discarded – undo
14 14
 class NOSQLController extends NOSQLBaseController {
15 15
 
16 16
     /**
17
-    * Index
18
-    * @GET
19
-    * @label  Admin nosql composer
20
-    * @action true
21
-    * @visible true
22
-    * @route /admin/nosql
23
-    * @return string HTML
24
-    */
17
+     * Index
18
+     * @GET
19
+     * @label  Admin nosql composer
20
+     * @action true
21
+     * @visible true
22
+     * @route /admin/nosql
23
+     * @return string HTML
24
+     */
25 25
     public function index() {
26 26
         return $this->render('index.html.twig');
27 27
     }
Please login to merge, or discard this patch.
src/NOSQL/Services/ParserService.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
         $dns .= '@' . Config::getParam('nosql.host', 'localhost', $lowerDomain);
28 28
 
29 29
         $database = Config::getParam('nosql.database', 'nosql', $lowerDomain);
30
-        if(null !== Config::getParam('nosql.replicaset')) {
30
+        if (null !== Config::getParam('nosql.replicaset')) {
31 31
             $dns .= '/' . $database . '?ssl=true&replicaSet=' . Config::getParam('nosql.replicaset', null, $lowerDomain);
32 32
             $dns .= '&authSource=admin&serverSelectionTryOnce=false&serverSelectionTimeoutMS=15000&retryWrites=true';
33 33
         } else {
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      */
49 49
     public function checkAndSave($domain, $collection, NOSQLModelDto $dto) {
50 50
         $errors = $dto->validate();
51
-        if(empty($errors)) {
51
+        if (empty($errors)) {
52 52
 
53 53
         } else {
54 54
             throw new ApiException(t('Dto not valid'), 400);
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     public function hydrateModelFromRequest(array $data, $className) {
65 65
         $model = null;
66 66
         $reflectionClass = new \ReflectionClass($className);
67
-        if($reflectionClass->isSubclassOf(NOSQLBase::class)) {
67
+        if ($reflectionClass->isSubclassOf(NOSQLBase::class)) {
68 68
             /** @var NOSQLActiveRecord $modelName */
69 69
             $modelName = $className::MODEL_CLASS;
70 70
             $model = $modelName::fromArray($data);
Please login to merge, or discard this patch.
src/NOSQL/Services/NOSQLService.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
      */
57 57
     private function extractTypes() {
58 58
         $baseClass = new \ReflectionClass(NOSQLBase::class);
59
-        if(null !== $baseClass) {
59
+        if (null !== $baseClass) {
60 60
             $types = [];
61
-            foreach($baseClass->getConstants() as $constant) {
61
+            foreach ($baseClass->getConstants() as $constant) {
62 62
                 $types[] = $constant;
63 63
             }
64 64
             $this->setTypes($types);
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
     public function getDomains() {
81 81
         $domains = [];
82 82
         $storedDomains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', Cache::JSON, TRUE);
83
-        if(!empty($storedDomains)) {
84
-            foreach($storedDomains as $domain => $data) {
83
+        if (!empty($storedDomains)) {
84
+            foreach ($storedDomains as $domain => $data) {
85 85
                 $domainLabel = str_replace(['@', '/'], '', $domain);
86
-                if('ROOT' !== $domainLabel) {
86
+                if ('ROOT' !== $domainLabel) {
87 87
                     $domains[] = $domainLabel;
88 88
                 }
89 89
             }
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
     public function getCollections($module) {
99 99
         $collections = [];
100 100
         $schemaFilename = CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Config' . DIRECTORY_SEPARATOR . 'schema.json';
101
-        if(file_exists($schemaFilename)) {
101
+        if (file_exists($schemaFilename)) {
102 102
             $collections = $this->cache->getDataFromFile($schemaFilename, Cache::JSON, TRUE);
103 103
         }
104 104
         return $collections;
@@ -121,10 +121,10 @@  discard block
 block discarded – undo
121 121
             '@NOSQL/generator/api.base.php.twig' => CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Api' . DIRECTORY_SEPARATOR . 'Base',
122 122
             '@NOSQL/generator/dto.php.twig' => CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Dto' . DIRECTORY_SEPARATOR . 'Models',
123 123
         ];
124
-        foreach($collections as $raw) {
124
+        foreach ($collections as $raw) {
125 125
             $collection = new CollectionDto(false);
126 126
             $collection->fromArray($raw);
127
-            foreach($files as $template => $path) {
127
+            foreach ($files as $template => $path) {
128 128
                 GeneratorHelper::createDir($path);
129 129
                 $templateDump = $tpl->dump($template, [
130 130
                     'domain' => $module,
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
                     'properties' => $collection->properties,
133 133
                 ]);
134 134
                 $force = false;
135
-                if(false !== strpos($template, 'dto') || false !== strpos(strtolower($template), 'base')) {
135
+                if (false !== strpos($template, 'dto') || false !== strpos(strtolower($template), 'base')) {
136 136
                     $force = true;
137 137
                 }
138 138
                 $this->writeTemplateToFile($templateDump, $path . DIRECTORY_SEPARATOR . $collection->name . '.php', $force);
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
         $db = ParserService::getInstance()->createConnection($module);
172 172
         $collections = $this->getCollections($module);
173 173
         $success = true;
174
-        foreach($collections as $raw) {
174
+        foreach ($collections as $raw) {
175 175
             $jsonSchema = $this->parseCollection($raw);
176 176
             try {
177 177
                 /** @var BSONDocument $result */
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
                 ]);
183 183
                 $response = $result->getArrayCopy();
184 184
                 $success = array_key_exists('ok', $response) && $response['ok'] > 0;
185
-            } catch(\Exception $exception) {
186
-                if($exception->getCode() !== 48) {
185
+            } catch (\Exception $exception) {
186
+                if ($exception->getCode() !== 48) {
187 187
                     $success = false;
188 188
                 }
189 189
             }
@@ -214,10 +214,10 @@  discard block
 block discarded – undo
214 214
                     $property = new StringPropertyDto(false);
215 215
                     break;
216 216
             }
217
-            if(array_key_exists('type', $rawProperty)) {
217
+            if (array_key_exists('type', $rawProperty)) {
218 218
                 $property->bsonType = $rawProperty['type'];
219 219
             }
220
-            if(array_key_exists('description', $rawProperty)) {
220
+            if (array_key_exists('description', $rawProperty)) {
221 221
                 $property->description = $rawProperty['description'];
222 222
             }
223 223
             if (array_key_exists('required', $rawProperty) && $rawProperty['required']) {
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
     public function getValidations() {
236 236
         $fieldTypes = new \ReflectionClass(Field::class);
237 237
         $validations = [];
238
-        foreach($fieldTypes->getConstants() as $validation) {
238
+        foreach ($fieldTypes->getConstants() as $validation) {
239 239
             $validations[] = $validation;
240 240
         }
241 241
         return $validations;
Please login to merge, or discard this patch.
src/NOSQL/Services/Helpers/NOSQLApiHelper.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     public static function parseForm(CollectionDto $collectionDto) {
34 34
         $form = new Form(false);
35 35
         $form->addField(self::generateId());
36
-        foreach($collectionDto->properties as $property) {
36
+        foreach ($collectionDto->properties as $property) {
37 37
             $values = null;
38 38
             $data = [];
39 39
             $url = null;
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
                 case NOSQLBase::NOSQL_TYPE_ENUM:
59 59
                     $type = Field::COMBO_TYPE;
60 60
                     $enumValues = explode('|', $property->enum);
61
-                    foreach($enumValues as $value) {
61
+                    foreach ($enumValues as $value) {
62 62
                         $data[] = [
63 63
                             $property->name => $value,
64 64
                             'Label' => t($value),
Please login to merge, or discard this patch.
src/NOSQL/Models/NOSQLActiveRecord.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
      */
44 44
     public function getDtoCopy($cleanPk = false) {
45 45
         $copy = clone $this->dto;
46
-        if($cleanPk) {
46
+        if ($cleanPk) {
47 47
             $this->dto->resetPk();
48 48
         }
49 49
         return $copy;
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      */
60 60
     public function save(Database $con = null) {
61 61
         $saved = false;
62
-        if(null === $con) {
62
+        if (null === $con) {
63 63
             $con = ParserService::getInstance()->createConnection($this->getDomain());
64 64
         }
65 65
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
             $isInsert = $isUpdate = false;
68 68
             $this->prepareData();
69 69
             $this->dto->setLastUpdate();
70
-            if($this->isNew()) {
70
+            if ($this->isNew()) {
71 71
                 $this->preInsert($con);
72 72
                 $isInsert = true;
73 73
             } elseif ($this->isModified()) {
@@ -75,19 +75,19 @@  discard block
 block discarded – undo
75 75
                 $isUpdate = true;
76 76
             }
77 77
             $result = $collection->insertOne($this->toArray());
78
-            if($result->getInsertedCount() > 0) {
78
+            if ($result->getInsertedCount() > 0) {
79 79
                 $id = $result->getInsertedId();
80 80
                 $this->dto->setPk($id->jsonSerialize()['$oid']);
81
-                if($isInsert) {
81
+                if ($isInsert) {
82 82
                     $this->postInsert($con);
83
-                } elseif($isUpdate) {
83
+                } elseif ($isUpdate) {
84 84
                     $this->postUpdate($con);
85 85
                 }
86 86
                 $saved = true;
87 87
                 $this->countAction();
88 88
             }
89
-        } catch(\Exception $exception) {
90
-            if($exception instanceof NOSQLValidationException) {
89
+        } catch (\Exception $exception) {
90
+            if ($exception instanceof NOSQLValidationException) {
91 91
                 throw $exception;
92 92
             } else {
93 93
                 Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray());
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      */
103 103
     public function update(Database $con = null) {
104 104
         $updated = false;
105
-        if(null === $con) {
105
+        if (null === $con) {
106 106
             $con = ParserService::getInstance()->createConnection($this->getDomain());
107 107
         }
108 108
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
             $this->postUpdate($con);
117 117
             $updated = true;
118 118
             $this->countAction();
119
-        } catch(\Exception $exception) {
120
-            if($exception instanceof NOSQLValidationException) {
119
+        } catch (\Exception $exception) {
120
+            if ($exception instanceof NOSQLValidationException) {
121 121
                 throw $exception;
122 122
             } else {
123 123
                 Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray());
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
      */
134 134
     public function bulkInsert(array $data, Database $con = null) {
135 135
         $inserts = 0;
136
-        if(null === $con) {
136
+        if (null === $con) {
137 137
             $con = ParserService::getInstance()->createConnection($this->getDomain());
138 138
         }
139 139
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
             $ids = $result->getInsertedIds();
144 144
             $inserts = $this->parseInsertedDtos($con, $ids, $dtos);
145 145
             $this->setActionCount($inserts);
146
-        } catch(\Exception $exception) {
146
+        } catch (\Exception $exception) {
147 147
             Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray());
148 148
         }
149 149
         return $inserts;
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
      */
156 156
     public function delete(Database $con = null) {
157 157
         $deleted = false;
158
-        if(null === $con) {
158
+        if (null === $con) {
159 159
             $con = ParserService::getInstance()->createConnection($this->getDomain());
160 160
         }
161 161
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
             $deleted = true;
167 167
             $this->dto = null;
168 168
             $this->countAction();
169
-        } catch(\Exception $exception) {
169
+        } catch (\Exception $exception) {
170 170
             Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray());
171 171
         }
172 172
         return $deleted;
Please login to merge, or discard this patch.