Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --project option to init command #11

Merged
merged 4 commits into from
Jul 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion config/drupal/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ application:
enabled: false
exception: false
phpcbf:
enabled: false
enabled: true
exception: false
file:
standard: vendor/drupal/coder/coder_sniffer/Drupal/ruleset.xml
phpcs:
enabled: true
exception: false
Expand Down
36 changes: 0 additions & 36 deletions config/php/config.yml

This file was deleted.

36 changes: 0 additions & 36 deletions config/symfony/config.yml

This file was deleted.

29 changes: 25 additions & 4 deletions src/Command/AnalyzeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class AnalyzeCommand extends Command

private $directory;

private $projects = [
'php',
'symfony',
'drupal'
];

protected function configure()
{
$this
Expand All @@ -26,7 +32,10 @@ protected function configure()
'project',
null,
InputOption::VALUE_OPTIONAL,
'Project name must be (php, symfony, drupal) or could be empty if a phpqa.yml or phpqa.yml.dist exists at current directory.'
sprintf(
'Project name must be (%) or could be empty if a phpqa.yml or phpqa.yml.dist exists at current directory.',
implode(',', $this->projects)
)
)
->addOption(
'files',
Expand All @@ -50,10 +59,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
*/
$config = $application->getConfig();

if (!$project && !$config->isCustom()) {
if (!$config->isCustom() && !$project) {
throw new \Exception(
sprintf(
'No local phpqa.yml or phpqa.yml.dist at current working directory ' .
'you must provide a valid project value (%s)',
implode(',', $this->projects)
)
);
}

if (!$config->isCustom() && !in_array($project, $this->projects)) {
throw new \Exception(
'No local phpqa.yml or phpqa.yml.dist at current working directory ' .
'you must provide a valid project name (php, symfony or drupal)'
sprintf(
'You must provide a valid project value (%s)',
implode(',', $this->projects)
)
);
}

Expand Down
56 changes: 49 additions & 7 deletions src/Command/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class InitCommand extends Command
'destination' => 'drupal/config.yml',
],
[
'source' => 'php/config.yml',
'source' => '/../phpqa.yml',
'destination' => 'php/config.yml',
],
[
'source' => 'symfony/config.yml',
'source' => '/../phpqa.yml',
'destination' => 'symfony/config.yml',
],
[
Expand All @@ -36,6 +36,17 @@ class InitCommand extends Command
],
];

private $projects = [
'php',
'symfony',
'drupal'
];

private $dirs = [
'home',
'current'
];

protected function configure()
{
$this
Expand All @@ -45,7 +56,19 @@ protected function configure()
'dir',
null,
InputOption::VALUE_REQUIRED,
'Directory to copy file(s) valid options home, current'
sprintf(
'Directory to copy file(s) valid options (%s)',
implode($this->dirs)
)
)
->addOption(
'project',
null,
InputOption::VALUE_OPTIONAL,
sprintf(
'Project name to copy config from, must be (%s).',
implode(',', $this->projects)
)
)
->addOption(
'override',
Expand All @@ -62,9 +85,22 @@ protected function execute(InputInterface $input, OutputInterface $output)

$dir = $input->getOption('dir');

if (!$dir) {
if (!$dir || !in_array($dir, $this->dirs)) {
throw new \Exception(
'You must provide a valid dir value (home or current)'
sprintf(
'You must provide a valid dir value (%s)',
implode(',', $this->dirs)
)
);
}

$project = $input->getOption('project');
if ($project && !in_array($project, $this->projects)) {
throw new \Exception(
sprintf(
'You must provide a valid project value (%s)',
implode(',', $this->projects)
)
);
}

Expand All @@ -74,20 +110,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

if ($dir === 'current') {
$this->copyCurrentDirectory($output, $config, $override);
$this->copyCurrentDirectory($output, $config, $override, $project);
}

if ($dir === 'home') {
$this->copyHomeDirectory($output, $config, $override);
}
}

private function copyCurrentDirectory($output, $config, $override)
private function copyCurrentDirectory($output, $config, $override, $project)
{
$baseConfigDirectory = $config->getBaseConfigDirectory();
$currentDirectory = $config->getApplicationDirectory();

$source = $baseConfigDirectory.'/../phpqa.yml';

$configFile = $baseConfigDirectory.$project.'/config.yml';
if (file_exists($configFile)) {
$source = $configFile;
}

$destination = $currentDirectory.'phpqa.yml';

if ($this->copyFile($source, $destination, $override)) {
Expand Down