| Conditions | 5 |
| Paths | 16 |
| Total Lines | 95 |
| Code Lines | 63 |
| 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 |
||
| 37 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 38 | { |
||
| 39 | $name = $input->getArgument('name'); |
||
| 40 | $buildDir = $input->getArgument('build-dir'); |
||
| 41 | $sourceDir = $input->getArgument('source-dir'); |
||
| 42 | |||
| 43 | $progress = new ProgressBar($output, 17); |
||
| 44 | $progress->start(); |
||
| 45 | |||
| 46 | $filesystem = new Filesystem(); |
||
| 47 | |||
| 48 | $pwd = getcwd(); |
||
| 49 | if (is_dir($buildDir)) { |
||
| 50 | system("rm -rf ${buildDir}"); |
||
| 51 | } |
||
| 52 | |||
| 53 | // build env |
||
| 54 | $filesystem->mkdir($buildDir, 0755); |
||
| 55 | $progress->advance(); |
||
| 56 | |||
| 57 | $filesystem->mirror($sourceDir, "${buildDir}/${name}"); |
||
| 58 | $progress->advance(); |
||
| 59 | |||
| 60 | PurgeVendorsCommand::cleanVendors("${buildDir}/${name}/vendor", $progress); |
||
| 61 | |||
| 62 | $writableArray = [ |
||
| 63 | "${buildDir}/${name}/var/cache", |
||
| 64 | "${buildDir}/${name}/var/log", |
||
| 65 | "${buildDir}/${name}/public/uploads", |
||
| 66 | ]; |
||
| 67 | $filesystem->chmod($writableArray, 0777); |
||
| 68 | $progress->advance(); |
||
| 69 | |||
| 70 | chdir($buildDir); |
||
| 71 | $finder = new Finder(); |
||
| 72 | $finder |
||
| 73 | ->in($name) |
||
| 74 | ->files() |
||
| 75 | ->ignoreDotFiles(false); |
||
| 76 | |||
| 77 | $allFiles = []; |
||
| 78 | /** @var SfSplFileInfo $file */ |
||
| 79 | foreach ($finder as $file) { |
||
| 80 | $allFiles[] = $file->getRelativePathname(); |
||
| 81 | } |
||
| 82 | $progress->advance(); |
||
| 83 | |||
| 84 | // build zip |
||
| 85 | $zip = new ZipArchive(); |
||
| 86 | $fileName = "${name}.zip"; |
||
| 87 | if (true !== $zip->open($fileName, ZipArchive::CREATE)) { |
||
| 88 | $output->writeln("<error>Error creating ${fileName}</error>"); |
||
| 89 | } |
||
| 90 | |||
| 91 | foreach ($allFiles as $file) { |
||
| 92 | $zip->addFile("${name}/${file}"); |
||
| 93 | } |
||
| 94 | $progress->advance(); |
||
| 95 | |||
| 96 | $zip->close(); |
||
| 97 | $progress->advance(); |
||
| 98 | |||
| 99 | // build tar |
||
| 100 | $fileName = "${name}.tar"; |
||
| 101 | system("tar cp ${name} > ${fileName}"); |
||
| 102 | $progress->advance(); |
||
| 103 | system("gzip ${fileName}"); |
||
| 104 | $progress->advance(); |
||
| 105 | |||
| 106 | // checksums |
||
| 107 | $zipMd5 = md5_file("${name}.zip"); |
||
| 108 | $tarMd5 = md5_file("${name}.tar.gz"); |
||
| 109 | $zipSha1 = sha1_file("${name}.zip"); |
||
| 110 | $tarSha1 = sha1_file("${name}.tar.gz"); |
||
| 111 | |||
| 112 | $checksum = <<<CHECKSUM |
||
| 113 | -----------------md5sums----------------- |
||
| 114 | ${zipMd5} ${name}.zip |
||
| 115 | ${tarMd5} ${name}.tar.gz |
||
| 116 | -----------------sha1sums----------------- |
||
| 117 | ${zipSha1} ${name}.zip |
||
| 118 | ${tarSha1} ${name}.tar.gz |
||
| 119 | CHECKSUM; |
||
| 120 | file_put_contents("${name}-checksum.txt", $checksum); |
||
| 121 | $progress->advance(); |
||
| 122 | |||
| 123 | // cleanup |
||
| 124 | system("rm -rf ${buildDir} ${name}"); |
||
| 125 | chdir($pwd); |
||
| 126 | $progress->advance(); |
||
| 127 | $progress->finish(); |
||
| 128 | |||
| 129 | $output->writeln("<info>Artifacts built in ${buildDir}/ folder</info>"); |
||
| 130 | |||
| 131 | return 0; |
||
| 132 | } |
||
| 134 |