Conditions | 2 |
Paths | 2 |
Total Lines | 65 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
78 | public function options( ServerRequestInterface $request, ResponseInterface $response, $prefix = null ) |
||
79 | { |
||
80 | $view = $this->getView(); |
||
81 | |||
82 | try |
||
83 | { |
||
84 | /** client/jsonapi/resources |
||
85 | * A list of resource names whose clients are available for the JSON API |
||
86 | * |
||
87 | * The HTTP OPTIONS method returns a list of resources known by the |
||
88 | * JSON API including their URLs. The list of available resources |
||
89 | * can be exteded dynamically be implementing a new Jsonadm client |
||
90 | * class handling request for this new domain. |
||
91 | * |
||
92 | * To add the new domain client to the list of resources returned |
||
93 | * by the HTTP OPTIONS method, you have to add its name in lower case |
||
94 | * to the existing configuration. |
||
95 | * |
||
96 | * @param array List of resource names |
||
97 | * @since 2017.03 |
||
98 | * @category Developer |
||
99 | */ |
||
100 | $default = ['attribute', 'basket', 'catalog', 'customer', 'locale', 'order', 'product', 'service', 'stock']; |
||
101 | $resources = $this->getContext()->getConfig()->get( 'client/jsonapi/resources', $default ); |
||
102 | |||
103 | $view->resources = (array) $resources; |
||
104 | $view->prefix = $prefix; |
||
105 | $status = 200; |
||
106 | } |
||
107 | catch( \Exception $e ) |
||
108 | { |
||
109 | $status = 500; |
||
110 | $view->errors = $this->getErrorDetails( $e ); |
||
111 | } |
||
112 | |||
113 | /** client/jsonapi/standard/template-options |
||
114 | * Relative path to the JSON API template for OPTIONS requests |
||
115 | * |
||
116 | * The template file contains the code and processing instructions |
||
117 | * to generate the result shown in the JSON API body. The |
||
118 | * configuration string is the path to the template file relative |
||
119 | * to the templates directory (usually in client/jsonapi/templates). |
||
120 | * |
||
121 | * You can overwrite the template file configuration in extensions and |
||
122 | * provide alternative templates. These alternative templates should be |
||
123 | * named like the default one but with the string "standard" replaced by |
||
124 | * an unique name. You may use the name of your project for this. If |
||
125 | * you've implemented an alternative client class as well, "standard" |
||
126 | * should be replaced by the name of the new class. |
||
127 | * |
||
128 | * @param string Relative path to the template creating the body for the OPTIONS method of the JSON API |
||
129 | * @since 2017.02 |
||
130 | * @category Developer |
||
131 | * @see client/jsonapi/standard/template-get |
||
132 | */ |
||
133 | $tplconf = 'client/jsonapi/standard/template-options'; |
||
134 | $default = 'options-standard.php'; |
||
135 | |||
136 | $body = $view->render( $view->config( $tplconf, $default ) ); |
||
137 | |||
138 | return $response->withHeader( 'Allow', 'GET' ) |
||
139 | ->withHeader( 'Content-Type', 'application/vnd.api+json' ) |
||
140 | ->withBody( $view->response()->createStreamFromString( $body ) ) |
||
141 | ->withStatus( $status ); |
||
142 | } |
||
143 | } |
||
144 |