Issues (3098)

Security Analysis    not enabled

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/KochTest/Pagination/PaginationTest.php (4 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 KochTest\Pagination;
4
5
use Koch\Pagination\Pagination;
6
7
class PaginationTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var Pagination
11
     */
12
    protected $object;
13
    protected $adapter;
14
15
    protected function setUp()
16
    {
17
        $this->adapter = $this->getMock('Koch\Pagination\AdapterInterface');
18
19
        // constructor injection
20
        $this->object = new Pagination($this->adapter);
21
    }
22
23
    protected function tearDown()
24
    {
25
        $this->object;
26
    }
27
28
    /**
29
     * @covers Koch\Pagination\Pagination::setAdapter
30
     */
31
    public function testSetAdapter()
32
    {
33
        // setter injection
34
        $r = $this->object->setAdapter($this->adapter);
35
36
        // fluent
37
        $this->assertInstanceOf('Koch\Pagination\Pagination', $r);
38
    }
39
40
    /**
41
     * @covers Koch\Pagination\Pagination::getAdapter
42
     */
43
    public function testGetAdapter()
44
    {
45
        $this->assertSame($this->adapter, $this->object->getAdapter());
46
    }
47
48
    /**
49
     * @covers Koch\Pagination\Pagination::setMaxResultsPerPage
50
     * @covers Koch\Pagination\Pagination::getMaxResultsPerPage
51
     */
52
    public function testSetMaxResultsPerPage()
53
    {
54
        $maxResultsPerPage = '15';
55
        $r                 = $this->object->setMaxResultsPerPage($maxResultsPerPage);
56
57
        $this->assertEquals($this->object->getMaxResultsPerPage(), $maxResultsPerPage);
58
59
        // fluent
60
        $this->assertInstanceOf('Koch\Pagination\Pagination', $r);
61
    }
62
63
    /**
64
     * @expectedException InvalidArgumentException
65
     * @expectedExceptionMessage There must be more than 1 MaxResultsPerPage.
66
     */
67
    public function testSetMaxResultsPerPage_throwsException()
0 ignored issues
show
function testSetMaxResul...rPage_throwsException() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
68
    {
69
        $this->object->setMaxResultsPerPage(-10);
70
    }
71
72
    /**
73
     * @covers Koch\Pagination\Pagination::setCurrentPage
74
     * @covers Koch\Pagination\Pagination::getCurrentPage
75
     */
76
    public function testSetCurrentPage()
77
    {
78
        // string
79
        $currentPage = '15';
80
        $this->object->setCurrentPage($currentPage);
81
        $this->assertEquals($this->object->getCurrentPage(), $currentPage);
82
83
        // int
84
        $currentPage = 15;
85
        $r           = $this->object->setCurrentPage($currentPage);
86
        $this->assertEquals($this->object->getCurrentPage(), $currentPage);
87
88
        // fluent
89
        $this->assertInstanceOf('Koch\Pagination\Pagination', $r);
90
    }
91
92
    /**
93
     * @covers Koch\Pagination\Pagination::getTotalNumberOfResults
94
     */
95
    public function getTotalNumberOfResults()
96
    {
97
        // hmm, phpunit bug? calls to the mock are not covered
98
        unset($this->object->totalNumberOfResults);
99
        $this->assertNull($this->object->totalNumberOfResults);
100
101
        $this->adapter->expects($this->any())
102
            ->method('getTotalNumberOfResults')->will($this->returnValue(666));
103
104
        $this->assertSame(666, $this->object->getTotalNumberOfResults());
105
    }
106
107
    /**
108
     * @covers Koch\Pagination\Pagination::setMaxResultsPerPage
109
     * @covers Koch\Pagination\Pagination::haveToPaginate
110
     */
111
    public function testHaveToPaginate()
112
    {
113
        $this->adapter->expects($this->any())
114
            ->method('getTotalNumberOfResults')->will($this->returnValue(15));
115
116
        $this->object->setMaxResultsPerPage(16);
117
        $this->assertFalse($this->object->haveToPaginate());
118
        $this->object->setMaxResultsPerPage(15);
119
        $this->assertFalse($this->object->haveToPaginate());
120
        $this->object->setMaxResultsPerPage(14);
121
        $this->assertTrue($this->object->haveToPaginate());
122
        $this->object->setMaxResultsPerPage(1);
123
        $this->assertTrue($this->object->haveToPaginate());
124
    }
125
126
    /**
127
     * @covers Koch\Pagination\Pagination::getTotalNumberOfResults
128
     * @covers Koch\Pagination\Pagination::setTotalNumberOfResults
129
     */
130
    public function testSetTotalNumberOfResults()
131
    {
132
        $this->adapter->expects($this->never())->method('getTotalNumberOfResults');
133
134
        $this->object->setTotalNumberOfResults(2);
135
        $this->assertEquals(2, $this->object->getTotalNumberOfResults());
136
    }
137
138
    /**
139
     * @covers Koch\Pagination\Pagination::getNumberOfPages
140
     * @covers Koch\Pagination\Pagination::setMaxResultsPerPage
141
     * @covers Koch\Pagination\Pagination::getLastPage
142
     */
143
    public function testGetNumberOfPages()
144
    {
145
        $this->adapter->expects($this->any())
146
            ->method('getTotalNumberOfResults')->will($this->returnValue(100));
147
148
        $this->object->setMaxResultsPerPage(10);
149
        $this->assertSame(10, $this->object->getNumberOfPages());
150
        $this->assertSame(10, $this->object->getLastPage());
151
    }
152
153
    /**
154
     * @covers Koch\Pagination\Pagination::setMaxResultsPerPage
155
     * @covers Koch\Pagination\Pagination::getCurrentPageResults
156
     * @covers Koch\Pagination\Pagination::getCurrentPage
157
     */
158
    public function testGetCurrentPageResults()
159
    {
160
        $returnValues = [
161
            ['foo' => 'bar', 'bar' => 'foo'],
162
            ['fanta', 'reiner', 'kristall', 'weizen'],
163
        ];
164
165
        $this->adapter->expects($this->once())->method('getSlice')
166
            ->with($this->equalTo(20), $this->equalTo(10))
167
            ->will($this->returnValue($returnValues[0]));
168
169
        $this->object->setMaxResultsPerPage(10);
170
        $this->object->setCurrentPage(3, true);
0 ignored issues
show
The call to Pagination::setCurrentPage() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
171
        $this->assertSame($returnValues[0], $this->object->getCurrentPageResults());
172
173
        // cached
174
        $this->assertSame($returnValues[0], $this->object->getCurrentPageResults());
175
    }
176
177
    /**
178
     * @covers Koch\Pagination\Pagination::setMaxResultsPerPage
179
     * @covers Koch\Pagination\Pagination::getCurrentPage
180
     * @covers Koch\Pagination\Pagination::hasPreviousPage
181
     * @covers Koch\Pagination\Pagination::getPreviousPage
182
     * @covers Koch\Pagination\Pagination::hasNextPage
183
     * @covers Koch\Pagination\Pagination::getNextPage
184
     */
185
    public function testGetPreviousPage()
186
    {
187
        $this->adapter->expects($this->any())
188
            ->method('getTotalNumberOfResults')->will($this->returnValue(25));
189
190
        $this->object->setMaxResultsPerPage(5);
191
        $this->object->setCurrentPage(1);
192
193
        // first page does not have a previous page
194
        $this->assertFalse($this->object->hasPreviousPage());
195
        try {
196
            $this->object->getPreviousPage();
197
            $this->fail();
198
        } catch (\Exception $e) {
199
            $this->assertInstanceOf('\LogicException', $e);
200
        }
201
202
        // first page has a next page
203
        $this->assertTrue($this->object->hasNextPage());
204
        $this->assertSame(2, $this->object->getNextPage());
205
206
        // check in between
207
        $this->object->setCurrentPage(5);
208
        $this->assertTrue($this->object->hasPreviousPage());
209
        $this->assertSame(4, $this->object->getPreviousPage());
210
211
        // last page
212
        $this->object->setCurrentPage(25);
213
        $this->assertTrue($this->object->hasPreviousPage());
214
        $this->assertSame(24, $this->object->getPreviousPage());
215
        $this->assertFalse($this->object->hasNextPage());
216
217
        // last page does not have a next page
218
        try {
219
            $this->object->getNextPage();
220
            $this->fail();
221
        } catch (\Exception $e) {
222
            $this->assertInstanceOf('\LogicException', $e);
223
        }
224
    }
225
226
    /**
227
     * @covers Koch\Pagination\Pagination::render
228
     * @covers Koch\Pagination\Pagination::setAdapter
229
     * @covers Koch\Pagination\Pagination::setMaxResultsPerPage
230
     */
231
    public function testRender()
232
    {
233
        // dataset
234
        $this->array = [];
0 ignored issues
show
The property array does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
235 View Code Duplication
        for ($i = 0; $i < 10; ++$i) {
0 ignored issues
show
This code seems to be duplicated across 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...
236
            $this->array[] = rand(1, 999);
237
        }
238
239
        // dataset adapter
240
        $adapter = new \Koch\Pagination\Adapter\NativeArray($this->array);
241
        $this->object->setAdapter($adapter);
242
243
        // settings
244
        $this->object->setMaxResultsPerPage(10);
245
246
        // expected pagination
247
        $expected = '<nav class="pagination">';
248
        $expected .= '<a href="URL">&lsaquo;&nbsp;First</a>';
249
        $expected .= '<a href="URL">1</a>';
250
        $expected .= '<a href="URL">&gt;</a>';
251
        $expected .= '<a href="URL">&nbsp;Last&rsaquo;</a>';
252
        $expected .= '</nav>';
253
254
        $this->assertEquals($expected, $this->object->render());
255
    }
256
}
257