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\Driver;
11
 
12
use function sprintf;
13
use SebastianBergmann\CodeCoverage\BranchAndPathCoverageNotSupportedException;
14
use SebastianBergmann\CodeCoverage\DeadCodeDetectionNotSupportedException;
15
use SebastianBergmann\CodeCoverage\Filter;
16
use SebastianBergmann\CodeCoverage\NoCodeCoverageDriverAvailableException;
17
use SebastianBergmann\CodeCoverage\NoCodeCoverageDriverWithPathCoverageSupportAvailableException;
18
use SebastianBergmann\CodeCoverage\RawCodeCoverageData;
19
 
20
/**
21
 * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
22
 */
23
abstract class Driver
24
{
25
    /**
26
     * @var int
27
     *
28
     * @see http://xdebug.org/docs/code_coverage
29
     */
30
    public const LINE_NOT_EXECUTABLE = -2;
31
 
32
    /**
33
     * @var int
34
     *
35
     * @see http://xdebug.org/docs/code_coverage
36
     */
37
    public const LINE_NOT_EXECUTED = -1;
38
 
39
    /**
40
     * @var int
41
     *
42
     * @see http://xdebug.org/docs/code_coverage
43
     */
44
    public const LINE_EXECUTED = 1;
45
 
46
    /**
47
     * @var int
48
     *
49
     * @see http://xdebug.org/docs/code_coverage
50
     */
51
    public const BRANCH_NOT_HIT = 0;
52
 
53
    /**
54
     * @var int
55
     *
56
     * @see http://xdebug.org/docs/code_coverage
57
     */
58
    public const BRANCH_HIT = 1;
59
 
60
    /**
61
     * @var bool
62
     */
63
    private $collectBranchAndPathCoverage = false;
64
 
65
    /**
66
     * @var bool
67
     */
68
    private $detectDeadCode = false;
69
 
70
    /**
71
     * @throws NoCodeCoverageDriverAvailableException
72
     * @throws PcovNotAvailableException
73
     * @throws PhpdbgNotAvailableException
74
     * @throws Xdebug2NotEnabledException
75
     * @throws Xdebug3NotEnabledException
76
     * @throws XdebugNotAvailableException
77
     *
78
     * @deprecated Use DriverSelector::forLineCoverage() instead
79
     */
80
    public static function forLineCoverage(Filter $filter): self
81
    {
82
        return (new Selector)->forLineCoverage($filter);
83
    }
84
 
85
    /**
86
     * @throws NoCodeCoverageDriverWithPathCoverageSupportAvailableException
87
     * @throws Xdebug2NotEnabledException
88
     * @throws Xdebug3NotEnabledException
89
     * @throws XdebugNotAvailableException
90
     *
91
     * @deprecated Use DriverSelector::forLineAndPathCoverage() instead
92
     */
93
    public static function forLineAndPathCoverage(Filter $filter): self
94
    {
95
        return (new Selector)->forLineAndPathCoverage($filter);
96
    }
97
 
98
    public function canCollectBranchAndPathCoverage(): bool
99
    {
100
        return false;
101
    }
102
 
103
    public function collectsBranchAndPathCoverage(): bool
104
    {
105
        return $this->collectBranchAndPathCoverage;
106
    }
107
 
108
    /**
109
     * @throws BranchAndPathCoverageNotSupportedException
110
     */
111
    public function enableBranchAndPathCoverage(): void
112
    {
113
        if (!$this->canCollectBranchAndPathCoverage()) {
114
            throw new BranchAndPathCoverageNotSupportedException(
115
                sprintf(
116
                    '%s does not support branch and path coverage',
117
                    $this->nameAndVersion()
118
                )
119
            );
120
        }
121
 
122
        $this->collectBranchAndPathCoverage = true;
123
    }
124
 
125
    public function disableBranchAndPathCoverage(): void
126
    {
127
        $this->collectBranchAndPathCoverage = false;
128
    }
129
 
130
    public function canDetectDeadCode(): bool
131
    {
132
        return false;
133
    }
134
 
135
    public function detectsDeadCode(): bool
136
    {
137
        return $this->detectDeadCode;
138
    }
139
 
140
    /**
141
     * @throws DeadCodeDetectionNotSupportedException
142
     */
143
    public function enableDeadCodeDetection(): void
144
    {
145
        if (!$this->canDetectDeadCode()) {
146
            throw new DeadCodeDetectionNotSupportedException(
147
                sprintf(
148
                    '%s does not support dead code detection',
149
                    $this->nameAndVersion()
150
                )
151
            );
152
        }
153
 
154
        $this->detectDeadCode = true;
155
    }
156
 
157
    public function disableDeadCodeDetection(): void
158
    {
159
        $this->detectDeadCode = false;
160
    }
161
 
162
    abstract public function nameAndVersion(): string;
163
 
164
    abstract public function start(): void;
165
 
166
    abstract public function stop(): RawCodeCoverageData;
167
}