PaginationExtensionTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 18
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testDefaultLimit() 0 3 1
A testDefaultOffset() 0 3 1
1
<?php
2
3
namespace Ntb\RestAPI;
4
5
use SS_Object;
6
use SapphireTest;
7
use SS_HTTPRequest;
8
use TestOnly;
9
10
class PaginationExtensionTest extends SapphireTest {
11
12
    private $controller;
13
14
    public function setUp() {
15
        parent::setUp();
16
        PaginationTestController::add_extension('Ntb\RestAPI\PaginationExtension');
17
        $this->controller = new PaginationTestController();
18
    }
19
20
    public function testDefaultLimit() {
21
        $this->assertEquals(20, $this->controller->getLimit(new SS_HTTPRequest("GET", "/")));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Ntb\RestAPI\PaginationExtensionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
    }
23
24
    public function testDefaultOffset() {
25
        $this->assertEquals(0, $this->controller->getOffset(new SS_HTTPRequest("GET", "/")));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<Ntb\RestAPI\PaginationExtensionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
26
    }
27
}
28
29
class PaginationTestController extends SS_Object implements TestOnly {
30
31
    public function getLimit($request) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
32
        return $this->limit($request);
0 ignored issues
show
Documentation Bug introduced by
The method limit does not exist on object<Ntb\RestAPI\PaginationTestController>? 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...
33
    }
34
35
    public function getOffset($request) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
36
        return $this->offset($request);
0 ignored issues
show
Bug introduced by
The method offset() does not exist on Ntb\RestAPI\PaginationTestController. Did you maybe mean getOffset()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
37
    }
38
}
39