|
1
|
|
|
<?php |
|
2
|
|
|
namespace PressCLI\Command; |
|
3
|
|
|
|
|
4
|
|
|
use RuntimeException; |
|
5
|
|
|
use PressCLI\Lib\FileSystem; |
|
6
|
|
|
use PressCLI\Option\Configuration; |
|
7
|
|
|
use PressCLI\Option\GlobalConfiguration; |
|
8
|
|
|
use Symfony\Component\Console\Command\Command; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
|
|
14
|
|
|
class ConfigureCommand extends Command |
|
15
|
|
|
{ |
|
16
|
|
|
use FileSystem; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Configure create command. |
|
20
|
|
|
*/ |
|
21
|
|
|
protected function configure() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->setName('configure') |
|
24
|
|
|
->setDescription('Creates a new project directory and configuration.') |
|
25
|
|
|
->addArgument('project-name', InputArgument::OPTIONAL, 'The project name.') |
|
26
|
|
|
->addOption( |
|
27
|
|
|
'global', |
|
28
|
|
|
null, |
|
29
|
|
|
InputOption::VALUE_NONE, |
|
30
|
|
|
'Creates the global configuration if it does not already exist.' |
|
31
|
|
|
); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Execute create command. |
|
36
|
|
|
* |
|
37
|
|
|
* @param InputInterface $input |
|
38
|
|
|
* @param OutputInterface $output |
|
39
|
|
|
*/ |
|
40
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
41
|
|
|
{ |
|
42
|
|
|
$global = $input->getOption('global'); |
|
43
|
|
|
if ($global) { |
|
44
|
|
|
GlobalConfiguration::create($output); |
|
45
|
|
|
|
|
46
|
|
|
return; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$name = $input->getArgument('project-name'); |
|
50
|
|
|
if (!$name) { |
|
51
|
|
|
throw new RuntimeException("Project name is required when not using the --global option!"); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
// Handle directory creation and local configuration. |
|
55
|
|
|
$directory = getcwd() . "/{$name}"; |
|
56
|
|
|
$this->createProjectDirectory($directory, $output); |
|
57
|
|
|
Configuration::create($directory, $name, $input, $output, $this->getHelper('question')); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.