Conditions | 7 |
Paths | 25 |
Total Lines | 58 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 |
||
50 | public function handle(CreateMessage $command) |
||
51 | { |
||
52 | $input = $command->getInput(); |
||
53 | $output = $command->getOutput(); |
||
54 | |||
55 | /** @var Config $config */ |
||
56 | $config = $command->getConfig(); |
||
57 | |||
58 | $directory = $config->getMigrationsDirectory(); |
||
59 | $filesystem = $command->getFilesystem(); |
||
60 | if (!$filesystem->has($directory)) { |
||
61 | throw new CliException(sprintf( |
||
62 | 'Migrations directory "%s" does not exist.', |
||
63 | $directory |
||
64 | )); |
||
65 | } |
||
66 | |||
67 | $namespace = $input->getOption('namespace'); |
||
68 | $editorCmd = $input->getOption('editor-cmd'); |
||
69 | |||
70 | if (null === $namespace) { |
||
71 | $namespace = $config->getMigrationsNamespace(); |
||
72 | } |
||
73 | if (!empty($namespace)) { |
||
74 | $namespace = rtrim($namespace, '\\'); |
||
75 | $namespace = preg_replace('/[^A-Za-z\d_\\\\]+/', '', $namespace); |
||
76 | } |
||
77 | |||
78 | $timestamp = date('YmdHis'); |
||
79 | $className = ['v'.$timestamp]; |
||
80 | $title = $input->getArgument('title'); |
||
81 | if (!empty($title)) { |
||
82 | $title = preg_replace('/[^A-Za-z\d_]+/', '', $title); |
||
83 | $className[] = $title; |
||
84 | } |
||
85 | |||
86 | $class = $this->generate(implode('_', $className), $namespace); |
||
87 | $result = $this->writeClass($class, $filesystem, $directory); |
||
88 | |||
89 | if ($result) { |
||
90 | $output->writeln(sprintf( |
||
91 | 'Created new Migration file at "<info>./%s</info>"', |
||
92 | $result |
||
93 | )); |
||
94 | if ($editorCmd) { |
||
95 | $pipes = []; |
||
96 | $baseDir = dirname($config->getMigrationsDirectoryPath()); |
||
97 | $command = $editorCmd . ' ' . escapeshellarg($baseDir . DIRECTORY_SEPARATOR . $result); |
||
98 | proc_open($command, array(), $pipes); |
||
99 | } |
||
100 | } else { |
||
101 | $output->writeln( |
||
102 | 'An error occurred creating a new Migration file. Please check directory permissions and configuration.' |
||
103 | ); |
||
104 | } |
||
105 | |||
106 | return $result; |
||
107 | } |
||
108 | |||
182 |