Issues (94)

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.

Tests/Unit/Collection/SeedCollectionTest.php (18 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
namespace TildBJ\Seeder\Tests\Unit\Collection;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2018 Dennis Römmich <[email protected]>
8
 *
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 2 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
use TildBJ\Seeder\Collection\SeedCollection;
28
use Nimut\TestingFramework\TestCase\UnitTestCase;
29
use TYPO3\CMS\Core\Utility\GeneralUtility;
30
31
/**
32
 * SeedCollectionTest
33
 *
34
 * @author Dennis Römmich<[email protected]>
35
 * @copyright Copyright belongs to the respective authors
36
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
37
 */
38
class SeedCollectionTest extends UnitTestCase
39
{
40
    /**
41
     * @var \TildBJ\Seeder\SeedCollection
42
     */
43
    protected $subject;
44
45
    public function setUp()
46
    {
47
        $this->subject = new SeedCollection();
48
    }
49
50
    /**
51
     * @method attach
52
     * @test
53
     */
54
    public function attachAttachesNewItemIfItNotExist()
55
    {
56
        $seed = $this->createMock(\TildBJ\Seeder\Seed::class);
57
        $this->subject->attach($seed);
0 ignored issues
show
$seed is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<TildBJ\Seeder\Seed>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
        $this->assertSame($seed, $this->subject->current()['NEW1']);
59
    }
60
61
    /**
62
     * @method attach
63
     * @test
64
     */
65
    public function attachAttachesOnlyOneSeedIfSeedsAreIdentical()
66
    {
67
        $seed = $this->createMock(\TildBJ\Seeder\Seed::class);
68
        $this->subject->attach($seed);
0 ignored issues
show
$seed is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<TildBJ\Seeder\Seed>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
69
        $this->subject->attach($seed);
0 ignored issues
show
$seed is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<TildBJ\Seeder\Seed>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
70
        $this->assertSame([
71
            0 => 'NEW1',
72
            1 => 'NEW2',
73
        ], array_keys($this->subject->current()));
74
    }
75
76
    /**
77
     * @param $name
78
     * @return \PHPUnit_Framework_MockObject_MockObject
79
     */
80
    protected function mockSeed($name)
81
    {
82
        $seed = $this->createMock(\TildBJ\Seeder\Seed::class);
83
        $seed->method('getTitle')->willReturn($name);
84
        $seed->method('getTarget')->willReturn(strtolower(preg_replace('/\B([A-Z])/', '_$1', $name)));
85
        $seed->method('getProperties')->willReturn(['pid' => 123]);
86
87
        return $seed;
88
    }
89
90
    /**
91
     * @test
92
     * @method get
93
     */
94 View Code Duplication
    public function getReturnsArrayWithTwoKeysWhenClassNameFooBar()
0 ignored issues
show
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...
95
    {
96
        $seeder = $this->createMock(\TildBJ\Seeder\Seeder::class);
97
        $seeder->method('getClass')->willReturn('FooBar');
98
        $fooBarSeed = $this->mockSeed('FooBar');
99
        $fooSeed = $this->mockSeed('Foo');
100
        $barSeed = $this->mockSeed('Bar');
101
102
        // NEW1
103
        $this->subject->attach($fooBarSeed);
104
        // NEW2
105
        $this->subject->attach($fooSeed);
106
        // NEW3
107
        $this->subject->attach(clone $fooBarSeed);
108
        // NEW4
109
        $this->subject->attach($barSeed);
110
111
        $this->subject->amount = 4;
0 ignored issues
show
Accessing amount on the interface TildBJ\Seeder\SeedCollection suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
112
        $this->assertSame([
113
            0 => 'NEW1',
114
            1 => 'NEW3',
115
        ], array_keys($this->subject->get($seeder)));
0 ignored issues
show
$seeder is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<TildBJ\Seeder\Seeder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
116
    }
117
118
    /**
119
     * @test
120
     * @method get
121
     */
122 View Code Duplication
    public function getReturnsArrayWithOneKeyWhenClassNameFoo()
0 ignored issues
show
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...
123
    {
124
        $seeder = $this->createMock(\TildBJ\Seeder\Seeder::class);
125
        $seeder->method('getClass')->willReturn('Foo');
126
        $fooBarSeed = $this->mockSeed('FooBar');
127
        $fooSeed = $this->mockSeed('Foo');
128
        $barSeed = $this->mockSeed('Bar');
129
130
        // NEW1
131
        $this->subject->attach($fooBarSeed);
132
        // NEW2
133
        $this->subject->attach($fooSeed);
134
        // NEW3
135
        $this->subject->attach($fooBarSeed);
136
        // NEW4
137
        $this->subject->attach($barSeed);
138
139
        $this->subject->amount = 4;
0 ignored issues
show
Accessing amount on the interface TildBJ\Seeder\SeedCollection suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
140
        $this->assertSame([
141
            0 => 'NEW2',
142
        ], array_keys($this->subject->get($seeder)));
0 ignored issues
show
$seeder is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<TildBJ\Seeder\Seeder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
143
    }
144
145
    /**
146
     * @test
147
     * @method get
148
     */
149 View Code Duplication
    public function getReturnsArrayWithOneKeyWhenClassNameFooBar()
0 ignored issues
show
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...
150
    {
151
        $seeder = $this->createMock(\TildBJ\Seeder\Seeder::class);
152
        $seeder->method('getClass')->willReturn('FooBar');
153
        $fooBarSeed = $this->mockSeed('FooBar');
154
        $fooSeed = $this->mockSeed('Foo');
155
        $barSeed = $this->mockSeed('Bar');
156
157
        // NEW1
158
        $this->subject->attach($fooBarSeed);
159
        // NEW2
160
        $this->subject->attach($fooSeed);
161
        // NEW3
162
        $this->subject->attach($fooBarSeed);
163
        // NEW4
164
        $this->subject->attach($barSeed);
165
166
        $this->subject->amount = 4;
0 ignored issues
show
Accessing amount on the interface TildBJ\Seeder\SeedCollection suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
167
        $this->assertSame([
168
            0 => 'NEW1',
169
            1 => 'NEW3',
170
        ], array_keys($this->subject->get($seeder)));
0 ignored issues
show
$seeder is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<TildBJ\Seeder\Seeder>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
171
    }
172
173
    /**
174
     * @method clear
175
     * @test
176
     */
177
    public function clearSeedCollectionRemovesAllSeeds()
178
    {
179
        $seed = $this->createMock(\TildBJ\Seeder\Seed::class);
180
        $this->subject->attach($seed);
0 ignored issues
show
$seed is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<TildBJ\Seeder\Seed>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
181
        $this->subject->clear();
182
183
        $this->assertSame([], $this->subject->toArray());
184
        $this->assertSame(0, $this->subject->count());
185
        $this->assertSame(false, $this->subject->current());
186
        $this->assertSame(false, $this->subject->valid());
187
        $this->assertSame(false, $this->subject->next());
188
        $this->assertSame(null, $this->subject->key());
189
        $this->assertSame(false, $this->subject->rewind());
190
    }
191
192
    /**
193
     * @method clear
194
     * @test
195
     */
196
    public function clearSeedCollectionSetCounterToZero()
197
    {
198
        $seed = $this->createMock(\TildBJ\Seeder\Seed::class);
199
        $this->subject->attach($seed);
0 ignored issues
show
$seed is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<TildBJ\Seeder\Seed>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
200
        $this->subject->clear();
201
        $this->subject->attach($seed);
0 ignored issues
show
$seed is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<TildBJ\Seeder\Seed>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
202
        $this->subject->attach(clone $seed);
0 ignored issues
show
clone $seed is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<TildBJ\Seeder\Seed>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
203
        $this->assertSame([
204
            0 => 'NEW1',
205
            1 => 'NEW2',
206
        ], array_keys($this->subject->current()));
207
    }
208
209
    /**
210
     * @method toArray
211
     * @test
212
     */
213
    public function toArrayReturnsCorrectArray()
214
    {
215
        $seed = $this->createMock(\TildBJ\Seeder\Seed::class);
216
        $seed->method('getTitle')->willReturn('FooBar');
217
        $seed->method('getTarget')->willReturn('foo_bar');
218
        $seed->method('getProperties')->willReturn(['pid' => 123]);
219
        $this->subject->attach($seed);
0 ignored issues
show
$seed is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<TildBJ\Seeder\Seed>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
220
        $this->subject->attach(clone $seed);
0 ignored issues
show
clone $seed is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<TildBJ\Seeder\Seed>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
221
        $this->assertSame([
222
            'foo_bar' => [
223
                'NEW1' => [
224
                    'pid' => 123
225
                ],
226
                'NEW2' => [
227
                    'pid' => 123
228
                ],
229
            ],
230
        ], $this->subject->toArray());
231
    }
232
233
    public function tearDown()
234
    {
235
        $this->subject->clear();
236
    }
237
}
238