| Conditions | 8 |
| Paths | 48 |
| Total Lines | 67 |
| Code Lines | 42 |
| 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 |
||
| 163 | public function generate($daonamespace, $beannamespace, /*$storeInUtc = 0,*/ $selfedit = 'false', $defaultPath = false, $storePath = '') |
||
| 164 | { |
||
| 165 | $this->selfedit = $selfedit; |
||
| 166 | |||
| 167 | if ($selfedit == 'true') { |
||
| 168 | $this->moufManager = MoufManager::getMoufManager(); |
||
| 169 | } else { |
||
| 170 | $this->moufManager = MoufManager::getMoufManagerHiddenInstance(); |
||
| 171 | } |
||
| 172 | |||
| 173 | $doctrineCache = $this->moufManager->getInstanceDescriptor('defaultDoctrineCache'); |
||
| 174 | |||
| 175 | $migratingFrom42 = false; |
||
| 176 | if ($this->moufManager->has('tdbmService') && !$this->moufManager->has('tdbmConfiguration')) { |
||
| 177 | $migratingFrom42 = true; |
||
| 178 | } |
||
| 179 | |||
| 180 | $namingStrategy = InstallUtils::getOrCreateInstance('namingStrategy', DefaultNamingStrategy::class, $this->moufManager); |
||
| 181 | if ($migratingFrom42) { |
||
| 182 | // Let's setup the naming strategy for compatibility |
||
| 183 | $namingStrategy->getSetterProperty('setBeanPrefix')->setValue(''); |
||
| 184 | $namingStrategy->getSetterProperty('setBeanSuffix')->setValue('Bean'); |
||
| 185 | $namingStrategy->getSetterProperty('setBaseBeanPrefix')->setValue(''); |
||
| 186 | $namingStrategy->getSetterProperty('setBaseBeanSuffix')->setValue('BaseBean'); |
||
| 187 | $namingStrategy->getSetterProperty('setDaoPrefix')->setValue(''); |
||
| 188 | $namingStrategy->getSetterProperty('setDaoSuffix')->setValue('Dao'); |
||
| 189 | $namingStrategy->getSetterProperty('setBaseDaoPrefix')->setValue(''); |
||
| 190 | $namingStrategy->getSetterProperty('setBaseDaoSuffix')->setValue('BaseDao'); |
||
| 191 | } |
||
| 192 | |||
| 193 | if (!$this->moufManager->instanceExists('tdbmConfiguration')) { |
||
| 194 | $moufListener = InstallUtils::getOrCreateInstance(MoufDiListener::class, MoufDiListener::class, $this->moufManager); |
||
| 195 | |||
| 196 | $tdbmConfiguration = $this->moufManager->createInstance(MoufConfiguration::class)->setName('tdbmConfiguration'); |
||
| 197 | $tdbmConfiguration->getConstructorArgumentProperty('connection')->setValue($this->moufManager->getInstanceDescriptor('dbalConnection')); |
||
| 198 | $tdbmConfiguration->getConstructorArgumentProperty('cache')->setValue($doctrineCache); |
||
| 199 | $tdbmConfiguration->getConstructorArgumentProperty('namingStrategy')->setValue($namingStrategy); |
||
| 200 | $tdbmConfiguration->getProperty('daoFactoryInstanceName')->setValue('daoFactory'); |
||
| 201 | $tdbmConfiguration->getConstructorArgumentProperty('generatorListeners')->setValue([$moufListener]); |
||
| 202 | |||
| 203 | // Let's also delete the tdbmService if migrating versions <= 4.2 |
||
| 204 | if ($migratingFrom42) { |
||
| 205 | $this->moufManager->removeComponent('tdbmService'); |
||
| 206 | } |
||
| 207 | } else { |
||
| 208 | $tdbmConfiguration = $this->moufManager->getInstanceDescriptor('tdbmConfiguration'); |
||
| 209 | } |
||
| 210 | |||
| 211 | if (!$this->moufManager->instanceExists('tdbmService')) { |
||
| 212 | $tdbmService = $this->moufManager->createInstance('Mouf\\Database\\TDBM\\TDBMService')->setName('tdbmService'); |
||
| 213 | $tdbmService->getConstructorArgumentProperty('configuration')->setValue($tdbmConfiguration); |
||
| 214 | } |
||
| 215 | |||
| 216 | // We declare our instance of the Symfony command as a Mouf instance |
||
| 217 | $generateCommand = InstallUtils::getOrCreateInstance('generateCommand', GenerateCommand::class, $this->moufManager); |
||
| 218 | $generateCommand->getConstructorArgumentProperty('configuration')->setValue($tdbmConfiguration); |
||
| 219 | |||
| 220 | // We register that instance descriptor using "ConsoleUtils" |
||
| 221 | $consoleUtils = new ConsoleUtils($this->moufManager); |
||
| 222 | $consoleUtils->registerCommand($generateCommand); |
||
| 223 | |||
| 224 | $this->moufManager->rewriteMouf(); |
||
| 225 | |||
| 226 | TdbmController::generateDaos($this->moufManager, 'tdbmService', $daonamespace, $beannamespace, 'daoFactory', $selfedit, /*$storeInUtc,*/ $defaultPath, $storePath); |
||
| 227 | |||
| 228 | InstallUtils::continueInstall($selfedit == 'true'); |
||
| 229 | } |
||
| 230 | |||
| 240 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.