DataTablesLoop   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
eloc 16
dl 0
loc 89
c 2
b 0
f 0
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A next() 0 3 1
A isFirst() 0 2 1
A getIndex0() 0 2 1
A isLast() 0 2 1
A setIndex() 0 3 1
A getRevIndex0() 0 2 1
A getRevIndex() 0 2 1
A getLength() 0 2 1
A __construct() 0 3 1
A getIndex() 0 2 1
1
<?php
2
3
/*
4
 * This file is part of the jquery-datatables-bundle package.
5
 *
6
 * (c) 2022 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\JQuery\DataTablesBundle\Model;
13
14
use WBW\Bundle\JQuery\DataTablesBundle\Api\DataTablesLoopInterface;
15
use WBW\Bundle\JQuery\DataTablesBundle\Traits\Arrays\ArrayEntitiesTrait;
16
17
/**
18
 * DataTables loop.
19
 *
20
 * @author webeweb <https://github.com/webeweb>
21
 * @package WBW\Bundle\JQuery\DataTablesBundle\Model
22
 */
23
class DataTablesLoop implements DataTablesLoopInterface {
24
25
    use ArrayEntitiesTrait;
26
27
    /**
28
     * Index.
29
     *
30
     * @var int
31
     */
32
    private $index;
33
34
    /**
35
     * Constructor.
36
     *
37
     * @param object[] $entities The entities.
38
     */
39
    public function __construct(array $entities) {
40
        $this->setEntities($entities);
41
        $this->setIndex(1);
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47
    public function getIndex(): int {
48
        return $this->index;
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54
    public function getIndex0(): int {
55
        return $this->index - 1;
56
    }
57
58
    /**
59
     * {@inheritDoc}
60
     */
61
    public function getLength(): int {
62
        return count($this->entities);
63
    }
64
65
    /**
66
     * {@inheritDoc}
67
     */
68
    public function getRevIndex(): int {
69
        return $this->getLength() - $this->getIndex() + 1;
70
    }
71
72
    /**
73
     * {@inheritDoc}
74
     */
75
    public function getRevIndex0(): int {
76
        return $this->getRevIndex() - 1;
77
    }
78
79
    /**
80
     * {@inheritDoc}
81
     */
82
    public function isFirst(): bool {
83
        return 1 === $this->getIndex();
84
    }
85
86
    /**
87
     * {@inheritDoc}
88
     */
89
    public function isLast(): bool {
90
        return $this->getLength() === $this->getIndex();
91
    }
92
93
    /**
94
     * Iterates.
95
     *
96
     * @return DataTablesLoop Returns this loop.
97
     */
98
    public function next(): DataTablesLoop {
99
        ++$this->index;
100
        return $this;
101
    }
102
103
    /**
104
     * Set the index.
105
     *
106
     * @param int $index The index.
107
     * @return DataTablesLoop Returns this loop.
108
     */
109
    protected function setIndex(int $index): DataTablesLoop {
110
        $this->index = $index;
111
        return $this;
112
    }
113
}
114