ServiceTrait::throwException()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace IanOlson\Support\Traits;
4
5
trait ServiceTrait
6
{
7
    /**
8
     * Full namespace of exception.
9
     *
10
     * @var string
11
     */
12
    protected $exception;
13
14
    /**
15
     * Full namespace of model.
16
     *
17
     * @var string
18
     */
19
    protected $model;
20
21
    /**
22
     * Create a new instance of the model.
23
     *
24
     * @param array $data
25
     *
26
     * @return mixed
27
     */
28 4
    public function createModel(array $data = [])
29
    {
30 4
        $class = '\\' . ltrim($this->getModel(), '\\');
31
32 4
        return new $class($data);
33
    }
34
35
    /**
36
     * Returns the model.
37
     *
38
     * @return string
39
     */
40 10
    public function getModel()
41
    {
42 10
        return $this->model;
43
    }
44
45
    /**
46
     * Runtime override of the model.
47
     *
48
     * @param string $model
49
     *
50
     * @return $this
51
     */
52 10
    public function setModel($model)
53
    {
54 10
        $this->model = $model;
55
56 10
        return $this;
57
    }
58
59
    /**
60
     * Returns the exception.
61
     *
62
     * @return string
63
     */
64 2
    public function getException()
65
    {
66 2
        return $this->exception;
67
    }
68
69
    /**
70
     * Runtime override of the exception.
71
     *
72
     * @param string $exception
73
     *
74
     * @return $this
75
     */
76 2
    public function setException($exception)
77
    {
78 2
        $this->exception = $exception;
79
80 2
        return $this;
81
    }
82
83
    /**
84
     * Throw model exception.
85
     *
86
     * @param string $message
87
     */
88 2
    public function throwException($message)
89
    {
90 2
        $exception = '\\' . ltrim($this->getException(), '\\');
91
92 2
        throw new $exception($message);
93
    }
94
}
95