Passed
Push — master ( 95d2e4...8875f5 )
by MusikAnimal
05:41
created

Model::getLimit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file contains only the Model class.
4
 */
5
6
namespace Xtools;
7
8
use Exception;
9
10
/**
11
 * A model is any domain-side entity to be represented in the application.
12
 * Models know nothing of persistence, transport, or presentation.
13
 */
14
abstract class Model
15
{
16
    /**
17
     * Below are the class properties. Some subclasses may not use all of these.
18
     */
19
20
    /** @var Repository The repository for this model. */
21
    private $repository;
22
23
    /** @var Project The project. */
24
    protected $project;
25
26
    /** @var User The user. */
27
    protected $user;
28
29
    /** @var Page the page associated with this edit */
30
    protected $page;
31
32
    /** @var int|string Which namespace we are querying for. 'all' for all namespaces. */
33
    protected $namespace;
34
35
    /** @var false|int|string Start of time period as UTC timestamp, or YYYY-MM-DD format. */
36
    protected $start;
37
38
    /** @var false|int|string End of time period as UTC timestamp, or YYYY-MM-DD format. */
39
    protected $end;
40
41
    /** @var int Number of rows to fetch. */
42
    protected $limit;
43
44
    /** @var int Number of rows to OFFSET, used for pagination. */
45
    protected $offset;
46
47
    /**
48
     * Set this model's data repository.
49
     * @param Repository $repository
50
     */
51 109
    public function setRepository(Repository $repository)
52
    {
53 109
        $this->repository = $repository;
54 109
    }
55
56
    /**
57
     * Get this model's repository.
58
     * @return Repository A subclass of Repository.
59
     * @throws Exception If the repository hasn't been set yet.
60
     */
61 97
    public function getRepository()
62
    {
63 97
        if (!$this->repository instanceof Repository) {
0 ignored issues
show
introduced by
$this->repository is always a sub-type of Xtools\Repository. If $this->repository can have other possible types, add them to src/Xtools/Model.php:20.
Loading history...
64 3
            $msg = sprintf('Repository for %s must be set before using.', get_class($this));
65 3
            throw new Exception($msg);
66
        }
67 96
        return $this->repository;
68
    }
69
70
    /**
71
     * Get the associated Project.
72
     * @return Project
73
     */
74 1
    public function getProject()
75
    {
76 1
        return $this->project;
77
    }
78
79
    /**
80
     * Get the associated User.
81
     * @return User
82
     */
83 1
    public function getUser()
84
    {
85 1
        return $this->user;
86
    }
87
88
    /**
89
     * Get the associated Page.
90
     * @return Page
91
     */
92 1
    public function getPage()
93
    {
94 1
        return $this->page;
95
    }
96
97
    /**
98
     * Get the associated namespace.
99
     * @return int|string Namespace ID or 'all' for all namespaces.
100
     */
101 3
    public function getNamespace()
102
    {
103 3
        return $this->namespace;
104
    }
105
106
    /**
107
     * Get date opening date range.
108
     * @return false|int
109
     */
110 3
    public function getStart()
111
    {
112 3
        return $this->start;
113
    }
114
115
    /**
116
     * Get date closing date range.
117
     * @return false|int
118
     */
119 3
    public function getEnd()
120
    {
121 3
        return $this->end;
122
    }
123
124
    /**
125
     * Has date range?
126
     * @return bool
127
     */
128 1
    public function hasDateRange()
129
    {
130 1
        return $this->start != '' || $this->end != '';
131
    }
132
133
    /**
134
     * Get the limit set on number of rows to fetch.
135
     * @return int
136
     */
137 1
    public function getLimit()
138
    {
139 1
        return $this->limit;
140
    }
141
142
    /**
143
     * Get the number of rows to OFFSET, used for pagination.
144
     * @return int
145
     */
146 3
    public function getOffset()
147
    {
148 3
        return $this->offset;
149
    }
150
}
151