| Conditions | 9 |
| Paths | 66 |
| Total Lines | 53 |
| Code Lines | 34 |
| 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 |
||
| 41 | protected function createComponentConsoleForm() |
||
| 42 | { |
||
| 43 | $form = new Form(); |
||
| 44 | |||
| 45 | $defaults = []; |
||
| 46 | |||
| 47 | // $form->setRenderer(new BootstrapRenderer()); |
||
| 48 | |||
| 49 | $uri = $this->request->getUrl(); |
||
| 50 | $scheme = $uri->scheme; |
||
| 51 | if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) { |
||
| 52 | $scheme = $_SERVER['HTTP_X_FORWARDED_PROTO']; |
||
| 53 | } |
||
| 54 | $url = $scheme . '://' . $uri->host . '/api/' . $this->endpoint->getUrl(); |
||
| 55 | |||
| 56 | $form->addText('api_url', 'Api Url'); |
||
| 57 | |||
| 58 | $defaults['api_url'] = $url; |
||
| 59 | |||
| 60 | if ($this->authorization instanceof BearerTokenAuthorization) { |
||
| 61 | $form->addText('token', 'Token:') |
||
| 62 | ->setAttribute('placeholder', 'napište token'); |
||
| 63 | } elseif ($this->authorization instanceof NoAuthorization) { |
||
| 64 | $form->addText('authorization', 'Authorization') |
||
| 65 | ->setDisabled(true); |
||
| 66 | $defaults['authorization'] = 'No authorization - global access'; |
||
| 67 | } |
||
| 68 | |||
| 69 | $params = $this->handler->params(); |
||
| 70 | foreach ($params as $param) { |
||
| 71 | $count = $param->isMulti() ? 5 : 1; |
||
| 72 | for ($i = 0; $i < $count; $i++) { |
||
| 73 | $key = $param->getKey(); |
||
| 74 | if ($param->isMulti()) { |
||
| 75 | $key = $key . '___' . $i; |
||
| 76 | } |
||
| 77 | $c = $form->addText($key, $param->getKey()); |
||
| 78 | if ($param->getAvailableValues()) { |
||
| 79 | $c->setOption('description', 'available values: ' . implode(' | ', $param->getAvailableValues())); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | $form->addSubmit('send', 'Otestuj') |
||
| 85 | ->getControlPrototype() |
||
| 86 | ->setName('button') |
||
| 87 | ->setHtml('<i class="fa fa-cloud-upload"></i> Try api'); |
||
| 88 | |||
| 89 | $form->setDefaults($defaults); |
||
| 90 | |||
| 91 | $form->onSuccess[] = array($this, 'formSucceeded'); |
||
| 92 | return $form; |
||
| 93 | } |
||
| 94 | |||
| 206 | } |
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.