Conditions | 8 |
Paths | 26 |
Total Lines | 92 |
Code Lines | 53 |
Lines | 11 |
Ratio | 11.96 % |
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 |
||
114 | protected function start() |
||
115 | { |
||
116 | $pluginCode = $this->paramList['pluginCode']['value']; |
||
117 | |||
118 | $codes = $this->getPluginCodes(); |
||
119 | if (!in_array($pluginCode, $codes)) { |
||
120 | $this->exitGenerator('<error>This plugin code does not exist.</error>'); |
||
121 | |||
122 | return; |
||
123 | } |
||
124 | |||
125 | $fsList = array( |
||
126 | 'dir' => array(), |
||
127 | 'file' => array(), |
||
128 | ); |
||
129 | |||
130 | $tableList = $this->paramList['tableList']['value']; |
||
131 | $codePath = $this->app['config']['root_dir'].'/app/Plugin/'.$pluginCode; |
||
132 | |||
133 | $dirList = array('Entity', 'Repository', 'Resource', 'Resource/doctrine', 'Resource/doctrine/migration'); |
||
134 | View Code Duplication | foreach ($dirList as $dirName) { |
|
135 | $dirPath = $codePath.'/'.$dirName; |
||
136 | if (!is_dir($dirPath)) { |
||
137 | mkdir($dirPath); |
||
138 | } |
||
139 | if (is_dir($dirPath)) { |
||
140 | $fsList['dir'][$dirPath] = true; |
||
141 | } else { |
||
142 | $fsList['dir'][$dirPath] = false; |
||
143 | } |
||
144 | } |
||
145 | |||
146 | $doctrinePath = $codePath.'/Resource/doctrine'; |
||
147 | |||
148 | if (count($tableList)) { |
||
149 | |||
150 | // ymlファイルの作成 |
||
151 | $em = $this->app['orm.em']; |
||
152 | |||
153 | $databaseDriver = new DatabaseDriver( |
||
154 | $em->getConnection()->getSchemaManager() |
||
155 | ); |
||
156 | |||
157 | $em->getConfiguration()->setMetadataDriverImpl( |
||
158 | $databaseDriver |
||
159 | ); |
||
160 | |||
161 | $databaseDriver->setNamespace('Plugin\\'.$pluginCode.'\\Entity\\'); |
||
162 | |||
163 | $cmf = new DisconnectedClassMetadataFactory(); |
||
164 | $cmf->setEntityManager($em); |
||
165 | $metadatas = $cmf->getAllMetadata(); |
||
166 | |||
167 | $filters = array_map(function ($value) { |
||
168 | return ucfirst(Inflector::camelize(str_replace('plg_', '', $value))); |
||
169 | }, $tableList); |
||
170 | $metadatas = MetadataFilter::filter($metadatas, $filters); |
||
171 | |||
172 | $cme = new ClassMetadataExporter(); |
||
173 | $exporter = $cme->getExporter('yml', $doctrinePath); |
||
174 | |||
175 | /** @var ClassMetadataInfo $class */ |
||
176 | foreach ($metadatas as $class) { |
||
177 | $class->name = str_replace('Plg', '', $class->name); |
||
178 | $class->rootEntityName = str_replace('Plg', '', $class->rootEntityName); |
||
179 | $name = explode('\\', $class->name); |
||
180 | $class->customRepositoryClassName = 'Plugin\\'.$pluginCode.'\\Repository\\'.$name[count($name) - 1].'Repository'; |
||
181 | $class->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); |
||
182 | } |
||
183 | |||
184 | $exporter->setMetadata($metadatas); |
||
185 | $exporter->export(); |
||
186 | |||
187 | $finder = new Finder(); |
||
188 | $finder->files()->depth('== 0'); |
||
189 | $files = $finder->in($doctrinePath); |
||
190 | |||
191 | foreach ($files as $item) { |
||
192 | $fsList['file'][$item->getRealPath()] = true; |
||
193 | } |
||
194 | |||
195 | // Entity、Repositoryファイルの作成 |
||
196 | $this->generateEntities($metadatas, $fsList); |
||
197 | |||
198 | // migrationファイルの作成 |
||
199 | $this->generateMigration($metadatas, $fsList, $pluginCode, $codePath); |
||
200 | |||
201 | // 完了メッセージ |
||
202 | $this->completeMessage($fsList); |
||
203 | } |
||
204 | |||
205 | } |
||
206 | |||
208 |