Completed
Pull Request — 1.0 (#53)
by Harald
05:33
created

LocationObject   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 81.82%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 34
ccs 9
cts 11
cp 0.8182
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getMapper() 0 8 2
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
10
namespace Transfer\EzPlatform\Repository\Values;
11
12
use eZ\Publish\API\Repository\Values\Content\Location;
13
use Transfer\EzPlatform\Repository\Values\Mapper\LocationMapper;
14
15
/*
16
  
17
** Available keys: **
18
 
19
    $data = [
20
        content_id          => int
21
        remote_id           => string
22
        parent_location_id  => int
23
        hidden              => bool
24
        priority            => int
25
        sort_field          => int 1-12 Location::SORT_FIELD_*
26
        sort_order          => int 0-1  Location::SORT_ORDER_DESC/SORT_ORDER_ASC
27
    ],
28
    $properties = [
29
        id                  => int
30
        depth               => int
31
        content_info        => \eZ\Publish\API\Repository\Values\Content\ContentInfo
32
        invisible           => bool
33
        path                => array
34
        path_string         => string
35
        action              => int {@link see \Transfer\EzPlatform\Data\Action\Enum\Action}
36
    ]
37
38
39
** Required on `create`:
40
41
**** Required by Transfer:
42
    * content_id
43
    * parent_location_id
44
45
**** Required by eZ:
46
    * @todo finish requirements
47
48
49
** Required on `update`:
50
51
**** Required by Transfer:
52
    * content_id or remote_id
53
    * parent_location_id
54
55
**** Required by eZ:
56
    * @todo finish requirements
57
58
*/
59
60
/**
61
 * Location object.
62
 */
63
class LocationObject extends EzPlatformObject
64
{
65
    /**
66
     * @var LocationMapper
67
     */
68
    private $mapper;
69
70
    /**
71
     * LocationObject constructor.
72
     *
73
     * @param array|Location $data
74
     * @param array          $properties
75
     */
76 7
    public function __construct($data, array $properties = [])
77
    {
78 7
        if ($data instanceof Location) {
79
            $this->getMapper()->locationToObject($data);
80
        } else {
81 7
            parent::__construct($data, $properties);
82
        }
83 7
    }
84
85
    /**
86
     * @return LocationMapper
87
     */
88 7
    public function getMapper()
89
    {
90 7
        if (!$this->mapper) {
91 7
            $this->mapper = new LocationMapper($this);
92 7
        }
93
94 7
        return $this->mapper;
95
    }
96
}
97