Completed
Push — master ( fcf66f...4020b1 )
by Sam
02:59
created

Model::getRepository()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace Xtools;
4
5
/**
6
 * A model is any domain-side entity to be represented in the application.
7
 * Models know nothing of persistence, transport, or presentation.
8
 */
9
abstract class Model
10
{
11
12
    /** @var Repository */
13
    private $repository;
14
15
    /**
16
     * Set this model's data repository.
17
     *
18
     * @param Repository $repository
19
     */
20
    public function setRepository(Repository $repository)
21
    {
22
        $this->repository = $repository;
23
    }
24
25
    /**
26
     * Get this model's repository.
27
     *
28
     * @return Repository A subclass of Repository.
29
     * @throws \Exception If the repository hasn't been set yet.
30
     */
31
    public function getRepository()
32
    {
33
        if (!$this->repository instanceof Repository) {
34
            throw new \Exception('Repository must be set before using.');
35
        }
36
        return $this->repository;
37
    }
38
}
39