Test Setup Failed
Branch master (7e6f9d)
by Rodrigo
03:08
created
Category
src/BaseApiController.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
70 70
 
71 71
         // Verificar autorização do modulo
72
-        if( $modulo = Yii::$app->request->get('modulo') ){
72
+        if ($modulo = Yii::$app->request->get('modulo')) {
73 73
             self::can($modulo);
74 74
         }
75 75
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      */
87 87
     public function actionIndex()
88 88
     {        
89
-        return $this->json( true, [
89
+        return $this->json(true, [
90 90
             'name' => Yii::$app->controller->id.'/status',
91 91
             'message' => 'API está funcionando!'
92 92
         ]);
@@ -109,52 +109,52 @@  discard block
 block discarded – undo
109 109
         $count = $dataProvider->getCount();
110 110
 
111 111
         // Verifica foi encontrado registros
112
-        if($count == 0){
113
-            throw new HttpException(404,'Nenhum registro foi encontrado!');
112
+        if ($count == 0) {
113
+            throw new HttpException(404, 'Nenhum registro foi encontrado!');
114 114
         }
115 115
 
116 116
         // incluir arquivos junto ao registro?
117
-        if ($files){
117
+        if ($files) {
118 118
             // instanciado data
119 119
             $data = array();
120 120
 
121 121
             // Adiciona arquivos aos registros
122 122
             foreach ($models as $key =>  $model) {
123 123
                 // convert model to array
124
-                $data []= ArrayHelper::toArray($model);
124
+                $data [] = ArrayHelper::toArray($model);
125 125
                 
126 126
                 // modulo possui arquivo unico
127
-                if ($model->canGetProperty('arquivo')){
127
+                if ($model->canGetProperty('arquivo')) {
128 128
                     // adicionar arquivo unico
129
-                    if($arquivo = $model->arquivo){
129
+                    if ($arquivo = $model->arquivo) {
130 130
                         //importar arquivo para o registro
131 131
                         self::importFile($data[$key]['files'], $arquivo, $modulo, $size, 'arquivo');
132 132
                     }
133 133
                 }
134 134
 
135 135
                 // modulo possui arquivo unico
136
-                if ($model->canGetProperty('id_banner')){
136
+                if ($model->canGetProperty('id_banner')) {
137 137
                     // adicionar arquivo unico
138
-                    if($arquivo = $model->banner){
138
+                    if ($arquivo = $model->banner) {
139 139
                         //importar arquivo para o registro
140 140
                         self::importFile($data[$key]['files'], $arquivo, $modulo, $size, 'banner');
141 141
                     }
142 142
                 }
143 143
 
144 144
                 // modulo possui arquivo unico
145
-                if ($model->canGetProperty('id_capa')){
145
+                if ($model->canGetProperty('id_capa')) {
146 146
                     // adicionar arquivo unico
147
-                    if($arquivo = $model->capa){
147
+                    if ($arquivo = $model->capa) {
148 148
                         //importar arquivo para o registro
149 149
                         self::importFile($data[$key]['files'], $arquivo, $modulo, $size, 'capa');
150 150
                     }
151 151
                 }
152 152
 
153 153
                 // modulo possui arquivos multiplos
154
-                if ($model->canGetProperty('arquivos')){
154
+                if ($model->canGetProperty('arquivos')) {
155 155
                     // adicionar arquivos multiplos
156
-                    if($arquivos = $model->arquivos){
157
-                        foreach($arquivos as $arquivo){
156
+                    if ($arquivos = $model->arquivos) {
157
+                        foreach ($arquivos as $arquivo) {
158 158
                             // importar arquivo para o registro
159 159
                             self::importFile($data[$key]['files'], $arquivo, $modulo, $size, 'arquivos');
160 160
                         }
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
         }
165 165
 
166 166
         // Output
167
-        return $this->json($files? $data: $models, ['count' => $count]);
167
+        return $this->json($files ? $data : $models, ['count' => $count]);
168 168
     }
169 169
 
170 170
     /**
@@ -185,22 +185,22 @@  discard block
 block discarded – undo
185 185
         $count = $dataProvider->getCount();
186 186
 
187 187
         // Verifica foi encontrado registros
188
-        if($count == 0){
189
-            throw new HttpException(404,'Nenhum registro foi encontrado!');
188
+        if ($count == 0) {
189
+            throw new HttpException(404, 'Nenhum registro foi encontrado!');
190 190
         }
191 191
 
192 192
         $model = array_shift($models);
193 193
         $arquivos = array();
194 194
 
195
-        if ($model->canGetProperty('arquivo')){
196
-            if($arquivo = $model->arquivo){
195
+        if ($model->canGetProperty('arquivo')) {
196
+            if ($arquivo = $model->arquivo) {
197 197
                 self::importFile($arquivos, $arquivo, $modulo, $size, 'arquivo');
198 198
             }
199 199
         }
200 200
         
201
-        if ($model->canGetProperty('arquivos')){
202
-            if($arquivos = $model->arquivos){
203
-                foreach($arquivos as $arquivo){
201
+        if ($model->canGetProperty('arquivos')) {
202
+            if ($arquivos = $model->arquivos) {
203
+                foreach ($arquivos as $arquivo) {
204 204
                     self::importFile($arquivos, $arquivo, $modulo, $size, 'arquivos');
205 205
                 }
206 206
             }
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
 
212 212
 
213 213
         // Verifica foi encontrado registros
214
-        if($count == 0){
215
-            throw new HttpException(404,'Nenhum arquivo foi encontrado!');
214
+        if ($count == 0) {
215
+            throw new HttpException(404, 'Nenhum arquivo foi encontrado!');
216 216
         }
217 217
 
218 218
         
@@ -239,14 +239,14 @@  discard block
 block discarded – undo
239 239
         $count = $dataProvider->getCount();
240 240
 
241 241
         // Verifica foi encontrado registros
242
-        if($count == 0){
243
-            throw new HttpException(404,'Nenhum Banner foi encontrado!');
242
+        if ($count == 0) {
243
+            throw new HttpException(404, 'Nenhum Banner foi encontrado!');
244 244
         }
245 245
 
246 246
         $data = array();
247 247
 
248 248
         foreach ($models as $model) {
249
-            $data []= $model->arquivo->getFileUrl('banner', $prefix);
249
+            $data [] = $model->arquivo->getFileUrl('banner', $prefix);
250 250
         }
251 251
         
252 252
         return $this->json($data, ['count' => $count]);
@@ -291,14 +291,14 @@  discard block
 block discarded – undo
291 291
     private static function importFile(&$arquivos, $arquivo, $modulo, $size, $local = 'desconhecido')
292 292
     {
293 293
         // não executar quando não houver arquivo para importar
294
-        if($arquivo === null){
294
+        if ($arquivo === null) {
295 295
             return false;
296 296
         }
297 297
 
298
-        $prefix = $arquivo->tipo == $arquivo::TIPO_IMAGEM ? $size:''; // prefixo tamano da imagem
298
+        $prefix = $arquivo->tipo == $arquivo::TIPO_IMAGEM ? $size : ''; // prefixo tamano da imagem
299 299
         $url = Url::to($arquivo->getFileUrl($modulo, $prefix), true); // Url Absoluta
300 300
 
301
-        $arquivos []= [
301
+        $arquivos [] = [
302 302
             'local' =>  $local,
303 303
             'url' =>  $url            
304 304
         ];
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
      */
347 347
     private static function can($modulo)
348 348
     {
349
-        if( array_search($modulo, static::modulos()) === false ){
349
+        if (array_search($modulo, static::modulos()) === false) {
350 350
             throw new HttpException(403, 'Não autorizado!');
351 351
         }
352 352
     }
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
         $url = Url::base(true).'/';
367 367
 
368 368
         // não tem o que substituir
369
-        if(!isset($database[0]['descricao'])){
369
+        if (!isset($database[0]['descricao'])) {
370 370
             return $database;
371 371
         }
372 372
 
Please login to merge, or discard this patch.