Passed
Push — master ( 3f4221...33ba2d )
by Maks
03:05
created

MutantExecutionResult::getMutatedCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * This code is licensed under the BSD 3-Clause License.
4
 *
5
 * Copyright (c) 2017, Maks Rafalko
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions are met:
10
 *
11
 * * Redistributions of source code must retain the above copyright notice, this
12
 *   list of conditions and the following disclaimer.
13
 *
14
 * * Redistributions in binary form must reproduce the above copyright notice,
15
 *   this list of conditions and the following disclaimer in the documentation
16
 *   and/or other materials provided with the distribution.
17
 *
18
 * * Neither the name of the copyright holder nor the names of its
19
 *   contributors may be used to endorse or promote products derived from
20
 *   this software without specific prior written permission.
21
 *
22
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
 */
33
34
declare(strict_types=1);
35
36
namespace Infection\Mutant;
37
38
use function array_keys;
39
use Infection\Mutator\ProfileList;
40
use Webmozart\Assert\Assert;
41
42
/**
43
 * @internal
44
 * @final
45
 */
46
class MutantExecutionResult
47
{
48
    private $processCommandLine;
49
    private $processOutput;
50
    private $detectionStatus;
51
    private $mutantDiff;
52
    private $mutatorName;
53
    private $originalFilePath;
54
    private $originalStartingLine;
55
    private $originalCode;
56
    private $mutatedCode;
57
58
    public function __construct(
59
        string $processCommandLine,
60
        string $processOutput,
61
        string $detectionStatus,
62
        string $mutantDiff,
63
        string $mutatorName,
64
        string $originalFilePath,
65
        int $originalStartingLine,
66
        string $originalCode,
67
        string $mutatedCode
68
    ) {
69
        Assert::oneOf($detectionStatus, DetectionStatus::ALL);
70
        Assert::oneOf($mutatorName, array_keys(ProfileList::ALL_MUTATORS));
71
72
        $this->processCommandLine = $processCommandLine;
73
        $this->processOutput = $processOutput;
74
        $this->detectionStatus = $detectionStatus;
75
        $this->mutantDiff = $mutantDiff;
76
        $this->mutatorName = $mutatorName;
77
        $this->originalFilePath = $originalFilePath;
78
        $this->originalStartingLine = $originalStartingLine;
79
        $this->originalCode = $originalCode;
80
        $this->mutatedCode = $mutatedCode;
81
    }
82
83
    public static function createFromNonCoveredMutant(Mutant $mutant): self
84
    {
85
        $mutation = $mutant->getMutation();
86
87
        return new self(
88
            '',
89
            '',
90
            DetectionStatus::NOT_COVERED,
91
            $mutant->getDiff(),
92
            $mutant->getMutation()->getMutatorName(),
93
            $mutation->getOriginalFilePath(),
94
            $mutation->getOriginalStartingLine(),
95
            $mutant->getPrettyPrintedOriginalCode(),
96
            $mutant->getMutatedCode()
97
        );
98
    }
99
100
    public function getProcessCommandLine(): string
101
    {
102
        return $this->processCommandLine;
103
    }
104
105
    public function getProcessOutput(): string
106
    {
107
        return $this->processOutput;
108
    }
109
110
    public function getDetectionStatus(): string
111
    {
112
        return $this->detectionStatus;
113
    }
114
115
    public function getMutantDiff(): string
116
    {
117
        return $this->mutantDiff;
118
    }
119
120
    public function getMutatorName(): string
121
    {
122
        return $this->mutatorName;
123
    }
124
125
    public function getOriginalFilePath(): string
126
    {
127
        return $this->originalFilePath;
128
    }
129
130
    public function getOriginalStartingLine(): int
131
    {
132
        return $this->originalStartingLine;
133
    }
134
135
    public function getOriginalCode(): string
136
    {
137
        return $this->originalCode;
138
    }
139
140
    public function getMutatedCode(): string
141
    {
142
        return $this->mutatedCode;
143
    }
144
}
145