Conditions | 9 |
Paths | 66 |
Total Lines | 55 |
Code Lines | 37 |
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 |
||
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 | $defaults['api_url'] = $url; |
||
58 | |||
59 | $form->addText('method', 'Method'); |
||
60 | $defaults['method'] = $this->endpoint->getMethod(); |
||
61 | |||
62 | if ($this->authorization instanceof BearerTokenAuthorization) { |
||
63 | $form->addText('token', 'Token:') |
||
64 | ->setAttribute('placeholder', 'napište token'); |
||
65 | } elseif ($this->authorization instanceof NoAuthorization) { |
||
66 | $form->addText('authorization', 'Authorization') |
||
67 | ->setDisabled(true); |
||
68 | $defaults['authorization'] = 'No authorization - global access'; |
||
69 | } |
||
70 | |||
71 | $params = $this->handler->params(); |
||
72 | foreach ($params as $param) { |
||
73 | $count = $param->isMulti() ? 5 : 1; |
||
74 | for ($i = 0; $i < $count; $i++) { |
||
75 | $key = $param->getKey(); |
||
76 | if ($param->isMulti()) { |
||
77 | $key = $key . '___' . $i; |
||
78 | } |
||
79 | $c = $form->addText($key, $param->getKey()); |
||
80 | if ($param->getAvailableValues()) { |
||
81 | $c->setOption('description', 'available values: ' . implode(' | ', $param->getAvailableValues())); |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | |||
86 | $form->addSubmit('send', 'Otestuj') |
||
87 | ->getControlPrototype() |
||
88 | ->setName('button') |
||
89 | ->setHtml('<i class="fa fa-cloud-upload"></i> Try api'); |
||
90 | |||
91 | $form->setDefaults($defaults); |
||
92 | |||
93 | $form->onSuccess[] = array($this, 'formSucceeded'); |
||
94 | return $form; |
||
95 | } |
||
96 | |||
115 | } |
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@property
annotation 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.