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

Give the ability to disable min score #298

Merged
merged 1 commit into from
Jan 31, 2021
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
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: ~