Conditions | 8 |
Paths | 12 |
Total Lines | 52 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
39 | public function __construct(\Symfony\Component\Form\FormView $formViews, bool $children = true) |
||
40 | { |
||
41 | $varsToArray = ['choices', 'preferred_choices', 'errors', 'is_selected']; |
||
42 | |||
43 | $outputVars = array_merge($varsToArray, [ |
||
44 | 'value', |
||
45 | 'attr', |
||
46 | 'id', |
||
47 | 'name', |
||
48 | 'full_name', |
||
49 | 'disabled', |
||
50 | 'label', |
||
51 | 'block_prefixes', |
||
52 | 'unique_block_prefix', |
||
53 | 'valid', |
||
54 | 'required', |
||
55 | 'label_attr', |
||
56 | 'expanded', |
||
57 | 'submitted', |
||
58 | 'placeholder', |
||
59 | 'is_selected', |
||
60 | 'placeholder_in_choices', |
||
61 | 'checked', |
||
62 | 'action', |
||
63 | 'multiple' |
||
64 | ]); |
||
65 | foreach ($outputVars as $var) { |
||
66 | if (isset($formViews->vars[$var])) { |
||
67 | $this->vars[$var] = $formViews->vars[$var]; |
||
68 | |||
69 | if (in_array($var, $varsToArray)) { |
||
70 | $choices = $this->vars[$var]; |
||
71 | $this->vars[$var] = []; |
||
72 | foreach ($choices as $choice) { |
||
73 | if (method_exists($choice, 'getMessage')) { |
||
74 | $this->vars[$var][] = $choice->getMessage(); |
||
75 | } else { |
||
76 | $this->vars[$var][] = (array) $choice; |
||
77 | } |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | } |
||
82 | |||
83 | if ($children) { |
||
84 | $this->children = new ArrayCollection(); |
||
85 | foreach ($formViews as $formView) { |
||
86 | $this->addChild($formView); |
||
87 | } |
||
88 | } |
||
89 | $this->rendered = $formViews->isRendered(); |
||
90 | $this->methodRendered = $formViews->isMethodRendered(); |
||
91 | } |
||
131 |