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

Model   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setRepository() 0 4 1
A getRepository() 0 7 2
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