Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of phpunit/php-code-coverage.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace SebastianBergmann\CodeCoverage\Node;
11
 
12
use function sprintf;
13
 
14
/**
15
 * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
16
 */
17
final class CrapIndex
18
{
19
    /**
20
     * @var int
21
     */
22
    private $cyclomaticComplexity;
23
 
24
    /**
25
     * @var float
26
     */
27
    private $codeCoverage;
28
 
29
    public function __construct(int $cyclomaticComplexity, float $codeCoverage)
30
    {
31
        $this->cyclomaticComplexity = $cyclomaticComplexity;
32
        $this->codeCoverage         = $codeCoverage;
33
    }
34
 
35
    public function asString(): string
36
    {
37
        if ($this->codeCoverage === 0.0) {
38
            return (string) ($this->cyclomaticComplexity ** 2 + $this->cyclomaticComplexity);
39
        }
40
 
41
        if ($this->codeCoverage >= 95) {
42
            return (string) $this->cyclomaticComplexity;
43
        }
44
 
45
        return sprintf(
46
            '%01.2F',
47
            $this->cyclomaticComplexity ** 2 * (1 - $this->codeCoverage / 100) ** 3 + $this->cyclomaticComplexity
48
        );
49
    }
50
}