Skip to content

Commit 31f1ab0

Browse files
committed
[#66] Use Yaml instead of Json for the configuration file
[#59] Read php-semver-checker.yml configuration file by default
1 parent 94f517a commit 31f1ab0

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"require": {
2929
"php": ">=5.4.0",
3030

31+
"hassankhan/config": "~0.8",
3132
"herrera-io/phar-update": "~2.0",
3233
"nikic/php-parser": "dev-features/php-semver-checker",
3334
"symfony/console": "~2.7",

src/PHPSemVerChecker/Configuration/Configuration.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPSemVerChecker\Configuration;
44

5+
use Noodlehaus\Config;
56
use PHPSemVerChecker\SemanticVersioning\Level;
67

78
class Configuration
@@ -12,29 +13,32 @@ class Configuration
1213
protected $mapping = [];
1314

1415
/**
15-
* @param string $file
16+
* @param string|array $file
1617
* @return \PHPSemVerChecker\Configuration\Configuration
1718
*/
1819
public static function fromFile($file)
1920
{
2021
$configuration = new Configuration();
21-
$config = json_decode(file_get_contents($file), true);
22+
$config = new Config($file);
2223

23-
$configuration->extractMapping($config);
24+
$configuration->extractMapping($config->get('level.mapping', []));
2425

2526
return $configuration;
2627
}
2728

2829
/**
29-
* @param array $config
30+
* @return \PHPSemVerChecker\Configuration\Configuration
3031
*/
31-
protected function extractMapping(array $config)
32+
public static function defaults()
3233
{
33-
if ( ! array_key_exists('level', $config) || ! array_key_exists('mapping', $config['level'])) {
34-
return;
35-
}
34+
return self::fromFile(['?php-semver-checker.yml.dist', '?php-semver-checker.yml']);
35+
}
3636

37-
$mapping = $config['level']['mapping'];
37+
/**
38+
* @param array $config
39+
*/
40+
protected function extractMapping(array $mapping)
41+
{
3842
foreach ($mapping as &$level) {
3943
$level = Level::fromString($level);
4044
}

src/PHPSemVerChecker/Console/Command/CompareCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
4141
$startTime = microtime(true);
4242

4343
$config = $input->getOption('config');
44-
$configuration = $config ? Configuration::fromFile($config) : new Configuration();
44+
$configuration = $config ? Configuration::fromFile($config) : Configuration::defaults();
4545

4646
// Set overrides
4747
LevelMapping::setOverrides($configuration->getLevelMapping());

0 commit comments

Comments
 (0)