Passed
Branch 1.0 (df18cb)
by Valentin
06:50
created

LocationObject::setStructCallback()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 4
cts 4
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * This file is part of Transfer.
5
 *
6
 * For the full copyright and license information, please view the LICENSE file located
7
 * in the root directory.
8
 */
9
namespace Transfer\EzPlatform\Repository\Values;
10
11
use eZ\Publish\API\Repository\Values\Content\Location;
12
use Transfer\EzPlatform\Repository\Values\Mapper\LocationMapper;
13
14
/**
15
 * Location object.
16
 *
17
 * @see http://transfer-framework.com/docs/1.0/sources_and_targets/ezplatform/the_objects/locationobject.html
18
 */
19
class LocationObject extends EzPlatformObject
20
{
21
    /**
22
     * @var LocationMapper
23
     */
24
    private $mapper;
25
26
    /**
27
     * LocationObject constructor.
28
     *
29
     * @param array|Location $data
30
     * @param array          $properties
31
     */
32 16
    public function __construct($data, array $properties = [])
33
    {
34 16
        if ($data instanceof Location) {
35 1
            $this->getMapper()->locationToObject($data);
36 1
        } else {
37 16
            parent::__construct($data, $properties);
38 1
        }
39 16
    }
40
41
    /**
42
     * Allows direct control in LocationCreateStruct and LocationUpdateStruct.
43
     *
44
     * @param \Closure $callback
45
     */
46 2
    public function setStructCallback(\Closure $callback)
47 1
    {
48 2
        $this->setProperty('struct_callback', $callback);
49 2
    }
50
51
    /**
52
     * @return LocationMapper
53
     */
54 15
    public function getMapper()
55
    {
56 15
        if (!$this->mapper) {
57 15
            $this->mapper = new LocationMapper($this);
58 15
        }
59
60 15
        return $this->mapper;
61
    }
62
}
63