GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 62839f...748982 )
by Sébastien
02:18
created

ArrayAccessCollectionTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testArrayAccessUnsetRemovesItemByKeyAndReturnsNull() 0 12 1
B testArrayAccessOffsetExistsAllowsIssetToWorkWithSquareBrackets() 0 46 1
B testArrayAccessOffsetSetAllowsUseOfSquareBracketsForSetting() 0 28 1
A testArrayAccessOffsetSetAllowsUseOfSquareBracketsForSettingWithoutIndex() 0 19 1
A testArrayAccessOffsetGetAllowsUseOfSquareBracketsForGetting() 0 7 1
A testArrayAccessOffsetGetThrowsExceptionIfIndexDoesNotExist() 0 6 1
1
<?php
2
/**
3
 * Novactive Collection.
4
 *
5
 * @author    Luke Visinoni <[email protected], [email protected]>
6
 * @author    Sébastien Morel <[email protected], [email protected]>
7
 * @copyright 2017 Novactive
8
 * @license   MIT
9
 */
10
11
namespace Novactive\Tests;
12
13
use Novactive\Collection\Factory;
14
15
/**
16
 * Class ArrayAccessCollectionTest.
17
 */
18
class ArrayAccessCollectionTest extends UnitTestCase
19
{
20
    public function testArrayAccessUnsetRemovesItemByKeyAndReturnsNull()
21
    {
22
        $exp  = $this->fixtures['assoc'];
23
        $coll = Factory::create($exp);
24
        $this->assertTrue($coll->containsKey('2nd'));
25
        $removed = $coll->offsetUnset('2nd');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $removed is correct as $coll->offsetUnset('2nd') (which targets Novactive\Collection\Collection::offsetUnset()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
26
        $this->assertFalse($coll->containsKey('2nd'));
27
        $this->assertNull($removed, 'The ArrayAccess interface expects offsetUnset to have no return value.');
28
        $this->assertTrue($coll->containsKey('3rd'));
29
        unset($coll['3rd']);
30
        $this->assertFalse($coll->containsKey('3rd'));
31
    }
32
33
    public function testArrayAccessOffsetExistsAllowsIssetToWorkWithSquareBrackets()
34
    {
35
        // associative
36
        $exp  = $this->fixtures['assoc'];
37
        $coll = Factory::create($exp);
38
        $this->assertTrue($coll->containsKey('2nd'));
39
        $this->assertTrue($coll->offsetExists('2nd'), 'Collection::offsetExists should return true if index exists.');
40
        $this->assertTrue(
41
            isset($coll['2nd']),
42
            'Collection::offsetExists should allow for the use of isset() on a collection using square brackets.'
43
        );
44
        $this->assertFalse($coll->containsKey('4th'));
45
        $this->assertFalse(
46
            $coll->offsetExists('4th'),
47
            'Collection::offsetExists should return false if index does not exist.'
48
        );
49
        $this->assertFalse(
50
            isset($coll['4th']),
51
            'Collection::offsetExists should allow for the use of isset() on a '.
52
            'collection using square brackets for an index that does not exist.'
53
        );
54
55
        // numeric
56
        $exp  = $this->fixtures['array'];
57
        $coll = Factory::create($exp);
58
        $this->assertTrue($coll->containsKey(1));
59
        $this->assertTrue(
60
            $coll->offsetExists(1),
61
            'Collection::offsetExists should return true if numeric offset exists.'
62
        );
63
        $this->assertTrue(
64
            isset($coll[1]),
65
            'Collection::offsetExists should allow for the use of isset() on a collection using '.
66
            'square brackets and numeric offset.'
67
        );
68
        $this->assertFalse($coll->containsKey(5));
69
        $this->assertFalse(
70
            $coll->offsetExists(5),
71
            'Collection::offsetExists should return false if numeric offset does not exist.'
72
        );
73
        $this->assertFalse(
74
            isset($coll[5]),
75
            'Collection::offsetExists should allow for the use of isset() on a collection using square brackets '.
76
            'for a numeric offset that does not exist.'
77
        );
78
    }
79
80
    public function testArrayAccessOffsetSetAllowsUseOfSquareBracketsForSetting()
81
    {
82
        // associative
83
        $exp  = $this->fixtures['assoc'];
84
        $coll = Factory::create($exp);
85
        $this->assertFalse($coll->containsKey('foo'));
86
        $coll['foo'] = 'bar';
87
        $this->assertTrue($coll->containsKey('foo'));
88
        $this->assertEquals('bar', $coll->get('foo'));
89
90
        $this->assertFalse($coll->containsKey('boo'));
91
        $this->assertNull($coll->offsetSet('boo', 'far'), 'ArrayAccess offsetSet MUST NOT have a return value.');
92
        $this->assertTrue($coll->containsKey('boo'));
93
        $this->assertEquals('far', $coll->get('boo'));
94
95
        // numeric
96
        $exp  = $this->fixtures['array'];
97
        $coll = Factory::create($exp);
98
        $this->assertFalse($coll->containsKey(5));
99
        $coll[5] = 'bar';
100
        $this->assertTrue($coll->containsKey(5));
101
        $this->assertEquals('bar', $coll->get(5));
102
103
        $this->assertFalse($coll->containsKey('boo'));
104
        $this->assertNull($coll->offsetSet(6, 'far'), 'ArrayAccess offsetSet MUST NOT have a return value.');
105
        $this->assertTrue($coll->containsKey(6));
106
        $this->assertEquals('far', $coll->get(6));
107
    }
108
109
    public function testArrayAccessOffsetSetAllowsUseOfSquareBracketsForSettingWithoutIndex()
110
    {
111
        // associative
112
        $assoc = $this->fixtures['assoc'];
113
        $aColl = Factory::create($assoc);
114
        $this->assertFalse($aColl->containsKey(0));
115
        $aColl[] = 'test';
116
        $this->assertTrue($aColl->containsKey(0));
117
118
        // numeric
119
        $arr     = $this->fixtures['array'];
120
        $arrColl = Factory::create($arr);
121
        $this->assertTrue($arrColl->containsKey(0));
122
        $this->assertTrue($arrColl->containsKey(1));
123
        $this->assertTrue($arrColl->containsKey(2));
124
        $this->assertFalse($arrColl->containsKey(3));
125
        $arrColl[] = 'test';
126
        $this->assertTrue($arrColl->containsKey(3));
127
    }
128
129
    public function testArrayAccessOffsetGetAllowsUseOfSquareBracketsForGetting()
130
    {
131
        $exp  = $this->fixtures['assoc'];
132
        $coll = Factory::create($exp);
133
        $this->assertEquals('first', $coll->offsetGet('1st'));
134
        $this->assertEquals('first', $coll['1st']);
135
    }
136
137
    /**
138
     * @expectedException \RuntimeException
139
     * @expectedExceptionMessage Unknown offset: foo
140
     */
141
    public function testArrayAccessOffsetGetThrowsExceptionIfIndexDoesNotExist()
142
    {
143
        $exp  = $this->fixtures['assoc'];
144
        $coll = Factory::create($exp);
145
        $foo  = $coll['foo'];
0 ignored issues
show
Unused Code introduced by
$foo 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...
146
    }
147
}
148