Issues (32)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Adapters/Phpunit/PrinterContents.php (13 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace NunoMaduro\Collision\Adapters\Phpunit;
4
5
use NunoMaduro\Collision\Exceptions\ShouldNotHappen;
6
use PHPUnit\Framework\AssertionFailedError;
7
use PHPUnit\Framework\Test;
8
use PHPUnit\Framework\TestCase;
9
use PHPUnit\Framework\TestSuite;
10
use PHPUnit\Framework\Warning;
11
use ReflectionObject;
12
use Symfony\Component\Console\Input\ArgvInput;
13
use Symfony\Component\Console\Output\ConsoleOutput;
14
use Throwable;
15
16
trait PrinterContents
17
{
18
    /**
19
     * Holds an instance of the style.
20
     *
21
     * Style is a class we use to interact with output.
22
     *
23
     * @var Style
24
     */
25
    private $style;
26
27
    /**
28
     * Holds the duration time of the test suite.
29
     *
30
     * @var Timer
31
     */
32
    private $timer;
33
34
    /**
35
     * Holds the state of the test
36
     * suite. The number of tests, etc.
37
     *
38
     * @var State
39
     */
40
    private $state;
41
42
    /**
43
     * If the test suite has ended before.
44
     *
45
     * @var bool
46
     */
47
    private $ended = false;
48
49
    /**
50
     * Creates a new instance of the listener.
51
     *
52
     * @param ConsoleOutput $output
53
     *
54
     * @throws \ReflectionException
55
     */
56 3
    public function __construct(ConsoleOutput $output = null)
57
    {
58 3
        if (intval(substr(\PHPUnit\Runner\Version::id(), 0, 1)) === 8) {
59 3
            parent::__construct();
60
        }
61
62 3
        $this->timer = Timer::start();
63
64 3
        $output = $output ?? new ConsoleOutput();
65 3
        ConfigureIO::of(new ArgvInput(), $output);
66
67 3
        $this->style = new Style($output);
68
        $dummyTest   = new class() extends TestCase {
69
        };
70
71 3
        $this->state = State::from($dummyTest);
0 ignored issues
show
Documentation Bug introduced by
It seems like \NunoMaduro\Collision\Ad...State::from($dummyTest) of type object<self> is incompatible with the declared type object<NunoMaduro\Collis...Adapters\Phpunit\State> of property $state.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
72 3
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77 View Code Duplication
    public function addError(Test $testCase, Throwable $throwable, float $time): void
0 ignored issues
show
The parameter $time is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
    {
79
        $testCase = $this->testCaseFromTest($testCase);
80
81
        $this->state->add(TestResult::fromTestCase($testCase, TestResult::FAIL));
82
83
        $this->style->writeError($this->state, $throwable);
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function addWarning(Test $testCase, Warning $warning, float $time): void
0 ignored issues
show
The parameter $time is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
90
    {
91
        $testCase = $this->testCaseFromTest($testCase);
92
93
        $this->state->add(TestResult::fromTestCase($testCase, TestResult::WARN, $warning->getMessage()));
94
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99
    public function addFailure(Test $testCase, AssertionFailedError $error, float $time): void
0 ignored issues
show
The parameter $time is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
100
    {
101
        $testCase = $this->testCaseFromTest($testCase);
102
103
        $this->state->add(TestResult::fromTestCase($testCase, TestResult::FAIL));
104
105
        $reflector = new ReflectionObject($error);
106
107
        if ($reflector->hasProperty('message')) {
108
            $message  = trim((string) preg_replace("/\r|\n/", ' ', $error->getMessage()));
109
            $property = $reflector->getProperty('message');
110
            $property->setAccessible(true);
111
            $property->setValue($error, $message);
112
        }
113
114
        $this->style->writeError($this->state, $error);
115
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120
    public function addIncompleteTest(Test $testCase, Throwable $t, float $time): void
0 ignored issues
show
The parameter $t is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $time is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
121
    {
122
        $testCase = $this->testCaseFromTest($testCase);
123
124
        $this->state->add(TestResult::fromTestCase($testCase, TestResult::INCOMPLETE));
125
    }
126
127
    /**
128
     * {@inheritdoc}
129
     */
130
    public function addRiskyTest(Test $testCase, Throwable $t, float $time): void
0 ignored issues
show
The parameter $time is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
131
    {
132
        $testCase = $this->testCaseFromTest($testCase);
133
134
        $this->state->add(TestResult::fromTestCase($testCase, TestResult::RISKY, $t->getMessage()));
135
    }
136
137
    /**
138
     * {@inheritdoc}
139
     */
140
    public function addSkippedTest(Test $testCase, Throwable $t, float $time): void
0 ignored issues
show
The parameter $time is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
141
    {
142
        $testCase = $this->testCaseFromTest($testCase);
143
144
        $this->state->add(TestResult::fromTestCase($testCase, TestResult::SKIPPED, $t->getMessage()));
145
    }
146
147
    /**
148
     * {@inheritdoc}
149
     */
150
    public function startTestSuite(TestSuite $suite): void
151
    {
152
        if ($this->state->suiteTotalTests === null) {
153
            $this->state->suiteTotalTests = $suite->count();
154
        }
155
    }
156
157
    /**
158
     * {@inheritdoc}
159
     */
160
    public function endTestSuite(TestSuite $suite): void
0 ignored issues
show
The parameter $suite is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
161
    {
162
        if (!$this->ended && $this->state->suiteTotalTests === $this->state->testSuiteTestsCount()) {
163
            $this->ended = true;
164
165
            $this->style->writeCurrentRecap($this->state);
166
167
            $this->style->updateFooter($this->state);
168
            $this->style->writeRecap($this->timer);
169
        }
170
    }
171
172
    /**
173
     * {@inheritdoc}
174
     */
175 1
    public function startTest(Test $testCase): void
176
    {
177 1
        $testCase = $this->testCaseFromTest($testCase);
178
179
        // Let's check first if the testCase is over.
180
        if ($this->state->testCaseHasChanged($testCase)) {
181
            $this->style->writeCurrentRecap($this->state);
182
183
            $this->state->moveTo($testCase);
184
        }
185
186
        $this->style->updateFooter($this->state, $testCase);
187
    }
188
189
    /**
190
     * {@inheritdoc}
191
     */
192 View Code Duplication
    public function endTest(Test $testCase, float $time): void
0 ignored issues
show
The parameter $time is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
193
    {
194
        $testCase = $this->testCaseFromTest($testCase);
195
196
        if (!$this->state->existsInTestCase($testCase)) {
197
            $this->state->add(TestResult::fromTestCase($testCase, TestResult::PASS));
198
        }
199
    }
200
201
    /**
202
     * Intentionally left blank as we output things on events of the listener.
203
     */
204
    public function write(string $content): void
0 ignored issues
show
The parameter $content is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
205
    {
206
        // ..
207
    }
208
209
    /**
210
     * Returns a test case from the given test.
211
     *
212
     * Note: This printer is do not work with normal Test classes - only
213
     * with Test Case classes. Please report an issue if you think
214
     * this should work any other way.
215
     */
216 1
    private function testCaseFromTest(Test $test): TestCase
217
    {
218 1
        if (!$test instanceof TestCase) {
219 1
            throw new ShouldNotHappen();
220
        }
221
222
        return $test;
223
    }
224
}
225