| Conditions | 3 |
| Paths | 3 |
| Total Lines | 52 |
| Code Lines | 31 |
| 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 |
||
| 30 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 31 | { |
||
| 32 | $isoCodePath = __DIR__.'/../../../vendor/ronanguilloux/isocodes'; |
||
| 33 | if (!file_exists($isoCodePath.'/.git')) { |
||
| 34 | $output->writeln( |
||
| 35 | '<error>No .git directory found on ronanguilloux/isocodes package. Please run rm -r vendor/ronanguilloux/isocodes && composer update ronanguilloux/isocodes --prefer-source command.</error>' |
||
|
|
|||
| 36 | ); |
||
| 37 | |||
| 38 | return 1; |
||
| 39 | } |
||
| 40 | |||
| 41 | $fqcnRepository = new FqcnRepository(new FileRepository(), new ParserFactory()); |
||
| 42 | |||
| 43 | $isoCodesClasses = array_map(function ($fqcn) { |
||
| 44 | return str_replace('IsoCodes\\', '', $fqcn); |
||
| 45 | }, $fqcnRepository->findIn(__DIR__.'/../../../vendor/ronanguilloux/isocodes/src/IsoCodes')); |
||
| 46 | |||
| 47 | $constraintClasses = array_filter(array_map(function ($fqcn) { |
||
| 48 | return str_replace('SLLH\\IsoCodesValidator\\Constraints\\', '', $fqcn); |
||
| 49 | }, $fqcnRepository->findIn(__DIR__.'/../../../src/Constraints')), function ($className) { |
||
| 50 | return !empty(trim($className)); |
||
| 51 | }); |
||
| 52 | |||
| 53 | $twig = new \Twig_Environment(new \Twig_Loader_Filesystem(__DIR__.'/../..')); |
||
| 54 | |||
| 55 | foreach (array_udiff($isoCodesClasses, $constraintClasses, 'strcasecmp') as $className) { |
||
| 56 | $classVersion = str_replace( |
||
| 57 | 'v', |
||
| 58 | '', |
||
| 59 | exec("git -C ${isoCodePath} tag --list --contains $(git -C ${isoCodePath} log --pretty=format:\"%h\" --diff-filter=A src/IsoCodes/${className}.php) | head -n 1") |
||
| 60 | ); |
||
| 61 | |||
| 62 | $output->writeln("Generate <comment>${className}</comment> constraint (<info>v${classVersion}</info>)."); |
||
| 63 | |||
| 64 | file_put_contents( |
||
| 65 | __DIR__."/../../../src/Constraints/${className}.php", |
||
| 66 | $twig->render('templates/Constraint.php.twig', [ |
||
| 67 | 'class_name' => $className, |
||
| 68 | 'class_version' => $classVersion, |
||
| 69 | ]) |
||
| 70 | ); |
||
| 71 | |||
| 72 | file_put_contents( |
||
| 73 | __DIR__."/../../../tests/Constraints/${className}ValidatorTest.php", |
||
| 74 | $twig->render('templates/ConstraintValidatorTest.php.twig', [ |
||
| 75 | 'class_name' => $className, |
||
| 76 | ]) |
||
| 77 | ); |
||
| 78 | } |
||
| 79 | |||
| 80 | return 0; |
||
| 81 | } |
||
| 82 | } |
||
| 83 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.