Passed
Branch v1 (0086d5)
by Andrew
05:40
created
Category
src/models/Recipe.php 1 patch
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
     /**
51 51
      * @var array
52 52
      */
53
-    public $ingredients = [];
53
+    public $ingredients = [ ];
54 54
 
55 55
     /**
56 56
      * @var array
57 57
      */
58
-    public $directions = [];
58
+    public $directions = [ ];
59 59
 
60 60
     /**
61 61
      * @var int
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
     /**
81 81
      * @var array
82 82
      */
83
-    public $ratings = [];
83
+    public $ratings = [ ];
84 84
 
85 85
     /**
86 86
      * @var string
@@ -151,27 +151,27 @@  discard block
 block discarded – undo
151 151
     public function rules()
152 152
     {
153 153
         return [
154
-            ['name', 'string'],
155
-            ['name', 'default', 'value' => ''],
156
-            ['description', 'string'],
157
-            ['skill', 'string'],
158
-            ['serves', 'integer'],
159
-            ['imageId', 'integer'],
160
-            ['prepTime', 'integer'],
161
-            ['cookTime', 'integer'],
162
-            ['totalTime', 'integer'],
163
-            ['servingSize', 'string'],
164
-            ['calories', 'integer'],
165
-            ['carbohydrateContent', 'integer'],
166
-            ['cholesterolContent', 'integer'],
167
-            ['fatContent', 'integer'],
168
-            ['fiberContent', 'integer'],
169
-            ['proteinContent', 'integer'],
170
-            ['saturatedFatContent', 'integer'],
171
-            ['sodiumContent', 'integer'],
172
-            ['sugarContent', 'integer'],
173
-            ['transFatContent', 'integer'],
174
-            ['unsaturatedFatContent', 'integer'],
154
+            [ 'name', 'string' ],
155
+            [ 'name', 'default', 'value' => '' ],
156
+            [ 'description', 'string' ],
157
+            [ 'skill', 'string' ],
158
+            [ 'serves', 'integer' ],
159
+            [ 'imageId', 'integer' ],
160
+            [ 'prepTime', 'integer' ],
161
+            [ 'cookTime', 'integer' ],
162
+            [ 'totalTime', 'integer' ],
163
+            [ 'servingSize', 'string' ],
164
+            [ 'calories', 'integer' ],
165
+            [ 'carbohydrateContent', 'integer' ],
166
+            [ 'cholesterolContent', 'integer' ],
167
+            [ 'fatContent', 'integer' ],
168
+            [ 'fiberContent', 'integer' ],
169
+            [ 'proteinContent', 'integer' ],
170
+            [ 'saturatedFatContent', 'integer' ],
171
+            [ 'sodiumContent', 'integer' ],
172
+            [ 'sugarContent', 'integer' ],
173
+            [ 'transFatContent', 'integer' ],
174
+            [ 'unsaturatedFatContent', 'integer' ],
175 175
         ];
176 176
     }
177 177
 
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
             'unsaturatedFatContent' => $this->unsaturatedFatContent,
213 213
         ];
214 214
         $nutrition = array_filter($nutrition);
215
-        $recipeJSONLD['nutrition'] = $nutrition;
216
-        if (count($recipeJSONLD['nutrition']) == 1) {
217
-            unset($recipeJSONLD['nutrition']);
215
+        $recipeJSONLD[ 'nutrition' ] = $nutrition;
216
+        if (count($recipeJSONLD[ 'nutrition' ]) == 1) {
217
+            unset($recipeJSONLD[ 'nutrition' ]);
218 218
         }
219 219
         $aggregateRating = $this->getAggregateRating();
220 220
         if ($aggregateRating) {
@@ -226,36 +226,36 @@  discard block
 block discarded – undo
226 226
                 'ratingValue' => $aggregateRating,
227 227
             ];
228 228
             $aggregateRatings = array_filter($aggregateRatings);
229
-            $recipeJSONLD['aggregateRating'] = $aggregateRatings;
229
+            $recipeJSONLD[ 'aggregateRating' ] = $aggregateRatings;
230 230
 
231
-            $reviews = [];
231
+            $reviews = [ ];
232 232
             foreach ($this->ratings as $rating) {
233 233
                 $review = [
234 234
                     "type" => "Review",
235
-                    'author' => $rating['author'],
235
+                    'author' => $rating[ 'author' ],
236 236
                     'name' => $this->name." ".Craft::t("recipe", "Review"),
237
-                    'description' => $rating['review'],
237
+                    'description' => $rating[ 'review' ],
238 238
                     'reviewRating' => [
239 239
                         "type" => "Rating",
240 240
                         'bestRating' => '5',
241 241
                         'worstRating' => '1',
242
-                        'ratingValue' => $rating['rating'],
242
+                        'ratingValue' => $rating[ 'rating' ],
243 243
                     ],
244 244
                 ];
245 245
                 array_push($reviews, $review);
246 246
             }
247 247
             $reviews = array_filter($reviews);
248
-            $recipeJSONLD['review'] = $reviews;
248
+            $recipeJSONLD[ 'review' ] = $reviews;
249 249
         }
250 250
 
251 251
         if ($this->prepTime) {
252
-            $recipeJSONLD['prepTime'] = "PT".$this->prepTime."M";
252
+            $recipeJSONLD[ 'prepTime' ] = "PT".$this->prepTime."M";
253 253
         }
254 254
         if ($this->cookTime) {
255
-            $recipeJSONLD['cookTime'] = "PT".$this->cookTime."M";
255
+            $recipeJSONLD[ 'cookTime' ] = "PT".$this->cookTime."M";
256 256
         }
257 257
         if ($this->totalTime) {
258
-            $recipeJSONLD['totalTime'] = "PT".$this->totalTime."M";
258
+            $recipeJSONLD[ 'totalTime' ] = "PT".$this->totalTime."M";
259 259
         }
260 260
 
261 261
         return $this->renderJsonLd($recipeJSONLD, $raw);
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
     {
271 271
         $result = "";
272 272
         if (isset($this->imageId) && $this->imageId) {
273
-            $image = Craft::$app->getAssets()->getAssetById($this->imageId[0]);
273
+            $image = Craft::$app->getAssets()->getAssetById($this->imageId[ 0 ]);
274 274
             if ($image) {
275 275
                 $result = $image->url;
276 276
             }
@@ -290,65 +290,65 @@  discard block
 block discarded – undo
290 290
      */
291 291
     public function getIngredients($outputUnits = "imperial", $serving = 0, $raw = true)
292 292
     {
293
-        $result = [];
293
+        $result = [ ];
294 294
         foreach ($this->ingredients as $row) {
295 295
             $convertedUnits = "";
296 296
             $ingredient = "";
297
-            if ($row['quantity']) {
297
+            if ($row[ 'quantity' ]) {
298 298
                 // Multiply the quantity by how many servings we want
299 299
                 $multiplier = 1;
300 300
                 if ($serving > 0) {
301 301
                     $multiplier = $serving / $this->serves;
302 302
                 }
303
-                $quantity = $row['quantity'] * $multiplier;
303
+                $quantity = $row[ 'quantity' ] * $multiplier;
304 304
                 $originalQuantity = $quantity;
305 305
 
306 306
                 // Do the units conversion
307 307
 
308 308
                 if ($outputUnits == 'imperial') {
309
-                    if ($row['units'] == "mls") {
309
+                    if ($row[ 'units' ] == "mls") {
310 310
                         $convertedUnits = "tsps";
311 311
                         $quantity = $quantity * 0.2;
312 312
                     }
313 313
 
314
-                    if ($row['units'] == "ls") {
314
+                    if ($row[ 'units' ] == "ls") {
315 315
                         $convertedUnits = "cups";
316 316
                         $quantity = $quantity * 4.2;
317 317
                     }
318 318
 
319
-                    if ($row['units'] == "mgs") {
319
+                    if ($row[ 'units' ] == "mgs") {
320 320
                         $convertedUnits = "ozs";
321 321
                         $quantity = $quantity * 0.000035274;
322 322
                     }
323 323
 
324
-                    if ($row['units'] == "gs") {
324
+                    if ($row[ 'units' ] == "gs") {
325 325
                         $convertedUnits = "ozs";
326 326
                         $quantity = $quantity * 0.035274;
327 327
                     }
328 328
                 }
329 329
 
330 330
                 if ($outputUnits == 'metric') {
331
-                    if ($row['units'] == "tsps") {
331
+                    if ($row[ 'units' ] == "tsps") {
332 332
                         $convertedUnits = "mls";
333 333
                         $quantity = $quantity * 4.929;
334 334
                     }
335 335
 
336
-                    if ($row['units'] == "tbsps") {
336
+                    if ($row[ 'units' ] == "tbsps") {
337 337
                         $convertedUnits = "mls";
338 338
                         $quantity = $quantity * 14.787;
339 339
                     }
340 340
 
341
-                    if ($row['units'] == "flozs") {
341
+                    if ($row[ 'units' ] == "flozs") {
342 342
                         $convertedUnits = "mls";
343 343
                         $quantity = $quantity * 29.574;
344 344
                     }
345 345
 
346
-                    if ($row['units'] == "cups") {
346
+                    if ($row[ 'units' ] == "cups") {
347 347
                         $convertedUnits = "ls";
348 348
                         $quantity = $quantity * 0.236588;
349 349
                     }
350 350
 
351
-                    if ($row['units'] == "ozs") {
351
+                    if ($row[ 'units' ] == "ozs") {
352 352
                         $convertedUnits = "gs";
353 353
                         $quantity = $quantity * 28.3495;
354 354
                     }
@@ -363,8 +363,8 @@  discard block
 block discarded – undo
363 363
                 }
364 364
                 $ingredient .= $quantity;
365 365
 
366
-                if ($row['units']) {
367
-                    $units = $row['units'];
366
+                if ($row[ 'units' ]) {
367
+                    $units = $row[ 'units' ];
368 368
                     if ($convertedUnits) {
369 369
                         $units = $convertedUnits;
370 370
                     }
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
                     $ingredient .= " ".$units;
376 376
                 }
377 377
             }
378
-            if ($row['ingredient']) {
379
-                $ingredient .= " ".$row['ingredient'];
378
+            if ($row[ 'ingredient' ]) {
379
+                $ingredient .= " ".$row[ 'ingredient' ];
380 380
             }
381 381
             if ($raw) {
382 382
                 $ingredient = Template::raw($ingredient);
@@ -460,9 +460,9 @@  discard block
 block discarded – undo
460 460
      */
461 461
     public function getDirections($raw = true)
462 462
     {
463
-        $result = [];
463
+        $result = [ ];
464 464
         foreach ($this->directions as $row) {
465
-            $direction = $row['direction'];
465
+            $direction = $row[ 'direction' ];
466 466
             if ($raw) {
467 467
                 $direction = Template::raw($direction);
468 468
             }
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
         $total = 0;
484 484
         if (isset($this->ratings) && !empty($this->ratings)) {
485 485
             foreach ($this->ratings as $row) {
486
-                $result += $row['rating'];
486
+                $result += $row[ 'rating' ];
487 487
                 $total++;
488 488
             }
489 489
             $result = $result / $total;
Please login to merge, or discard this patch.
src/Recipe.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
         Event::on(
55 55
             Fields::class,
56 56
             Fields::EVENT_REGISTER_FIELD_TYPES,
57
-            function (RegisterComponentTypesEvent $event) {
58
-                $event->types[] = RecipeField::class;
57
+            function(RegisterComponentTypesEvent $event) {
58
+                $event->types[ ] = RecipeField::class;
59 59
             }
60 60
         );
61 61
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
         Event::on(
64 64
             Plugins::class,
65 65
             Plugins::EVENT_AFTER_INSTALL_PLUGIN,
66
-            function (PluginEvent $event) {
66
+            function(PluginEvent $event) {
67 67
                 if (!Craft::$app->getRequest()->getIsConsoleRequest()
68 68
                 && ($event->plugin === $this)) {
69 69
                     Craft::$app->getResponse()->redirect(UrlHelper::cpUrl('recipe/welcome'))->send();
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             Craft::t(
76 76
                 'recipe',
77 77
                 '{name} plugin loaded',
78
-                ['name' => $this->name]
78
+                [ 'name' => $this->name ]
79 79
             ),
80 80
             __METHOD__
81 81
         );
Please login to merge, or discard this patch.
src/fields/Recipe.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
     /**
36 36
      * @var array
37 37
      */
38
-    public $assetSources = [];
38
+    public $assetSources = [ ];
39 39
 
40 40
     // Static Methods
41 41
     // =========================================================================
@@ -128,12 +128,12 @@  discard block
 block discarded – undo
128 128
         Craft::$app->getView()->registerJs("$('#{$nameSpacedId}-field').RecipeRecipe(".$jsonVars.");");
129 129
 
130 130
         // Set asset elements
131
-        $elements = [];
131
+        $elements = [ ];
132 132
         if ($value->imageId) {
133 133
             if (is_array($value->imageId)) {
134
-                $value->imageId = $value->imageId[0];
134
+                $value->imageId = $value->imageId[ 0 ];
135 135
             }
136
-            $elements = [Craft::$app->getAssets()->getAssetById($value->imageId)];
136
+            $elements = [ Craft::$app->getAssets()->getAssetById($value->imageId) ];
137 137
         }
138 138
 
139 139
         // Render the input template
Please login to merge, or discard this patch.
src/helpers/Json.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@
 block discarded – undo
95 95
             return $array;
96 96
         }
97 97
         $keys = array_keys($array);
98
-        $keys[array_search($oldKey, $keys)] = $newKey;
98
+        $keys[ array_search($oldKey, $keys) ] = $newKey;
99 99
 
100 100
         return array_combine($keys, $array);
101 101
     }
Please login to merge, or discard this patch.