Conditions | 3 |
Paths | 3 |
Total Lines | 55 |
Code Lines | 33 |
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 |
||
45 | protected function execute(InputInterface $input, OutputInterface $output) |
||
46 | { |
||
47 | $isoCodePath = __DIR__.'/../../../vendor/ronanguilloux/isocodes'; |
||
48 | if (!file_exists($isoCodePath.'/.git')) { |
||
49 | $output->writeln( |
||
50 | '<error>No .git directory found on ronanguilloux/isocodes package. Please run rm -r vendor/ronanguilloux/isocodes && composer update ronanguilloux/isocodes --prefer-source command.</error>' |
||
|
|||
51 | ); |
||
52 | |||
53 | return 1; |
||
54 | } |
||
55 | |||
56 | $fqcnRepository = new FqcnRepository(new FileRepository(), new ParserFactory()); |
||
57 | |||
58 | $isoCodesClasses = array_diff( |
||
59 | array_map(function ($fqcn) { |
||
60 | return str_replace('IsoCodes\\', '', $fqcn); |
||
61 | }, $fqcnRepository->findIn(__DIR__.'/../../../vendor/ronanguilloux/isocodes/src/IsoCodes')), |
||
62 | $this->excludedClasses |
||
63 | ); |
||
64 | |||
65 | $constraintClasses = array_filter(array_map(function ($fqcn) { |
||
66 | return str_replace('SLLH\\IsoCodesValidator\\Constraints\\', '', $fqcn); |
||
67 | }, $fqcnRepository->findIn(__DIR__.'/../../../src/Constraints')), function ($className) { |
||
68 | return !empty(trim($className)); |
||
69 | }); |
||
70 | |||
71 | $twig = new \Twig_Environment(new \Twig_Loader_Filesystem(__DIR__.'/../..')); |
||
72 | |||
73 | foreach (array_udiff($isoCodesClasses, $constraintClasses, 'strcasecmp') as $className) { |
||
74 | $classVersion = str_replace( |
||
75 | 'v', |
||
76 | '', |
||
77 | exec("git -C ${isoCodePath} tag --list --contains $(git -C ${isoCodePath} log --pretty=format:\"%h\" --diff-filter=A src/IsoCodes/${className}.php) | head -n 1") |
||
78 | ); |
||
79 | |||
80 | $output->writeln("Generate <comment>${className}</comment> constraint (<info>v${classVersion}</info>)."); |
||
81 | |||
82 | file_put_contents( |
||
83 | __DIR__."/../../../src/Constraints/${className}.php", |
||
84 | $twig->render('templates/Constraint.php.twig', [ |
||
85 | 'class_name' => $className, |
||
86 | 'class_version' => $classVersion, |
||
87 | ]) |
||
88 | ); |
||
89 | |||
90 | file_put_contents( |
||
91 | __DIR__."/../../../tests/Constraints/${className}ValidatorTest.php", |
||
92 | $twig->render('templates/ConstraintValidatorTest.php.twig', [ |
||
93 | 'class_name' => $className, |
||
94 | ]) |
||
95 | ); |
||
96 | } |
||
97 | |||
98 | return 0; |
||
99 | } |
||
100 | } |
||
101 |
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.