Completed
Push — master ( 116ca6...19b0f3 )
by Anton
03:42 queued 01:47
created

SampleSource   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 4 1
A getIterator() 0 10 1
1
<?php
2
/**
3
 * vault
4
 *
5
 * @author    Wolfy-J
6
 */
7
8
namespace Spiral\Vault\Controllers\Grids;
9
10
use Spiral\Core\Component;
11
use Spiral\Pagination\PaginatorAwareInterface;
12
use Spiral\Pagination\Traits\PaginatorTrait;
13
14
class SampleSource extends Component implements \IteratorAggregate, PaginatorAwareInterface, \Countable
15
{
16
    use PaginatorTrait;
17
18
    private $data = [
19
        0 => [
20
            'id'      => 1,
21
            'active'  => true,
22
            'name'    => 'Anton',
23
            'balance' => 100
24
        ],
25
        1 => [
26
            'id'      => 2,
27
            'active'  => false,
28
            'name'    => 'John',
29
            'balance' => 200
30
        ],
31
        2 => [
32
            'id'      => 3,
33
            'active'  => false,
34
            'name'    => 'Bill',
35
            'balance' => 300
36
        ],
37
        3 => [
38
            'id'      => 4,
39
            'active'  => false,
40
            'name'    => 'William',
41
            'balance' => 400
42
        ],
43
        4 => [
44
            'id'      => 5,
45
            'active'  => true,
46
            'name'    => 'Bruce',
47
            'balance' => 500
48
        ]
49
    ];
50
51
    /**
52
     * @return int
53
     */
54
    public function count()
55
    {
56
        return count($this->data);
57
    }
58
59
    /**
60
     * @return \ArrayIterator
61
     */
62
    public function getIterator()
63
    {
64
        $paginator = $this->getPaginator();
65
66
        return new \ArrayIterator(array_slice(
67
            $this->data,
68
            $paginator->getOffset(),
69
            $paginator->getLimit()
70
        ));
71
    }
72
}