MapperTrait::staticMapper()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
namespace PhMap;
4
5
use \PhMap\Wrapper\Smart;
6
7
/**
8
 * Class MapperTrait
9
 * @package PhMap
10
 */
11
trait MapperTrait {
12
13
    /**
14
     * @var Smart
15
     */
16
    private static $mapper;
17
18
    /**
19
     * @param array|object|string $value
20
     * @param integer $adapter
21
     * @return Smart
22
     * @static
23
     */
24 1
    public static function staticMapper($value, $adapter = Mapper::MEMORY_ANNOTATION_ADAPTER) {
25 1
        return self::updateMapper($value, $adapter);
26
    }
27
28
    /**
29
     * @param array|object|string $value
30
     * @param integer $adapter
31
     * @return Smart
32
     * @static
33
     */
34 1
    public function mapper($value, $adapter = Mapper::MEMORY_ANNOTATION_ADAPTER) {
35 1
        return self::updateMapper($value, $adapter);
36
    }
37
38
    /**
39
     * @param $value
40
     * @param int $adapter
41
     * @return Smart
42
     */
43 1
    private static function updateMapper($value, $adapter = Mapper::MEMORY_ANNOTATION_ADAPTER) {
44 1
        if (is_null(self::$mapper)) {
45 1
            self::$mapper = new Smart($value, get_called_class(), $adapter);
46 1
        } else {
47
            self::$mapper
48 1
                ->setInputValue($value)
49 1
                ->setAnnotationAdapterType($adapter);
50
        }
51
52 1
        return self::$mapper;
53
    }
54
55
}