Passed
Push — master ( 32c543...94bf2c )
by Rougin
03:19
created

ReturnTotalEntities::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Rougin\Windstorm\Mutators;
4
5
use Rougin\Windstorm\QueryInterface;
6
7
/**
8
 * Return Total Entities Mutator
9
 *
10
 * @package Windstorm
11
 * @author  Rougin Gutib <[email protected]>
12
 */
13
class ReturnTotalEntities extends ReturnEntities
14
{
15
    /**
16
     * @var string
17
     */
18
    protected $keyword = 'total';
19
20
    /**
21
     * @var integer|null
22
     */
23
    protected $limit = null;
24
25
    /**
26
     * @var integer|null
27
     */
28
    protected $offset = null;
29
30
    /**
31
     * Initializes the mutator instance.
32
     *
33
     * @param string|null $table
34
     */
35
    public function __construct($table = null)
36
    {
37
        if ($table)
38
        {
39
            $this->table = $table;
40
        }
41
    }
42
43
    /**
44
     * Returns the keyword used in getting the field from the result.
45
     *
46
     * @return string
47
     */
48
    public function keyword()
49
    {
50
        return $this->keyword;
51
    }
52
53
    /**
54
     * Sets a predefined query instance.
55
     *
56
     * @param \Rougin\Windstorm\QueryInterface $query
57
     */
58
    protected function query(QueryInterface $query)
59
    {
60
        $query->select('COUNT(*) as ' . $this->keyword);
61
62
        if (! $this->alias && $this->table)
63
        {
64
            $this->alias = $this->table[0];
65
        }
66
67
        return $query->from($this->table, $this->alias);
68
    }
69
}
70