Completed
Push — ezp_30981_content_info_proxy ( e47d06...65f6d5 )
by
unknown
19:59
created

TrashItem   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 88
c 0
b 0
f 0
rs 10
wmc 12
lcom 0
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getContentInfo() 0 4 1
A getParentLocation() 0 4 1
A getProperties() 0 4 1
A __get() 0 18 6
A __isset() 0 8 3
1
<?php
2
3
/**
4
 * File containing the eZ\Publish\Core\Repository\Values\Content\TrashItem class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Repository\Values\Content;
10
11
use eZ\Publish\API\Repository\Values\Content\Location;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, eZ\Publish\Core\Repository\Values\Content\Location.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
12
use eZ\Publish\API\Repository\Values\Content\TrashItem as APITrashItem;
13
14
/**
15
 * this class represents a trash item, which is actually a trashed location.
16
 *
17
 * @internal Meant for internal use by Repository, type hint against API object instead.
18
 */
19
class TrashItem extends APITrashItem
20
{
21
    /**
22
     * Content info of the content object of this trash item.
23
     *
24
     * @var \eZ\Publish\API\Repository\Values\Content\ContentInfo
25
     */
26
    protected $contentInfo;
27
28
    /** @var array */
29
    protected $path;
30
31
    /** @var \eZ\Publish\API\Repository\Values\Content\Location */
32
    protected $parentLocation;
33
34
    /**
35
     * Returns the content info of the content object of this trash item.
36
     *
37
     * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo
38
     */
39
    public function getContentInfo()
40
    {
41
        return $this->contentInfo;
42
    }
43
44
    public function getParentLocation(): ?Location
45
    {
46
        return $this->parentLocation;
47
    }
48
49
    /**
50
     * Function where list of properties are returned.
51
     *
52
     * Override to add dynamic properties
53
     *
54
     * @uses \parent::getProperties()
55
     *
56
     * @param array $dynamicProperties
57
     *
58
     * @return array
59
     */
60
    protected function getProperties($dynamicProperties = ['contentId', 'path'])
61
    {
62
        return parent::getProperties($dynamicProperties);
63
    }
64
65
    /**
66
     * Magic getter for retrieving convenience properties.
67
     *
68
     * @param string $property The name of the property to retrieve
69
     *
70
     * @return mixed
71
     */
72
    public function __get($property)
73
    {
74
        switch ($property) {
75
            case 'contentId':
76
                return $this->contentInfo->id;
77
            case 'path':
78
                if ($this->path !== null) {
79
                    return $this->path;
80
                }
81
                if (isset($this->pathString[1]) && $this->pathString[0] === '/') {
82
                    return $this->path = explode('/', trim($this->pathString, '/'));
83
                }
84
85
                return $this->path = [];
86
        }
87
88
        return parent::__get($property);
89
    }
90
91
    /**
92
     * Magic isset for signaling existence of convenience properties.
93
     *
94
     * @param string $property
95
     *
96
     * @return bool
97
     */
98
    public function __isset($property)
99
    {
100
        if ($property === 'contentId' || $property === 'path') {
101
            return true;
102
        }
103
104
        return parent::__isset($property);
105
    }
106
}
107