Mapper::setOutputObjectInternal()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PhMap;
4
5
/**
6
 * Class Mapper
7
 * @abstract
8
 * @package PhMap
9
 */
10
abstract class Mapper implements MapperInterface {
11
12
    /**
13
     * @const integer
14
     */
15
    const MEMORY_ANNOTATION_ADAPTER = 1;
16
17
    /**
18
     * @const integer
19
     */
20
    const FILES_ANNOTATION_ADAPTER = 2;
21
22
    /**
23
     * @const integer
24
     */
25
    const APC_ANNOTATION_ADAPTER = 3;
26
27
    /**
28
     * @const integer
29
     */
30
    const X_CACHE_ANNOTATION_ADAPTER = 4;
31
32
    /**
33
     * @var string
34
     */
35
    private $outputClass;
36
37
    /**
38
     * @var object
39
     */
40
    private $outputObject;
41
42
    /**
43
     * @var integer
44
     */
45
    private $annotationAdapterType;
46
47
    /**
48
     * @var Transforms
49
     */
50
    private $transforms;
51
52
    /**
53
     * @var boolean
54
     */
55
    private $validation;
56
57
    /**
58
     * @var array
59
     */
60
    private $skipAttributes;
61
62
    /**
63
     * @return string
64
     */
65 47
    public function getOutputClass() {
66 47
        return $this->outputClass;
67
    }
68
69
    /**
70
     * @param string $class
71
     * @return $this
72
     */
73 50
    protected function setOutputClassInternal($class) {
74 50
        $this->outputClass = $class;
75 50
        $this->outputObject = new $class();
76
77 50
        return $this;
78
    }
79
80
    /**
81
     * @return object
82
     */
83 47
    public function getOutputObject() {
84 47
        return $this->outputObject;
85
    }
86
87
    /**
88
     * @param object $object
89
     * @return $this
90
     */
91 15
    protected function setOutputObjectInternal($object) {
92 15
        $this->outputObject = $object;
93 15
        $this->outputClass = get_class($object);
94
95 15
        return $this;
96
    }
97
98
    /**
99
     * @return integer
100
     */
101 50
    public function getAnnotationAdapterType() {
102 50
        return $this->annotationAdapterType;
103
    }
104
105
    /**
106
     * @param integer $adapter
107
     * @return $this
108
     */
109 50
    public function setAnnotationAdapterType($adapter) {
110 50
        $this->annotationAdapterType = $adapter;
111
112 50
        return $this;
113
    }
114
115
    /**
116
     * @return Transforms
117
     */
118 47
    public function getTransforms() {
119 47
        return $this->transforms;
120
    }
121
122
    /**
123
     * @param Transforms|null $transforms
124
     * @return $this
125
     */
126 36
    public function setTransforms(Transforms $transforms = null) {
127 36
        $this->transforms = $transforms;
128
129 36
        return $this;
130
    }
131
132
    /**
133
     * @return boolean
134
     */
135 47
    public function hasValidation() {
136 47
        return $this->validation;
137
    }
138
139
    /**
140
     * @return $this
141
     */
142 12
    public function disableValidation() {
143 12
        $this->validation = false;
144
145 12
        return $this;
146
    }
147
148
    /**
149
     * @return $this
150
     */
151
    public function enableValidation() {
152
        $this->validation = true;
153
154
        return $this;
155
    }
156
157
    /**
158
     * @param boolean $validation
159
     * @return $this
160
     */
161 47
    public function setValidation($validation) {
162 47
        $this->validation = $validation;
163
164 47
        return $this;
165
    }
166
167
    /**
168
     * @param array $attributes
169
     * @return $this
170
     */
171 47
    public function setSkipAttributes(array $attributes = []) {
172 47
        $this->skipAttributes = $attributes;
173
174 47
        return $this;
175
    }
176
177
    /**
178
     * @return array
179
     */
180 47
    public function getSkipAttributes() {
181 47
        return $this->skipAttributes;
182
    }
183
184
    /**
185
     * @param string|object $outputClassOrObject
186
     * @param integer $adapter
187
     */
188 50
    public function __construct($outputClassOrObject, $adapter = self::MEMORY_ANNOTATION_ADAPTER) {
189 50
        $this->setOutputClassOrObject($outputClassOrObject)
190 50
            ->setAnnotationAdapterType($adapter)
191 47
            ->setValidation(true)
192 47
            ->setSkipAttributes();
193 47
    }
194
195
    /**
196
     * @param string|object $outputClassOrObject
197
     * @return $this
198
     */
199 50
    private function setOutputClassOrObject($outputClassOrObject) {
200 50
        if (is_object($outputClassOrObject)) {
201 15
            $this->setOutputObjectInternal($outputClassOrObject);
202 15
        } else {
203 50
            $this->setOutputClassInternal($outputClassOrObject);
204
        }
205
206 50
        return $this;
207
    }
208
209
}