Issues (446)

src/controllers/NutritionApiController.php (20 issues)

1
<?php
2
/**
3
 * Recipe plugin for Craft CMS 3.x
4
 *
5
 * A comprehensive recipe FieldType for Craft CMS that includes metric/imperial
6
 * conversion, portion calculation, and JSON-LD microdata support
7
 *
8
 * @link      https://nystudio107.com
0 ignored issues
show
The tag in position 1 should be the @copyright tag
Loading history...
9
 * @copyright Copyright (c) 2017 nystudio107
0 ignored issues
show
@copyright tag must contain a year and the name of the copyright holder
Loading history...
10
 */
0 ignored issues
show
PHP version not specified
Loading history...
Missing @category tag in file comment
Loading history...
Missing @package tag in file comment
Loading history...
Missing @author tag in file comment
Loading history...
Missing @license tag in file comment
Loading history...
11
12
namespace nystudio107\recipe\controllers;
13
14
use Craft;
15
use craft\web\Controller;
16
use nystudio107\recipe\Recipe;
17
use yii\web\BadRequestHttpException;
18
use yii\web\Response;
19
20
/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
21
 * @author    nystudio107
0 ignored issues
show
The tag in position 1 should be the @package tag
Loading history...
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
22
 * @package   Recipe
0 ignored issues
show
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
23
 * @since     1.3.0
0 ignored issues
show
The tag in position 3 should be the @author tag
Loading history...
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
24
 */
0 ignored issues
show
Missing @category tag in class comment
Loading history...
Missing @license tag in class comment
Loading history...
Missing @link tag in class comment
Loading history...
25
class NutritionApiController extends Controller
26
{
27
    /**
28
     * Returns nutritional information about a recipe.
29
     *
30
     * @throws BadRequestHttpException
31
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
32
    public function actionGetNutritionalInfo(): Response
33
    {
34
        $this->requireAcceptsJson();
35
36
        $ingredients = Craft::$app->getRequest()->getParam('ingredients');
37
        $serves = Craft::$app->getRequest()->getParam('serves');
38
39
        if (empty($ingredients)) {
40
            return $this->asJson([
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
41
                'error' => 'Please provide some ingredients first.',
42
            ]);
0 ignored issues
show
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
43
        }
44
45
        $nutritionalInfo = Recipe::$plugin->nutritionApi->getNutritionalInfo($ingredients, $serves);
46
47
        return $this->asJson($nutritionalInfo);
48
    }
49
}
50