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

DX: Configurator - reduce cyclomatic complexity #291

Merged
merged 1 commit into from
Sep 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 25 additions & 18 deletions src/Bundle/CoverallsBundle/Config/Configurator.php
Expand Up @@ -82,7 +82,7 @@ protected function process(array $yml)
*
* @param array $options processed configuration
* @param string $rootDir path to project root directory
* @param InputInterface $input|null Input arguments
* @param InputInterface $input|null input arguments
*
* @return \PhpCoveralls\Bundle\CoverallsBundle\Config\Configuration
*/
Expand All @@ -94,23 +94,8 @@ protected function createConfiguration(array $options, $rootDir, InputInterface
$repoToken = $options['repo_token'];
$repoSecretToken = $options['repo_secret_token'];

// handle coverage clover
$coverage_clover = $options['coverage_clover'];
if ($input !== null && $input->hasOption('coverage_clover')) {
$option = $input->getOption('coverage_clover');
if (!empty($option)) {
$coverage_clover = $option;
}
}

// handle output json path
$json_path = $options['json_path'];
if ($input !== null && $input->hasOption('json_path')) {
$option = $input->getOption('json_path');
if (!empty($option)) {
$json_path = $option;
}
}
$coverage_clover = $this->getPotentiallyOverriddenOptionValue('coverage_clover', $options, $input);
$json_path = $this->getPotentiallyOverriddenOptionValue('json_path', $options, $input);

return $configuration
->setEntrypoint($options['entry_point'])
Expand Down Expand Up @@ -246,4 +231,26 @@ protected function ensureJsonPath($option, $rootDir, Path $file)

return $realpath;
}

/**
* Get option from YAML config, potentially overridden via input params.
*
* @param string $optionName option name
* @param array $options processed configuration
* @param InputInterface $input|null input arguments
*
* @return \PhpCoveralls\Bundle\CoverallsBundle\Config\Configuration
*/
private function getPotentiallyOverriddenOptionValue($optionName, array $options, InputInterface $input = null)
{
$value = $options[$optionName];
if ($input !== null && $input->hasOption($optionName)) {
$inputOverride = $input->getOption($optionName);
if (!empty($inputOverride)) {
$value = $inputOverride;
}
}

return $value;
}
}