Skip to content

Commit 4e82de4

Browse files
committed
Extract BaseCommand from CompareCommand.
- This sets the configuration values for all commands. Configuration::defaults() must now receive a configuration name file when called (such that other apps using php-semver-checker can create their own configuration file, see php-semver-checker-git).
1 parent 9ec3237 commit 4e82de4

File tree

3 files changed

+39
-28
lines changed

3 files changed

+39
-28
lines changed

src/PHPSemVerChecker/Configuration/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public static function fromFile($file)
3737
/**
3838
* @return \PHPSemVerChecker\Configuration\Configuration
3939
*/
40-
public static function defaults()
40+
public static function defaults($name)
4141
{
42-
return self::fromFile(['?php-semver-checker.yml.dist', '?php-semver-checker.yml']);
42+
return self::fromFile(['?'.$name.'.yml.dist', '?'.$name.'.yml']);
4343
}
4444

4545
/**
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace PHPSemVerChecker\Console\Command;
4+
5+
use PHPSemVerChecker\Configuration\Configuration;
6+
use PHPSemVerChecker\Configuration\LevelMapping;
7+
use PHPSemVerChecker\Console\InputMerger;
8+
use Symfony\Component\Console\Command\Command;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
12+
class BaseCommand extends Command
13+
{
14+
/**
15+
* @var \PHPSemVerChecker\Configuration\Configuration
16+
*/
17+
protected $config;
18+
19+
/**
20+
* @param \Symfony\Component\Console\Input\InputInterface $input
21+
* @param \Symfony\Component\Console\Output\OutputInterface $output
22+
*/
23+
protected function initialize(InputInterface $input, OutputInterface $output)
24+
{
25+
parent::initialize($input, $output);
26+
$configPath = $input->getOption('config');
27+
$this->config = $configPath ? Configuration::fromFile($configPath) : Configuration::defaults('php-semver-checker');
28+
$inputMerger = new InputMerger();
29+
$inputMerger->merge($input, $this->config);
30+
31+
// Set overrides
32+
LevelMapping::setOverrides($this->config->getLevelMapping());
33+
}
34+
}

src/PHPSemVerChecker/Console/Command/CompareCommand.php

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,18 @@
55
use PHPSemVerChecker\Analyzer\Analyzer;
66
use PHPSemVerChecker\Configuration\Configuration;
77
use PHPSemVerChecker\Configuration\LevelMapping;
8-
use PHPSemVerChecker\Console\InputMerger;
98
use PHPSemVerChecker\Filter\SourceFilter;
109
use PHPSemVerChecker\Finder\Finder;
1110
use PHPSemVerChecker\Reporter\JsonReporter;
1211
use PHPSemVerChecker\Reporter\Reporter;
1312
use PHPSemVerChecker\Scanner\ProgressScanner;
1413
use PHPSemVerChecker\Scanner\Scanner;
15-
use Symfony\Component\Console\Command\Command;
1614
use Symfony\Component\Console\Input\InputArgument;
1715
use Symfony\Component\Console\Input\InputInterface;
1816
use Symfony\Component\Console\Input\InputOption;
1917
use Symfony\Component\Console\Output\OutputInterface;
2018

21-
class CompareCommand extends Command {
22-
/**
23-
* @var \PHPSemVerChecker\Configuration\Configuration
24-
*/
25-
protected $config;
26-
19+
class CompareCommand extends BaseCommand {
2720
protected function configure()
2821
{
2922
$this
@@ -32,32 +25,16 @@ protected function configure()
3225
->setDefinition([
3326
new InputArgument('source-before', InputArgument::REQUIRED, 'A base directory to check (ex my-test)'),
3427
new InputArgument('source-after', InputArgument::REQUIRED, 'A base directory to check against (ex my-test)'),
35-
new InputOption('include-before', null, InputOption::VALUE_OPTIONAL, 'List of paths to include <info>(comma separated)</info>'),
28+
new InputOption('include-before', null, InputOption::VALUE_OPTIONAL, 'List of paths to include <info>(comma separated)</info>'),
3629
new InputOption('include-after', null, InputOption::VALUE_OPTIONAL, 'List of paths to include <info>(comma separated)</info>'),
37-
new InputOption('exclude-before', null, InputOption::VALUE_REQUIRED, 'List of paths to exclude <info>(comma separated)</info>'),
30+
new InputOption('exclude-before', null, InputOption::VALUE_REQUIRED, 'List of paths to exclude <info>(comma separated)</info>'),
3831
new InputOption('exclude-after', null, InputOption::VALUE_REQUIRED, 'List of paths to exclude <info>(comma separated)</info>'),
3932
new InputOption('full-path', null, InputOption::VALUE_NONE, 'Display the full path to the file instead of the relative path'),
4033
new InputOption('config', null, InputOption::VALUE_REQUIRED, 'A configuration file to configure php-semver-checker'),
4134
new InputOption('to-json', null, InputOption::VALUE_REQUIRED, 'Output the result to a JSON file')
4235
]);
4336
}
4437

45-
/**
46-
* @param \Symfony\Component\Console\Input\InputInterface $input
47-
* @param \Symfony\Component\Console\Output\OutputInterface $output
48-
*/
49-
protected function initialize(InputInterface $input, OutputInterface $output)
50-
{
51-
parent::initialize($input, $output);
52-
$configPath = $input->getOption('config');
53-
$this->config = $configPath ? Configuration::fromFile($configPath) : Configuration::defaults();
54-
$inputMerger = new InputMerger();
55-
$inputMerger->merge($input, $this->config);
56-
57-
// Set overrides
58-
LevelMapping::setOverrides($this->config->getLevelMapping());
59-
}
60-
6138
/**
6239
* @param \Symfony\Component\Console\Input\InputInterface $input
6340
* @param \Symfony\Component\Console\Output\OutputInterface $output

0 commit comments

Comments
 (0)