Passed
Push — master ( ed3493...5e2464 )
by Fabien
02:38
created

MaxScoreChecker::isOverThreshold()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 9
nc 4
nop 3
dl 0
loc 16
rs 8.8333
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Churn\Command\Helper;
6
7
use Churn\Result\ResultAccumulator;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\ConsoleOutputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * @internal
14
 */
15
class MaxScoreChecker
16
{
17
18
    /**
19
     * @var float|null
20
     */
21
    private $maxScoreThreshold;
22
23
    /**
24
     * @param float|null $maxScoreThreshold The max score threshold.
25
     */
26
    public function __construct(?float $maxScoreThreshold)
27
    {
28
        $this->maxScoreThreshold = $maxScoreThreshold;
29
    }
30
31
    /**
32
     * @param InputInterface $input Input.
33
     * @param OutputInterface $output Output.
34
     * @param ResultAccumulator $report The report containing the scores.
35
     */
36
    public function isOverThreshold(InputInterface $input, OutputInterface $output, ResultAccumulator $report): bool
37
    {
38
        $maxScore = $report->getMaxScore();
39
40
        if (null === $this->maxScoreThreshold || null === $maxScore || $maxScore <= $this->maxScoreThreshold) {
41
            return false;
42
        }
43
44
        if ('text' === $input->getOption('format') || !empty($input->getOption('output'))) {
45
            $output = $output instanceof ConsoleOutputInterface
46
                ? $output->getErrorOutput()
47
                : $output;
48
            $output->writeln('<error>Max score is over the threshold</>');
49
        }
50
51
        return true;
52
    }
53
}
54