Passed
Push — master ( 369dd9...0c3679 )
by Fabien
01:59
created

MaxScoreChecker::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
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\OutputInterface;
10
11
/**
12
 * @internal
13
 */
14
class MaxScoreChecker
15
{
16
17
    /**
18
     * @var float|null
19
     */
20
    private $maxScoreThreshold;
21
22
    /**
23
     * @param float|null $maxScoreThreshold The max score threshold.
24
     */
25
    public function __construct(?float $maxScoreThreshold)
26
    {
27
        $this->maxScoreThreshold = $maxScoreThreshold;
28
    }
29
30
    /**
31
     * @param InputInterface $input Input.
32
     * @param OutputInterface $output Output.
33
     * @param ResultAccumulator $report The report containing the scores.
34
     */
35
    public function isOverThreshold(InputInterface $input, OutputInterface $output, ResultAccumulator $report): bool
36
    {
37
        $maxScore = $report->getMaxScore();
38
39
        if (null === $this->maxScoreThreshold || null === $maxScore || $maxScore <= $this->maxScoreThreshold) {
40
            return false;
41
        }
42
43
        if ('text' === $input->getOption('format') || !empty($input->getOption('output'))) {
44
            $output->writeln('<error>Max score is over the threshold</>');
45
        }
46
47
        return true;
48
    }
49
}
50