CallbackIteratorTest::testMainFunctionality()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace itertools;
4
5
use PHPUnit_Framework_TestCase;
6
7
8
class CallbackIteratorTest extends PHPUnit_Framework_TestCase
9
{
10
	/** @test */
11
	public function testMainFunctionality()
12
	{
13
		$count = 0;
14
		$it = new CallbackIterator(function() use(&$count) { $count += 1; });
15
16
		$it->rewind();
17
		$it->valid();
0 ignored issues
show
Unused Code introduced by
The call to the method itertools\CallbackIterator::valid() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
18
		$it->current();
19
		$it->valid();
0 ignored issues
show
Unused Code introduced by
The call to the method itertools\CallbackIterator::valid() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
20
		$it->next();
21
		$it->current();
22
		$it->current();
23
		$it->current();
24
		$it->valid();
0 ignored issues
show
Unused Code introduced by
The call to the method itertools\CallbackIterator::valid() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
25
		$it->next();
26
		$it->current();
27
28
		$this->assertEquals(3, $count);
29
	}
30
31
	/** @test */
32
	public function testMaxInvocations()
33
	{
34
		$it = new CallbackIterator(function() { return 1; }, 3);
35
		$this->assertCount(3, iterator_to_array($it));
36
	}
37
}
38
39