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 Basis; |
||
4 | |||
5 | use Basis\Converter; |
||
6 | use Basis\Service; |
||
7 | use PHPUnit\Framework\TestCase; |
||
8 | use ReflectionProperty; |
||
9 | use Tarantool\Mapper\Mapper; |
||
10 | use Tarantool\Mapper\Pool; |
||
11 | |||
12 | abstract class Test extends TestCase |
||
13 | { |
||
14 | use Toolkit; |
||
15 | |||
16 | public $params = []; |
||
17 | public $disableRemote = true; |
||
18 | |||
19 | public $mocks = []; |
||
20 | public $data = []; |
||
21 | |||
22 | 3 | public function __construct() |
|
23 | { |
||
24 | parent::__construct(); |
||
25 | |||
26 | $this->app = new Test\Application($this); |
||
27 | |||
28 | foreach ($this->mocks as [$method, $params, $result]) { |
||
29 | $this->mock($method, $params)->willReturn($result); |
||
0 ignored issues
–
show
|
|||
30 | } |
||
31 | |||
32 | $serviceData = []; |
||
33 | foreach ($this->data as $space => $data) { |
||
34 | [$service, $space] = explode('.', $space); |
||
0 ignored issues
–
show
The variable
$service seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?
This error can happen if you refactor code and forget to move the variable initialization. Let’s take a look at a simple example: function someFunction() {
$x = 5;
echo $x;
}
The above code is perfectly fine. Now imagine that we re-order the statements: function someFunction() {
echo $x;
$x = 5;
}
In that case,
Loading history...
|
|||
35 | if (!array_key_exists($service, $serviceData)) { |
||
0 ignored issues
–
show
The variable
$service seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?
This error can happen if you refactor code and forget to move the variable initialization. Let’s take a look at a simple example: function someFunction() {
$x = 5;
echo $x;
}
The above code is perfectly fine. Now imagine that we re-order the statements: function someFunction() {
echo $x;
$x = 5;
}
In that case,
Loading history...
|
|||
36 | $serviceData[$service] = []; |
||
0 ignored issues
–
show
The variable
$service seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?
This error can happen if you refactor code and forget to move the variable initialization. Let’s take a look at a simple example: function someFunction() {
$x = 5;
echo $x;
}
The above code is perfectly fine. Now imagine that we re-order the statements: function someFunction() {
echo $x;
$x = 5;
}
In that case,
Loading history...
|
|||
37 | } |
||
38 | $serviceData[$service][$space] = $data; |
||
0 ignored issues
–
show
The variable
$service seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?
This error can happen if you refactor code and forget to move the variable initialization. Let’s take a look at a simple example: function someFunction() {
$x = 5;
echo $x;
}
The above code is perfectly fine. Now imagine that we re-order the statements: function someFunction() {
echo $x;
$x = 5;
}
In that case,
Loading history...
|
|||
39 | } |
||
40 | |||
41 | $pool = $this->app->get(Pool::class); |
||
42 | $property = new ReflectionProperty(Pool::class, 'resolvers'); |
||
43 | $property->setAccessible(true); |
||
44 | $property->setValue($pool, []); |
||
45 | |||
46 | $service = $this->app->get(Service::class)->getName(); |
||
47 | $pool->register($service, function() { |
||
48 | return $this->app->get(Mapper::class); |
||
49 | }); |
||
50 | |||
51 | 3 | $pool->registerResolver(function($service) use ($serviceData) { |
|
52 | 3 | if (array_key_exists($service, $serviceData)) { |
|
53 | 2 | return new Test\Mapper($this, $service); |
|
54 | } |
||
55 | 2 | }); |
|
56 | } |
||
57 | |||
58 | 45 | public function setup() |
|
59 | { |
||
60 | 45 | $this->dispatch('tarantool.migrate'); |
|
61 | 45 | } |
|
62 | |||
63 | 45 | public function tearDown() |
|
64 | { |
||
65 | 45 | $this->dispatch('tarantool.clear'); |
|
66 | 45 | } |
|
67 | |||
68 | public $mockInstances = []; |
||
69 | |||
70 | 5 | public function mock(string $job, array $params = []) |
|
71 | { |
||
72 | 5 | if (!array_key_exists($job, $this->mockInstances)) { |
|
73 | 4 | $this->mockInstances[$job] = []; |
|
74 | } |
||
75 | |||
76 | 5 | $mock = new Test\Mock($this->get(Converter::class), $this, $params); |
|
77 | |||
78 | 5 | $this->mockInstances[$job][] = $mock; |
|
79 | |||
80 | 5 | return $mock; |
|
81 | } |
||
82 | } |
||
83 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.