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
Coding Style
introduced
by
![]() |
|||
9 | * @copyright Copyright (c) 2017 nystudio107 |
||
0 ignored issues
–
show
|
|||
10 | */ |
||
0 ignored issues
–
show
|
|||
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
|
|||
21 | * @author nystudio107 |
||
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
![]() |
|||
22 | * @package Recipe |
||
0 ignored issues
–
show
|
|||
23 | * @since 1.3.0 |
||
0 ignored issues
–
show
|
|||
24 | */ |
||
0 ignored issues
–
show
|
|||
25 | class NutritionApiController extends Controller |
||
26 | { |
||
27 | /** |
||
28 | * Returns nutritional information about a recipe. |
||
29 | * |
||
30 | * @throws BadRequestHttpException |
||
31 | */ |
||
0 ignored issues
–
show
|
|||
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
|
|||
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.
![]() |
|||
43 | } |
||
44 | |||
45 | $nutritionalInfo = Recipe::$plugin->nutritionApi->getNutritionalInfo($ingredients, $serves); |
||
46 | |||
47 | return $this->asJson($nutritionalInfo); |
||
48 | } |
||
49 | } |
||
50 |