| Conditions | 17 |
| Paths | 3458 |
| Total Lines | 101 |
| 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 |
||
| 70 | protected function execute(InputInterface $input, OutputInterface $output, FrameworkApplication $application): int |
||
| 71 | { |
||
| 72 | /** |
||
| 73 | * @var KernelInterface |
||
| 74 | */ |
||
| 75 | $kernel = $application->getKernel(); |
||
| 76 | |||
| 77 | $targetArg = rtrim($input->getArgument('target') ?? '', '/'); |
||
| 78 | |||
| 79 | if (!$targetArg) { |
||
| 80 | $targetArg = $this->getPublicDirectory($kernel->getContainer()); |
||
| 81 | } |
||
| 82 | |||
| 83 | if (!is_dir($targetArg)) { |
||
| 84 | $targetArg = $kernel->getProjectDir().'/'.$targetArg; |
||
| 85 | |||
| 86 | if (!is_dir($targetArg)) { |
||
| 87 | throw new InvalidArgumentException(sprintf( |
||
| 88 | 'The target directory "%s" does not exist.', |
||
| 89 | $input->getArgument('target') |
||
| 90 | )); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | $bundlesDir = $targetArg.'/bundles/'; |
||
| 95 | |||
| 96 | $io = new SymfonyStyle($input, $output); |
||
| 97 | $io->newLine(); |
||
| 98 | |||
| 99 | if ($input->getOption('relative')) { |
||
| 100 | $expectedMethod = self::METHOD_RELATIVE_SYMLINK; |
||
| 101 | $io->text('Trying to install deprecated SonataCoreBundle assets from SonataAdminBundle as <info>relative symbolic links</info>.'); |
||
| 102 | } elseif ($input->getOption('symlink')) { |
||
| 103 | $expectedMethod = self::METHOD_ABSOLUTE_SYMLINK; |
||
| 104 | $io->text('Trying to install deprecated SonataCoreBundle assets from SonataAdminBundle as <info>absolute symbolic links</info>.'); |
||
| 105 | } else { |
||
| 106 | $expectedMethod = self::METHOD_COPY; |
||
| 107 | $io->text('Installing deprecated SonataCoreBundle assets from SonataAdminBundle as <info>hard copies</info>.'); |
||
| 108 | } |
||
| 109 | |||
| 110 | $io->newLine(); |
||
| 111 | |||
| 112 | $copyUsed = false; |
||
| 113 | $exitCode = 0; |
||
| 114 | $validAssetDirs = []; |
||
| 115 | |||
| 116 | $bundle = $kernel->getBundle('SonataAdminBundle'); |
||
| 117 | $originDir = $bundle->getPath().'/Resources/private/SonataCoreBundleAssets'; |
||
| 118 | |||
| 119 | $assetDir = preg_replace('/bundle$/', '', 'sonatacore'); |
||
| 120 | $targetDir = $bundlesDir.$assetDir; |
||
| 121 | $validAssetDirs[] = $assetDir; |
||
| 122 | |||
| 123 | if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
||
| 124 | $message = sprintf("%s\n-> %s", $bundle->getName(), $targetDir); |
||
|
|
|||
| 125 | } else { |
||
| 126 | $message = $bundle->getName(); |
||
| 127 | } |
||
| 128 | |||
| 129 | try { |
||
| 130 | $this->filesystem->remove($targetDir); |
||
| 131 | |||
| 132 | if (self::METHOD_RELATIVE_SYMLINK === $expectedMethod) { |
||
| 133 | $method = $this->relativeSymlinkWithFallback($originDir, $targetDir); |
||
| 134 | } elseif (self::METHOD_ABSOLUTE_SYMLINK === $expectedMethod) { |
||
| 135 | $method = $this->absoluteSymlinkWithFallback($originDir, $targetDir); |
||
| 136 | } else { |
||
| 137 | $method = $this->hardCopy($originDir, $targetDir); |
||
| 138 | } |
||
| 139 | |||
| 140 | if (self::METHOD_COPY === $method) { |
||
| 141 | $copyUsed = true; |
||
| 142 | } |
||
| 143 | |||
| 144 | if ($method === $expectedMethod) { |
||
| 145 | $ioMethod = 'success'; |
||
| 146 | } else { |
||
| 147 | $ioMethod = 'warning'; |
||
| 148 | } |
||
| 149 | } catch (\Exception $e) { |
||
| 150 | $exitCode = 1; |
||
| 151 | $ioMethod = 'error'; |
||
| 152 | } |
||
| 153 | |||
| 154 | if (0 !== $exitCode) { |
||
| 155 | $io->error('Some errors occurred while installing assets.'); |
||
| 156 | } else { |
||
| 157 | if ($copyUsed) { |
||
| 158 | $io->note('Some assets were installed via copy. If you make changes to these assets you have to run this command again.'); |
||
| 159 | } |
||
| 160 | |||
| 161 | switch ($ioMethod) { |
||
| 162 | case 'success': |
||
| 163 | case 'warning':$io->$ioMethod('All deprecated SonataCoreBundle assets from SonataAdminBundle were successfully installed.'); break; |
||
| 164 | case 'error': |
||
| 165 | default: $io->$ioMethod('No deprecated SonataCoreBundle assets from SonataAdminBundle were provided by any bundle.'); break; |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | return $exitCode; |
||
| 170 | } |
||
| 171 | |||
| 262 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.