From 867d6711260517e72f28a8794a08f96cef73b79c Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 21 Sep 2023 00:17:39 +0000 Subject: [PATCH] style fixes --- basics/responses.md | 8 ++--- basics/routing.md | 74 +++++++++++++++++++++--------------------- services/validation.md | 4 +-- standards/php.md | 18 ++++------ 4 files changed, 50 insertions(+), 54 deletions(-) diff --git a/basics/responses.md b/basics/responses.md index 7f15522..db37cb9 100755 --- a/basics/responses.md +++ b/basics/responses.md @@ -66,11 +66,11 @@ In most cases the text/html response is created based on a `View` which has a te ```php public function controllerEndpoint(HttpRequest $request, HttpResponse $response, array $data = []) : RenderableInterface { - $view = new View($this->app->l11nManager, $request, $response); - $view->setTemplate('....'); - $view->setData('data_id', ....); + $view = new View($this->app->l11nManager, $request, $response); + $view->setTemplate('....'); + $view->setData('data_id', ....); - return $view; + return $view; } ``` diff --git a/basics/routing.md b/basics/routing.md index 1ffd81a..5d1c712 100755 --- a/basics/routing.md +++ b/basics/routing.md @@ -24,7 +24,7 @@ For routes it's possible to define a `\Closure` which will get returned upon usi ```php $router->add('foo/bar', function() { - return 'Hello World'; + return 'Hello World'; }); ``` @@ -32,7 +32,7 @@ Routes can have different verbs which are derived from the HTTP verbs. Routes th ```php $router->add('foo/bar', function() { - return 'Hello World'; + return 'Hello World'; }, RouteVerb::GET | RouteVerb::SET); ``` @@ -62,17 +62,17 @@ The routing file must have the following structure: ```php [ - [ - 'dest' => CLOSURE/REFERENCE_STRING, - 'verb' => VERB_1 | VERB_2, - ], - [ - 'dest' => CLOSURE/REFERENCE_STRING, - 'verb' => VERB_3, - ], - ], - '{ANOTHER_ROUTE_STRING}' => [ ... ], + '{ROUTE_STRING}' => [ + [ + 'dest' => CLOSURE/REFERENCE_STRING, + 'verb' => VERB_1 | VERB_2, + ], + [ + 'dest' => CLOSURE/REFERENCE_STRING, + 'verb' => VERB_3, + ], + ], + '{ANOTHER_ROUTE_STRING}' => [ ... ], ]; ``` @@ -108,22 +108,22 @@ $router->route('foo/bar', null, RouteVerb::GET, 'APP_NAME', ORG_ID, ACCOUNT); ```php [ - [ - 'dest' => CLOSURE/REFERENCE_STRING, - 'verb' => VERB_1 | VERB_2, - 'permission' => [ - 'module' => NAME, - 'type' => CREATE | READ | UPDATE | DELETE | PERMISSION, - 'state' => MODULE_SPECIFIC_IDENTIFIER_FOR_THE_PERMISSION, - ], - ], - [ - 'dest' => CLOSURE/REFERENCE_STRING, - 'verb' => VERB_3, - ], - ], - '{ANOTHER_ROUTE_STRING}' => [ ... ], + '{ROUTE_STRING}' => [ + [ + 'dest' => CLOSURE/REFERENCE_STRING, + 'verb' => VERB_1 | VERB_2, + 'permission' => [ + 'module' => NAME, + 'type' => CREATE | READ | UPDATE | DELETE | PERMISSION, + 'state' => MODULE_SPECIFIC_IDENTIFIER_FOR_THE_PERMISSION, + ], + ], + [ + 'dest' => CLOSURE/REFERENCE_STRING, + 'verb' => VERB_3, + ], + ], + '{ANOTHER_ROUTE_STRING}' => [ ... ], ]; ``` @@ -147,19 +147,19 @@ Often you would like to enable `CSRF` protection for certain urls or routing pat ```php $router->add('foo/bar', function() { - return 'Hello World'; - }, RouteVerb::GET | RouteVerb::SET, - true, // CSRF token is required + return 'Hello World'; + }, RouteVerb::GET | RouteVerb::SET, + true, // CSRF token is required ); ``` ```php $router->route( - 'foo/bar', - $request->getData('CSRF'), - RouteVerb::GET, - 'APP_NAME', - ORG_ID, ACCOUNT + 'foo/bar', + $request->getData('CSRF'), + RouteVerb::GET, + 'APP_NAME', + ORG_ID, ACCOUNT ); ``` diff --git a/services/validation.md b/services/validation.md index 101bd17..a3444fd 100755 --- a/services/validation.md +++ b/services/validation.md @@ -33,8 +33,8 @@ Example: ```php function functionName(mixed $var, $mySetting1, $mySetting2) : bool { - // Do some validation here - return true; + // Do some validation here + return true; } Validator::isValid($testVariable, ['functionName' => $settings]); diff --git a/standards/php.md b/standards/php.md index a1b357a..1e19d3d 100755 --- a/standards/php.md +++ b/standards/php.md @@ -2,7 +2,7 @@ The php code needs to be php 8.1 compliant. No php 8.1 deprecated or removed elements, functions or practices are allowed (e.g. short open tag). Please use the `phpcs.xml` configuration for PHP Code Sniffer to identify most of the basic code standards. -## Php Tags +## Php Tags PHP code MUST use the long `` tags or the short-echo `` tags; it MUST NOT use the other tag variations. @@ -31,10 +31,10 @@ or for multiline function parameters ```php function( - string $para1, - int $para2, - bool $para3, - array $para4 + string $para1, + int $para2, + bool $para3, + array $para4 ) : int { @@ -80,7 +80,7 @@ echo 'Hello' , 'World'; ## If -#### Elseif +### Elseif Use `elseif` where possible instead of `else if`. @@ -114,11 +114,7 @@ Instead of using `\file_exists()` the functions `\is_dir()` or `\is_file()` shou Don't use the internal enum implementations of PHP (neither `SplEnum` nor `enum`) -#### Model IDs - -Model IDs must always be private. They must not have a setter. Therfore most models need/should have a getter function which returns the model ID. - -#### Pseudo enums +### Pseudo enums Whenever a scalar coming from the internal enum data type (`\phpOMS\Stdlib\Base\Enum`) is used the variable should be private and a getter and setter should exist for additional type checks.