{"_path":"/guidelines-internal/development-php","_draft":false,"_partial":false,"_empty":false,"title":"Development: PHP","description":"","excerpt":{"type":"root","children":[{"type":"element","tag":"h1","props":{"id":"development-php"},"children":[{"type":"text","value":"Development: PHP"}]},{"type":"element","tag":"h2","props":{"id":"coding-style"},"children":[{"type":"text","value":"Coding Style"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"The PHP code style "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" follow the "},{"type":"element","tag":"a","props":{"href":"https://laravel.com/docs/8.x/contributions#coding-style","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"laravel coding style"}]},{"type":"text","value":". This includes the "},{"type":"element","tag":"a","props":{"href":"https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"PSR-2"}]},{"type":"text","value":" coding standart and the "},{"type":"element","tag":"a","props":{"href":"https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"PSR-4"}]},{"type":"text","value":" autoloading standard."}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"A different coding standard can be applied if a development environment in a framework different from laravel requires it."}]},{"type":"element","tag":"h3","props":{"id":"types"},"children":[{"type":"text","value":"Types"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"a","props":{"href":"https://github.com/aw-studio/guidelines/issues/19","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"Original discussion"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"All methods and functions "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" be type hinted as much as possible.In packages, however, care must be taken to ensure that typehints do not restrict inheritance and overwriting of classes for other uses."}]},{"type":"element","tag":"h3","props":{"id":"phpdoc"},"children":[{"type":"text","value":"PHPDoc"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"All methods "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" have docblocks that:"}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" contain a full sentence describing the purpose of the method."}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"SHOULD"}]},{"type":"text","value":" contain links to additional resources"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" contain all parameter types and names"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"SHOULD"}]},{"type":"text","value":" contain parameter descriptions (when the name is may not be self explaining)"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" contain the return type"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" contain all exception that are thrown directly by the method"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST NOT"}]},{"type":"text","value":" contain exceptions that are thrown by other methods on a higher level"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"The following shows an example class method and a corresponding docblock:"}]},{"type":"element","tag":"code","props":{"code":"/**\n * Register a binding with the container.\n *\n * @see https://example.org\n *\n * @param  string|array          $abstract  The abstract that the binding is named after\n * @param  \\Closure|string|null  $concrete\n * @param  bool                  $shared\n * @return void\n *\n * @throws \\Exception\n */\npublic function bind($abstract, $concrete = null, $shared = false)\n{\n    //\n}\n","language":"php"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"/**\n * Register a binding with the container.\n *\n * @see https://example.org\n *\n * @param  string|array          $abstract  The abstract that the binding is named after\n * @param  \\Closure|string|null  $concrete\n * @param  bool                  $shared\n * @return void\n *\n * @throws \\Exception\n */\npublic function bind($abstract, $concrete = null, $shared = false)\n{\n    //\n}\n"}]}]}]},{"type":"element","tag":"h2","props":{"id":"helpers"},"children":[{"type":"text","value":"Helpers"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Helpers are files that contain functions that are not wrapped inside of a class."}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"File names of helpers "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" be kebab-case."}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"The number of helpers within a project "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"SHOULD"}]},{"type":"text","value":" be reduced to the minimum. (It is recommended to have one helper named "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"helpers.php"}]},{"type":"text","value":")"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Helper functions "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" wrap existing methods and "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST NOT"}]},{"type":"text","value":" introduce new logic."}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"The purpose of helper methods "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" be solely to increase the readability of the code."}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Read the "},{"type":"element","tag":"a","props":{"href":"../../tutorials/php/helpers.md"},"children":[{"type":"text","value":"tutorial"}]},{"type":"text","value":" about how to register helpers."}]}]},"public":true,"body":{"type":"root","children":[{"type":"element","tag":"h1","props":{"id":"development-php"},"children":[{"type":"text","value":"Development: PHP"}]},{"type":"element","tag":"h2","props":{"id":"coding-style"},"children":[{"type":"text","value":"Coding Style"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"The PHP code style "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" follow the "},{"type":"element","tag":"a","props":{"href":"https://laravel.com/docs/8.x/contributions#coding-style","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"laravel coding style"}]},{"type":"text","value":". This includes the "},{"type":"element","tag":"a","props":{"href":"https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"PSR-2"}]},{"type":"text","value":" coding standart and the "},{"type":"element","tag":"a","props":{"href":"https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"PSR-4"}]},{"type":"text","value":" autoloading standard."}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"A different coding standard can be applied if a development environment in a framework different from laravel requires it."}]},{"type":"element","tag":"h3","props":{"id":"types"},"children":[{"type":"text","value":"Types"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"element","tag":"a","props":{"href":"https://github.com/aw-studio/guidelines/issues/19","rel":["nofollow","noopener","noreferrer"],"target":"_blank"},"children":[{"type":"text","value":"Original discussion"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"All methods and functions "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" be type hinted as much as possible.In packages, however, care must be taken to ensure that typehints do not restrict inheritance and overwriting of classes for other uses."}]},{"type":"element","tag":"h3","props":{"id":"phpdoc"},"children":[{"type":"text","value":"PHPDoc"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"All methods "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" have docblocks that:"}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" contain a full sentence describing the purpose of the method."}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"SHOULD"}]},{"type":"text","value":" contain links to additional resources"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" contain all parameter types and names"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"SHOULD"}]},{"type":"text","value":" contain parameter descriptions (when the name is may not be self explaining)"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" contain the return type"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" contain all exception that are thrown directly by the method"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST NOT"}]},{"type":"text","value":" contain exceptions that are thrown by other methods on a higher level"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"The following shows an example class method and a corresponding docblock:"}]},{"type":"element","tag":"code","props":{"code":"/**\n * Register a binding with the container.\n *\n * @see https://example.org\n *\n * @param  string|array          $abstract  The abstract that the binding is named after\n * @param  \\Closure|string|null  $concrete\n * @param  bool                  $shared\n * @return void\n *\n * @throws \\Exception\n */\npublic function bind($abstract, $concrete = null, $shared = false)\n{\n    //\n}\n","language":"php"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":"/**"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":" * Register a binding with the container."}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":" *"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":" * "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"@see"}]},{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":" https://example.org"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":" *"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":" * "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"@param"}]},{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":"  "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"string"}]},{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":"|"}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"array"}]},{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":"          $abstract  The abstract that the binding is named after"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":" * "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"@param"}]},{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":"  "}]},{"type":"element","tag":"span","props":{"style":{"color":"#79C0FF"}},"children":[{"type":"text","value":"\\Closure"}]},{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":"|"}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"string"}]},{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":"|"}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"null"}]},{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":"  $concrete"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":" * "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"@param"}]},{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":"  "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"bool"}]},{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":"                  $shared"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":" * "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"@return"}]},{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"void"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":" *"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":" * "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"@throws"}]},{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"style":{"color":"#79C0FF"}},"children":[{"type":"text","value":"\\Exception"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":" */"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"public"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"function"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"style":{"color":"#D2A8FF"}},"children":[{"type":"text","value":"bind"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"($abstract, $concrete "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"="}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"style":{"color":"#79C0FF"}},"children":[{"type":"text","value":"null"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":", $shared "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"="}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"style":{"color":"#79C0FF"}},"children":[{"type":"text","value":"false"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":")"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"{"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"    "}]},{"type":"element","tag":"span","props":{"style":{"color":"#8B949E"}},"children":[{"type":"text","value":"//"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"}"}]}]}]}]}]},{"type":"element","tag":"h2","props":{"id":"helpers"},"children":[{"type":"text","value":"Helpers"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Helpers are files that contain functions that are not wrapped inside of a class."}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"File names of helpers "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" be kebab-case."}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"The number of helpers within a project "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"SHOULD"}]},{"type":"text","value":" be reduced to the minimum. (It is recommended to have one helper named "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"helpers.php"}]},{"type":"text","value":")"}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Helper functions "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" wrap existing methods and "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST NOT"}]},{"type":"text","value":" introduce new logic."}]},{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"The purpose of helper methods "},{"type":"element","tag":"strong","props":{},"children":[{"type":"text","value":"MUST"}]},{"type":"text","value":" be solely to increase the readability of the code."}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Read the "},{"type":"element","tag":"a","props":{"href":"../../tutorials/php/helpers.md"},"children":[{"type":"text","value":"tutorial"}]},{"type":"text","value":" about how to register helpers."}]}],"toc":{"title":"","searchDepth":2,"depth":2,"links":[{"id":"coding-style","depth":2,"text":"Coding Style","children":[{"id":"types","depth":3,"text":"Types"},{"id":"phpdoc","depth":3,"text":"PHPDoc"}]},{"id":"helpers","depth":2,"text":"Helpers"}]}},"_type":"markdown","_id":"content:06.guidelines-internal:development-php.md","_source":"content","_file":"06.guidelines-internal/development-php.md","_extension":"md"}