| Conditions | 12 | 
| Paths | 376 | 
| Total Lines | 91 | 
| Code Lines | 61 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 6 | ||
| Bugs | 0 | 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 | ||
| 53 | protected function execute(InputInterface $input, OutputInterface $output) | ||
| 54 |     { | ||
| 55 |         $force = $input->getOption('force'); | ||
| 56 |         $demo = $input->getOption('demo'); | ||
|  | |||
| 57 | |||
| 58 |         try { | ||
| 59 | // ask to override existing site? | ||
| 60 |             if (Util\File::getFS()->exists(Util::joinFile($this->getPath(), $this->findConfigFile('name') ?: self::CONFIG_FILE[0])) && !$force) { | ||
| 61 |                 $output->writeln('<comment>Website already exists.</comment>'); | ||
| 62 |                 if (!$this->io->confirm('Do you want to override it?', false)) { | ||
| 63 | return 0; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | // define root path | ||
| 67 | $root = Util\Plateform::isPhar() ? Util\Plateform::getPharPath() . '/' : realpath(Util::joinFile(__DIR__, '/../../')); | ||
| 68 | // setup questions | ||
| 69 |             $title = $this->io->ask('Give a title to your new site', 'Site title'); | ||
| 70 |             $baseline = $this->io->ask('Describe your site in few words', ''); | ||
| 71 |             $baseurl = $this->io->ask('Base URL?', 'https://domain.tld/', [$this, 'validateUrl']); | ||
| 72 |             $description = $this->io->ask('Write a full description of your site', 'Site description.'); | ||
| 73 |             $authorName = $this->io->ask('What is the author name?', 'Cecil'); | ||
| 74 |             $authorUrl = $this->io->ask('What is the author URL?', 'https://cecil.app', [$this, 'validateUrl']); | ||
| 75 |             $demo = $this->io->confirm('Add demo content?', false); | ||
| 76 | // override skeleton default config | ||
| 77 | $config = Yaml::parseFile(Util::joinPath($root, 'resources/skeleton', self::CONFIG_FILE[0])); | ||
| 78 | $config = array_replace_recursive($config, [ | ||
| 79 | 'title' => $title, | ||
| 80 | 'baseline' => $baseline, | ||
| 81 | 'baseurl' => $baseurl, | ||
| 82 | 'description' => $description, | ||
| 83 | 'author' => [ | ||
| 84 | 'name' => $authorName, | ||
| 85 | 'url' => $authorUrl, | ||
| 86 | ], | ||
| 87 | ]); | ||
| 88 | $configYaml = Yaml::dump($config, 2, 2); | ||
| 89 |             Util\File::getFS()->dumpFile(Util::joinPath($this->getPath(), $this->findConfigFile('name') ?: self::CONFIG_FILE[0]), $configYaml); | ||
| 90 | // creates dir | ||
| 91 | foreach ( | ||
| 92 | [ | ||
| 93 |                     (string) $this->getBuilder()->getConfig()->get('assets.dir'), | ||
| 94 |                     (string) $this->getBuilder()->getConfig()->get('layouts.dir'), | ||
| 95 |                     (string) $this->getBuilder()->getConfig()->get('pages.dir'), | ||
| 96 |                     (string) $this->getBuilder()->getConfig()->get('static.dir'), | ||
| 97 | ] as $value | ||
| 98 |             ) { | ||
| 99 | Util\File::getFS()->mkdir(Util::joinPath($this->getPath(), $value)); | ||
| 100 | } | ||
| 101 | // copy files | ||
| 102 | foreach ( | ||
| 103 | [ | ||
| 104 | 'assets/favicon.png', | ||
| 105 | 'pages/index.md', | ||
| 106 | 'static/cecil-card.png', | ||
| 107 | ] as $value | ||
| 108 |             ) { | ||
| 109 | Util\File::getFS()->copy( | ||
| 110 | Util::joinPath($root, 'resources/skeleton', $value), | ||
| 111 | Util::joinPath($this->getPath(), $value) | ||
| 112 | ); | ||
| 113 | } | ||
| 114 | // demo: copy all files | ||
| 115 |             if ($demo) { | ||
| 116 | foreach ( | ||
| 117 | [ | ||
| 118 |                         (string) $this->getBuilder()->getConfig()->get('assets.dir'), | ||
| 119 |                         (string) $this->getBuilder()->getConfig()->get('layouts.dir'), | ||
| 120 |                         (string) $this->getBuilder()->getConfig()->get('pages.dir'), | ||
| 121 |                         (string) $this->getBuilder()->getConfig()->get('static.dir'), | ||
| 122 | ] as $value | ||
| 123 |                 ) { | ||
| 124 | Util\File::getFS()->mirror( | ||
| 125 | Util::joinPath($root, 'resources/skeleton', $value), | ||
| 126 | Util::joinPath($this->getPath(), $value) | ||
| 127 | ); | ||
| 128 | } | ||
| 129 | } | ||
| 130 | // done | ||
| 131 |             $output->writeln(sprintf('<info>Your new Cecil site is created in %s.</info>', realpath($this->getPath()))); | ||
| 132 | $this->io->newLine(); | ||
| 133 | $this->io->listing([ | ||
| 134 | 'You can download a theme from https://cecil.app/themes/', | ||
| 135 | 'You can create a new page with "cecil new:page"', | ||
| 136 | 'Start the built-in preview server via "cecil serve"', | ||
| 137 | ]); | ||
| 138 |             $this->io->text('Visit https://cecil.app for full documentation.'); | ||
| 139 |         } catch (\Exception $e) { | ||
| 140 | throw new RuntimeException(sprintf($e->getMessage())); | ||
| 141 | } | ||
| 142 | |||
| 143 | return 0; | ||
| 144 | } | ||
| 146 |