Skip to content

Commit

Permalink
Give the ability to disable min score (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
villfa authored Jan 31, 2021
1 parent 961e415 commit d5a474b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ A sample `churn.yml` file looks like:
filesToShow: 10

# The minimum score a file need to display in the results table.
# Disabled if null.
# Default: 0.1
minScoreToShow: 0

Expand Down
12 changes: 8 additions & 4 deletions src/Configuration/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Config
*/
private function __construct(array $configuration = [])
{
if (!empty($configuration)) {
if ([] !== $configuration) {
(new Validator())->validateConfigurationValues($configuration);
}

Expand Down Expand Up @@ -78,11 +78,15 @@ public function getFilesToShow(): int
}

/**
* Get the minimum score a file need to display.
* Get the minimum score a file need to display (ignored if null).
*/
public function getMinScoreToShow(): float
public function getMinScoreToShow(): ?float
{
return $this->configuration['minScoreToShow'] ?? self::MINIMUM_SCORE_TO_SHOW;
if (\array_key_exists('minScoreToShow', $this->configuration)) {
return $this->configuration['minScoreToShow'];
}

return self::MINIMUM_SCORE_TO_SHOW;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private function validateFilesToShow(array $configuration): void
*/
private function validateMinScoreToShow(array $configuration): void
{
if (!\array_key_exists('minScoreToShow', $configuration)) {
if (!\array_key_exists('minScoreToShow', $configuration) || null === $configuration['minScoreToShow']) {
return;
}

Expand Down
11 changes: 10 additions & 1 deletion tests/Unit/Configuration/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public function it_can_return_its_default_values_when_instantiated_without_any_p
public function it_can_return_its_values_when_instantiated_parameters()
{
$filesToShow = 13;

$directoriesToScan = ['src', 'tests'];
$minScoreToShow = 5;
$parallelJobs = 7;
Expand Down Expand Up @@ -73,4 +72,14 @@ public function it_can_return_its_values_when_instantiated_parameters()
$this->assertSame($fileExtensions, $config->getFileExtensions());
$this->assertSame($vcs, $config->getVCS());
}

/** @test */
public function it_accepts_null_for_min_score_to_show()
{
$config = Config::create([
'minScoreToShow' => null,
]);

$this->assertNull($config->getMinScoreToShow());
}
}
3 changes: 2 additions & 1 deletion tests/docker/fossil/churn.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vcs: fossil
directoriesToScan:
- /tmp/test
- /tmp/test
minScoreToShow: ~

0 comments on commit d5a474b

Please sign in to comment.