| Conditions | 4 |
| Paths | 8 |
| Total Lines | 54 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 34 | public function get( ServerRequestInterface $request, ResponseInterface $response ) |
||
| 35 | { |
||
| 36 | $view = $this->getView(); |
||
| 37 | |||
| 38 | try |
||
| 39 | { |
||
| 40 | if( $view->param( 'id' ) != '' ) { |
||
| 41 | $response = $this->getItem( $view, $request, $response ); |
||
| 42 | } else { |
||
| 43 | $response = $this->getItems( $view, $request, $response ); |
||
| 44 | } |
||
| 45 | |||
| 46 | $status = 200; |
||
| 47 | } |
||
| 48 | catch( \Aimeos\MShop\Exception $e ) |
||
| 49 | { |
||
| 50 | $status = 404; |
||
| 51 | $view->errors = $this->getErrorDetails( $e, 'mshop' ); |
||
| 52 | } |
||
| 53 | catch( \Exception $e ) |
||
| 54 | { |
||
| 55 | $status = 500; |
||
| 56 | $view->errors = $this->getErrorDetails( $e ); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** client/jsonapi/stock/standard/template |
||
| 60 | * Relative path to the catalog lists JSON API template |
||
| 61 | * |
||
| 62 | * The template file contains the code and processing instructions |
||
| 63 | * to generate the result shown in the JSON API body. The |
||
| 64 | * configuration string is the path to the template file relative |
||
| 65 | * to the templates directory (usually in client/jsonapi/templates). |
||
| 66 | * |
||
| 67 | * You can overwrite the template file configuration in extensions and |
||
| 68 | * provide alternative templates. These alternative templates should be |
||
| 69 | * named like the default one but with the string "default" replaced by |
||
| 70 | * an unique name. You may use the name of your project for this. If |
||
| 71 | * you've implemented an alternative client class as well, "standard" |
||
| 72 | * should be replaced by the name of the new class. |
||
| 73 | * |
||
| 74 | * @param string Relative path to the template creating the body for the GET method of the JSON API |
||
| 75 | * @since 2017.03 |
||
| 76 | * @category Developer |
||
| 77 | */ |
||
| 78 | $tplconf = 'client/jsonapi/stock/standard/template'; |
||
| 79 | $default = 'stock/standard.php'; |
||
| 80 | |||
| 81 | $body = $view->render( $view->config( $tplconf, $default ) ); |
||
| 82 | |||
| 83 | return $response->withHeader( 'Allow', 'GET,OPTIONS' ) |
||
| 84 | ->withHeader( 'Content-Type', 'application/vnd.api+json' ) |
||
| 85 | ->withBody( $view->response()->createStreamFromString( $body ) ) |
||
| 86 | ->withStatus( $status ); |
||
| 87 | } |
||
| 88 | |||
| 171 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.