Conditions | 7 |
Paths | 1 |
Total Lines | 89 |
Code Lines | 53 |
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 |
||
34 | public function configureOptions(OptionsResolver $resolver) |
||
35 | { |
||
36 | parent::configureOptions($resolver); |
||
37 | |||
38 | $choiceLoader = function (Options $options) { |
||
39 | // Unless the choices are given explicitly, load them on demand |
||
40 | if (null === $options['data']) { |
||
41 | $hash = null; |
||
|
|||
42 | $qbParts = null; |
||
43 | |||
44 | if (null !== $options['query_builder']) { |
||
45 | $entityLoader = $this->getLoader($options['em'], $options['query_builder'], $options['class']); |
||
46 | } else { |
||
47 | $queryBuilder = $options['em']->getRepository($options['class'])->createQueryBuilder('e'); |
||
48 | $entityLoader = $this->getLoader($options['em'], $queryBuilder, $options['class']); |
||
49 | } |
||
50 | |||
51 | $doctrineChoiceLoader = new DoctrineChoiceLoader( |
||
52 | $options['em'], |
||
53 | $options['class'], |
||
54 | $options['id_reader'], |
||
55 | $entityLoader |
||
56 | ); |
||
57 | |||
58 | return $doctrineChoiceLoader; |
||
59 | } |
||
60 | }; |
||
61 | |||
62 | $emNormalizer = function (Options $options, $em) { |
||
63 | /* @var ManagerRegistry $registry */ |
||
64 | if (null !== $em) { |
||
65 | if ($em instanceof ObjectManager) { |
||
66 | return $em; |
||
67 | } |
||
68 | |||
69 | return $this->getOb->getManager($em); |
||
70 | } |
||
71 | |||
72 | $em = $this->registry->getManagerForClass($options['class']); |
||
73 | |||
74 | if (null === $em) { |
||
75 | throw new \RuntimeException(sprintf( |
||
76 | 'Class "%s" seems not to be a managed Doctrine entity. '. |
||
77 | 'Did you forget to map it?', |
||
78 | $options['class'] |
||
79 | )); |
||
80 | } |
||
81 | |||
82 | return $em; |
||
83 | }; |
||
84 | |||
85 | // Invoke the query builder closure so that we can cache choice lists |
||
86 | // for equal query builders |
||
87 | $queryBuilderNormalizer = function (Options $options, $queryBuilder) { |
||
88 | if (is_callable($queryBuilder)) { |
||
89 | $queryBuilder = call_user_func($queryBuilder, $options['em']->getRepository($options['class'])); |
||
90 | } |
||
91 | |||
92 | return $queryBuilder; |
||
93 | }; |
||
94 | |||
95 | // Set the "id_reader" option via the normalizer. This option is not |
||
96 | // supposed to be set by the user. |
||
97 | $idReaderNormalizer = function (Options $options) { |
||
98 | $classMetadata = $options['em']->getClassMetadata($options['class']); |
||
99 | return new IdReader($options['em'], $classMetadata); |
||
100 | }; |
||
101 | |||
102 | $resolver->setDefaults(array( |
||
103 | 'align' => 'left', |
||
104 | 'cellAlign' => 'left', |
||
105 | 'type' => 'combo', |
||
106 | 'data' => null, |
||
107 | 'class' => null, |
||
108 | 'query_builder' => null, |
||
109 | 'choice_loader' => $choiceLoader, |
||
110 | 'choice_label' => null, |
||
111 | 'id_reader' => null, |
||
112 | 'em' => null, |
||
113 | )); |
||
114 | $resolver->setRequired(['class']); |
||
115 | |||
116 | $resolver->setNormalizer('em', $emNormalizer); |
||
117 | $resolver->setNormalizer('query_builder', $queryBuilderNormalizer); |
||
118 | $resolver->setNormalizer('id_reader', $idReaderNormalizer); |
||
119 | |||
120 | $resolver->setAllowedTypes('attr', 'array'); |
||
121 | $resolver->setAllowedTypes('data', ['array', 'null']); |
||
122 | } |
||
123 | |||
198 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.