Issues (76)

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/Runners/PHPUnit/WrapperRunner.php (10 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
declare(strict_types=1);
4
5
namespace ParaTest\Runners\PHPUnit;
6
7
class WrapperRunner extends BaseRunner
8
{
9
    const PHPUNIT_FAILURES = 1;
10
    const PHPUNIT_ERRORS = 2;
11
12
    /**
13
     * @var array
14
     */
15
    protected $streams;
16
17
    /**
18
     * @var Worker[]
19
     */
20
    protected $workers;
21
22
    /**
23
     * @var array
24
     */
25
    protected $modified;
26
27
    public function run()
28
    {
29
        parent::run();
30
31
        $this->startWorkers();
32
        $this->assignAllPendingTests();
33
        $this->sendStopMessages();
34
        $this->waitForAllToFinish();
35
        $this->complete();
36
    }
37
38
    protected function load()
39
    {
40
        if ($this->options->functional) {
0 ignored issues
show
The property $functional is declared protected in ParaTest\Runners\PHPUnit\Options. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
41
            throw new \RuntimeException('The `functional` option is not supported yet in the WrapperRunner. Only full classes can be run due to the current PHPUnit commands causing classloading issues.');
42
        }
43
        parent::load();
44
    }
45
46
    private function startWorkers()
47
    {
48
        $wrapper = realpath(__DIR__ . '/../../../bin/phpunit-wrapper');
49
        for ($i = 1; $i <= $this->options->processes; ++$i) {
0 ignored issues
show
The property $processes is declared protected in ParaTest\Runners\PHPUnit\Options. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
50
            $worker = new Worker();
51
            if ($this->options->noTestTokens) {
0 ignored issues
show
The property $noTestTokens is declared protected in ParaTest\Runners\PHPUnit\Options. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
52
                $token = null;
53
                $uniqueToken = null;
54
            } else {
55
                $token = $i;
56
                $uniqueToken = uniqid();
57
            }
58
            $worker->start($wrapper, $token, $uniqueToken);
59
            $this->streams[] = $worker->stdout();
60
            $this->workers[] = $worker;
61
        }
62
    }
63
64
    private function assignAllPendingTests()
65
    {
66
        $phpunit = $this->options->phpunit;
0 ignored issues
show
The property $phpunit is declared protected in ParaTest\Runners\PHPUnit\Options. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
67
        $phpunitOptions = $this->options->filtered;
0 ignored issues
show
The property $filtered is declared protected in ParaTest\Runners\PHPUnit\Options. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
68
        // $phpunitOptions['no-globals-backup'] = null;  // removed in phpunit 6.0
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
69
        while (count($this->pending)) {
70
            $this->waitForStreamsToChange($this->streams);
71
            foreach ($this->progressedWorkers() as $worker) {
72
                if ($worker->isFree()) {
73
                    $this->flushWorker($worker);
74
                    $pending = array_shift($this->pending);
75
                    if ($pending) {
76
                        $worker->assign($pending, $phpunit, $phpunitOptions);
77
                    }
78
                }
79
            }
80
        }
81
    }
82
83
    private function sendStopMessages()
84
    {
85
        foreach ($this->workers as $worker) {
86
            $worker->stop();
87
        }
88
    }
89
90
    private function waitForAllToFinish()
91
    {
92
        $toStop = $this->workers;
93
        while (count($toStop) > 0) {
94
            $toCheck = $this->streamsOf($toStop);
95
            $new = $this->waitForStreamsToChange($toCheck);
0 ignored issues
show
$new is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
96
            foreach ($this->progressedWorkers() as $index => $worker) {
97
                if (!$worker->isRunning()) {
98
                    $this->flushWorker($worker);
99
                    unset($toStop[$index]);
100
                }
101
            }
102
        }
103
    }
104
105
    // put on WorkersPool
106
    private function waitForStreamsToChange(array $modified)
107
    {
108
        $write = [];
109
        $except = [];
110
        $result = stream_select($modified, $write, $except, 1);
111
        if ($result === false) {
112
            throw new \RuntimeException('stream_select() returned an error while waiting for all workers to finish.');
113
        }
114
        $this->modified = $modified;
115
116
        return $result;
117
    }
118
119
    /**
120
     * put on WorkersPool.
121
     *
122
     * @return Worker[]
123
     */
124
    private function progressedWorkers(): array
125
    {
126
        $result = [];
127
        foreach ($this->modified as $modifiedStream) {
128
            $found = null;
129
            foreach ($this->streams as $index => $stream) {
130
                if ($modifiedStream === $stream) {
131
                    $found = $index;
132
                    break;
133
                }
134
            }
135
            $result[$found] = $this->workers[$found];
136
        }
137
        $this->modified = [];
138
139
        return $result;
140
    }
141
142
    /**
143
     * Returns the output streams of a subset of workers.
144
     *
145
     * @param array    keys are positions in $this->workers
146
     *
147
     * @return array
148
     */
149
    private function streamsOf(array $workers): array
150
    {
151
        $streams = [];
152
        foreach (array_keys($workers) as $index) {
153
            $streams[$index] = $this->streams[$index];
154
        }
155
156
        return $streams;
157
    }
158
159
    private function complete()
160
    {
161
        $this->setExitCode();
162
        $this->printer->printResults();
163
        $this->interpreter->rewind();
164
        $this->log();
165
        $this->logCoverage();
166
        $readers = $this->interpreter->getReaders();
167
        foreach ($readers as $reader) {
168
            $reader->removeLog();
169
        }
170
    }
171
172
    private function setExitCode()
173
    {
174
        if ($this->interpreter->getTotalErrors()) {
0 ignored issues
show
Documentation Bug introduced by
The method getTotalErrors does not exist on object<ParaTest\Logging\LogInterpreter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
175
            $this->exitcode = self::PHPUNIT_ERRORS;
176
        } elseif ($this->interpreter->getTotalFailures()) {
0 ignored issues
show
Documentation Bug introduced by
The method getTotalFailures does not exist on object<ParaTest\Logging\LogInterpreter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
177
            $this->exitcode = self::PHPUNIT_FAILURES;
178
        } else {
179
            $this->exitcode = 0;
180
        }
181
    }
182
183
    private function flushWorker(Worker $worker)
184
    {
185
        if ($this->hasCoverage()) {
186
            $this->getCoverage()->addCoverageFromFile($worker->getCoverageFileName());
187
        }
188
        $worker->printFeedback($this->printer);
189
        $worker->reset();
190
    }
191
192
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
193
    private function testIsStillRunning($test)
194
    {
195
        if(!$test->isDoneRunning()) return true;
196
        $this->setExitCode($test);
197
        $test->stop();
198
        if (static::PHPUNIT_FATAL_ERROR === $test->getExitCode())
199
            throw new \Exception($test->getStderr(), $test->getExitCode());
200
        return false;
201
    }
202
     */
203
}
204