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.

AccumulateTest::testSupportsPartialIterations()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 15
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 19
rs 9.7666
1
<?php
2
declare(strict_types = 1);
3
4
namespace Tests\Innmind\Immutable;
5
6
use Innmind\Immutable\Accumulate;
7
use PHPUnit\Framework\TestCase;
8
9
class AccumulateTest extends TestCase
10
{
11
    public function testInterface()
12
    {
13
        $this->assertInstanceOf(
14
            \Iterator::class,
15
            new Accumulate((static function() {
16
                yield 1;
17
            })()),
18
        );
19
20
        $loaded = false;
21
        $iterator = new Accumulate((static function() use (&$loaded) {
22
            yield 1;
23
            yield 2;
24
            yield 3;
25
            $loaded = true;
26
        })());
27
28
        $this->assertFalse($loaded);
29
        $this->assertSame([1, 2, 3], \iterator_to_array($iterator));
30
        $this->assertTrue($loaded);
31
        $this->assertSame([1, 2, 3], \iterator_to_array($iterator));
32
    }
33
34
    public function testSupportsPartialIterations()
35
    {
36
        $loaded = false;
37
        $iterator = new Accumulate((static function() use (&$loaded) {
38
            yield 1;
39
            yield 2;
40
            yield 3;
41
            yield 4;
42
            $loaded = true;
43
        })());
44
45
        $this->assertSame(0, $iterator->key());
46
        $this->assertSame(1, $iterator->current());
47
        $this->assertNull($iterator->next());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $iterator->next() targeting Innmind\Immutable\Accumulate::next() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

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

Loading history...
48
        $this->assertSame(1, $iterator->key());
49
        $this->assertSame(2, $iterator->current());
50
        $this->assertNull($iterator->rewind());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $iterator->rewind() targeting Innmind\Immutable\Accumulate::rewind() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

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

Loading history...
51
        $this->assertFalse($loaded);
52
        $this->assertSame([1, 2, 3, 4], \iterator_to_array($iterator));
53
    }
54
55
    public function testMixingPartialIterationsInGeneratorsCompositionDoesntTamperIteration()
56
    {
57
        $initial = new Accumulate((static function() {
58
            yield 1;
59
            yield 2;
60
        })());
61
        $decorate = (static function($initial) {
62
            foreach ($initial as $i) {
63
                yield $i;
64
            }
65
66
            yield 3;
67
        })($initial);
68
        $iterator = new Accumulate($decorate);
69
        $iterator->rewind();
70
71
        $this->assertTrue($iterator->valid());
72
        $this->assertSame([1, 2], \iterator_to_array($initial));
73
        $this->assertSame([1, 2, 3], \iterator_to_array($iterator));
74
    }
75
}
76