Conditions | 13 |
Paths | 960 |
Total Lines | 91 |
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 |
||
96 | public function generate(Bundle $bundle, $modelName) |
||
97 | { |
||
98 | $dir = $bundle->getTargetDirectory(); |
||
99 | |||
100 | // Retrieves model folder depending on chosen Model Manager |
||
101 | $modelFolder = ''; |
||
102 | switch ($this->generator) { |
||
103 | case 'propel': |
||
104 | $modelFolder = 'Model'; |
||
105 | break; |
||
106 | case 'doctrine': |
||
107 | $modelFolder = 'Entity'; |
||
108 | break; |
||
109 | case 'doctrine_orm': |
||
110 | $modelFolder = 'Document'; |
||
111 | break; |
||
112 | } |
||
113 | |||
114 | if (false === strpos($bundle->getNamespace(), '\\')) { |
||
115 | $bundleName = $bundle->getNamespace(); |
||
116 | $namespacePrefix = null; |
||
117 | } else { |
||
118 | list( $namespacePrefix, $bundleName) = explode('\\', $bundle->getNamespace(), 2); |
||
119 | } |
||
120 | |||
121 | $parameters = array( |
||
122 | 'namespace' => $bundle->getNamespace(), |
||
123 | 'bundle' => $bundle->getName(), |
||
124 | 'generator' => 'admingenerator.generator.'.$this->generator, |
||
125 | 'namespace_prefix' => $namespacePrefix, |
||
126 | 'bundle_name' => $bundleName, |
||
127 | 'model_folder' => $modelFolder, |
||
128 | 'model_name' => $modelName, |
||
129 | 'prefix' => ucfirst($this->prefix), |
||
130 | ); |
||
131 | |||
132 | if (!file_exists($dir.'/'.$bundle->getName().'.php')) { |
||
133 | $this->renderGeneratedFile('Bundle.php.twig', $dir.'/'.$bundle->getName().'.php', $parameters); |
||
134 | } |
||
135 | |||
136 | foreach ($this->actions as $action => $actionProperties) { |
||
137 | $parameters['action'] = $action; |
||
138 | |||
139 | $controllerFile = $dir.'/Controller/' |
||
140 | .($this->prefix ? ucfirst($this->prefix).'/' : '').$action.'Controller.php'; |
||
141 | $this->copyPreviousFile($controllerFile); |
||
142 | $this->renderGeneratedFile( |
||
143 | 'DefaultController.php.twig', |
||
144 | $controllerFile, |
||
145 | $parameters |
||
146 | ); |
||
147 | |||
148 | foreach ($actionProperties['views'] as $templateName) { |
||
149 | $templateFile = $dir.'/Resources/views/'.ucfirst($this->prefix).$action.'/'.$templateName.'.html.twig'; |
||
150 | $this->copyPreviousFile($templateFile); |
||
151 | $this->renderGeneratedFile( |
||
152 | 'default_view.html.twig', |
||
153 | $templateFile, |
||
154 | $parameters + array('view' => $templateName) |
||
155 | ); |
||
156 | } |
||
157 | } |
||
158 | |||
159 | foreach ($this->forms as $form) { |
||
160 | $parameters['form'] = $form; |
||
161 | |||
162 | $formFile = $dir.'/Form/Type/'.($this->prefix ? ucfirst($this->prefix).'/' : '').$form.'Type.php'; |
||
163 | $this->copyPreviousFile($formFile); |
||
164 | $this->renderGeneratedFile( |
||
165 | 'DefaultType.php.twig', |
||
166 | $formFile, |
||
167 | $parameters |
||
168 | ); |
||
169 | } |
||
170 | |||
171 | $optionsFile = $dir.'/Form/Type/'.($this->prefix ? ucfirst($this->prefix).'/' : '').'Options.php'; |
||
172 | $this->copyPreviousFile($optionsFile); |
||
173 | $this->renderGeneratedFile( |
||
174 | 'DefaultOptions.php.twig', |
||
175 | $optionsFile, |
||
176 | $parameters |
||
177 | ); |
||
178 | |||
179 | $generatorFile = $dir.'/Resources/config/'.($this->prefix ? ucfirst($this->prefix).'-' : '').'generator.yml'; |
||
180 | $this->copyPreviousFile($generatorFile); |
||
181 | $this->renderGeneratedFile( |
||
182 | 'generator.yml.twig', |
||
183 | $generatorFile, |
||
184 | $parameters |
||
185 | ); |
||
186 | } |
||
187 | |||
220 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: