SkipFirstFilter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 30
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A filter() 0 10 2
1
<?php
2
3
/**
4
 * This file is part of plumphp/plum.
5
 *
6
 * (c) Florian Eckerstorfer <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Plum\Plum\Filter;
12
13
use LogicException;
14
15
/**
16
 * SkipFirstFilter.
17
 *
18
 * @author    Sebastian Göttschkes <[email protected]>
19
 * @copyright 2014-2016 Florian Eckerstorfer
20
 */
21
class SkipFirstFilter implements FilterInterface
22
{
23
    /** @var int */
24
    private $counter;
25
26 3
    public function __construct($counter)
27
    {
28 3
        if (!is_int($counter)) {
29 1
            throw new LogicException('SkipFirstFilter expects an integer as first argument');
30
        }
31
32 2
        $this->counter = $counter;
33 2
    }
34
35
    /**
36
     * @param mixed $item
37
     *
38
     * @return bool
39
     */
40 2
    public function filter($item)
41
    {
42 2
        if ($this->counter > 0) {
43 1
            --$this->counter;
44
45 1
            return false;
46
        }
47
48 2
        return true;
49
    }
50
}
51