Completed
Push — 6.13 ( b9a79e )
by
unknown
25:06 queued 12:25
created

loadParentLocationsForDraftContent()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 27
Code Lines 18

Duplication

Lines 6
Ratio 22.22 %

Importance

Changes 0
Metric Value
dl 6
loc 27
c 0
b 0
f 0
cc 4
eloc 18
nc 4
nop 1
rs 8.5806
1
<?php
2
3
/**
4
 * File containing the eZ\Publish\Core\Repository\LocationService 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;
10
11
use eZ\Publish\API\Repository\PermissionCriterionResolver;
12
use eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct;
13
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct;
14
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
15
use eZ\Publish\API\Repository\Values\Content\Location as APILocation;
16
use eZ\Publish\API\Repository\Values\Content\LocationList;
17
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
18
use eZ\Publish\SPI\Persistence\Content\Location\UpdateStruct;
19
use eZ\Publish\API\Repository\LocationService as LocationServiceInterface;
20
use eZ\Publish\API\Repository\Repository as RepositoryInterface;
21
use eZ\Publish\SPI\Persistence\Handler;
22
use eZ\Publish\API\Repository\Values\Content\Query;
23
use eZ\Publish\API\Repository\Values\Content\LocationQuery;
24
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
25
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\LogicalAnd as CriterionLogicalAnd;
26
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\LogicalNot as CriterionLogicalNot;
27
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Subtree as CriterionSubtree;
28
use eZ\Publish\API\Repository\Exceptions\NotFoundException as APINotFoundException;
29
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue;
30
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException;
31
use eZ\Publish\Core\Base\Exceptions\BadStateException;
32
use eZ\Publish\Core\Base\Exceptions\UnauthorizedException;
33
use Exception;
34
35
/**
36
 * Location service, used for complex subtree operations.
37
 *
38
 * @example Examples/location.php
39
 */
40
class LocationService implements LocationServiceInterface
41
{
42
    /**
43
     * @var \eZ\Publish\Core\Repository\Repository
44
     */
45
    protected $repository;
46
47
    /**
48
     * @var \eZ\Publish\SPI\Persistence\Handler
49
     */
50
    protected $persistenceHandler;
51
52
    /**
53
     * @var array
54
     */
55
    protected $settings;
56
57
    /**
58
     * @var \eZ\Publish\Core\Repository\Helper\DomainMapper
59
     */
60
    protected $domainMapper;
61
62
    /**
63
     * @var \eZ\Publish\Core\Repository\Helper\NameSchemaService
64
     */
65
    protected $nameSchemaService;
66
67
    /**
68
     * @var \eZ\Publish\API\Repository\PermissionCriterionResolver
69
     */
70
    protected $permissionCriterionResolver;
71
72
    /**
73
     * Setups service with reference to repository object that created it & corresponding handler.
74
     *
75
     * @param \eZ\Publish\API\Repository\Repository $repository
76
     * @param \eZ\Publish\SPI\Persistence\Handler $handler
77
     * @param \eZ\Publish\Core\Repository\Helper\DomainMapper $domainMapper
78
     * @param \eZ\Publish\Core\Repository\Helper\NameSchemaService $nameSchemaService
79
     * @param \eZ\Publish\API\Repository\PermissionCriterionResolver $permissionCriterionResolver
80
     * @param array $settings
81
     */
82
    public function __construct(
83
        RepositoryInterface $repository,
84
        Handler $handler,
85
        Helper\DomainMapper $domainMapper,
86
        Helper\NameSchemaService $nameSchemaService,
87
        PermissionCriterionResolver $permissionCriterionResolver,
88
        array $settings = array()
89
    ) {
90
        $this->repository = $repository;
0 ignored issues
show
Documentation Bug introduced by
$repository is of type object<eZ\Publish\API\Repository\Repository>, but the property $repository was declared to be of type object<eZ\Publish\Core\Repository\Repository>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
91
        $this->persistenceHandler = $handler;
92
        $this->domainMapper = $domainMapper;
93
        $this->nameSchemaService = $nameSchemaService;
94
        // Union makes sure default settings are ignored if provided in argument
95
        $this->settings = $settings + array(
96
            //'defaultSetting' => array(),
97
        );
98
        $this->permissionCriterionResolver = $permissionCriterionResolver;
99
    }
100
101
    /**
102
     * Copies the subtree starting from $subtree as a new subtree of $targetLocation.
103
     *
104
     * Only the items on which the user has read access are copied.
105
     *
106
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed copy the subtree to the given parent location
107
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user does not have read access to the whole source subtree
108
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the target location is a sub location of the given location
109
     *
110
     * @param \eZ\Publish\API\Repository\Values\Content\Location $subtree - the subtree denoted by the location to copy
111
     * @param \eZ\Publish\API\Repository\Values\Content\Location $targetParentLocation - the target parent location for the copy operation
112
     *
113
     * @return \eZ\Publish\API\Repository\Values\Content\Location The newly created location of the copied subtree
114
     */
115
    public function copySubtree(APILocation $subtree, APILocation $targetParentLocation)
116
    {
117
        $loadedSubtree = $this->loadLocation($subtree->id);
118
        $loadedTargetLocation = $this->loadLocation($targetParentLocation->id);
119
120
        if (stripos($loadedTargetLocation->pathString, $loadedSubtree->pathString) !== false) {
0 ignored issues
show
Documentation introduced by
The property $pathString is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
121
            throw new InvalidArgumentException('targetParentLocation', 'target parent location is a sub location of the given subtree');
122
        }
123
124
        // check create permission on target
125
        if (!$this->repository->canUser('content', 'create', $loadedSubtree->getContentInfo(), $loadedTargetLocation)) {
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Repository\Repository::canUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::canUser() instead. Check if user has access to a given action on a given value object. Indicates if the current user is allowed to perform an action given by the function on the given
objects.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
126
            throw new UnauthorizedException('content', 'create');
127
        }
128
129
        /** Check read access to whole source subtree
130
         * @var bool|\eZ\Publish\API\Repository\Values\Content\Query\Criterion
131
         */
132
        $contentReadCriterion = $this->permissionCriterionResolver->getPermissionsCriterion();
0 ignored issues
show
Bug introduced by
The call to getPermissionsCriterion() misses some required arguments starting with $module.
Loading history...
133 View Code Duplication
        if ($contentReadCriterion === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
134
            throw new UnauthorizedException('content', 'read');
135
        } elseif ($contentReadCriterion !== true) {
136
            // Query if there are any content in subtree current user don't have access to
137
            $query = new Query(
138
                array(
139
                    'limit' => 0,
140
                    'filter' => new CriterionLogicalAnd(
141
                        array(
142
                            new CriterionSubtree($loadedSubtree->pathString),
0 ignored issues
show
Documentation introduced by
The property $pathString is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
143
                            new CriterionLogicalNot($contentReadCriterion),
0 ignored issues
show
Bug introduced by
It seems like $contentReadCriterion defined by $this->permissionCriteri...tPermissionsCriterion() on line 132 can also be of type boolean; however, eZ\Publish\API\Repositor...gicalNot::__construct() does only seem to accept object<eZ\Publish\API\Re...ontent\Query\Criterion>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
144
                        )
145
                    ),
146
                )
147
            );
148
            $result = $this->repository->getSearchService()->findContent($query, array(), false);
149
            if ($result->totalCount > 0) {
150
                throw new UnauthorizedException('content', 'read');
151
            }
152
        }
153
154
        $this->repository->beginTransaction();
155
        try {
156
            $newLocation = $this->persistenceHandler->locationHandler()->copySubtree(
157
                $loadedSubtree->id,
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
158
                $loadedTargetLocation->id
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
159
            );
160
161
            $content = $this->repository->getContentService()->loadContent($newLocation->contentId);
162
            $urlAliasNames = $this->nameSchemaService->resolveUrlAliasSchema($content);
163 View Code Duplication
            foreach ($urlAliasNames as $languageCode => $name) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
164
                $this->persistenceHandler->urlAliasHandler()->publishUrlAliasForLocation(
165
                    $newLocation->id,
166
                    $loadedTargetLocation->id,
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
167
                    $name,
168
                    $languageCode,
169
                    $content->contentInfo->alwaysAvailable
170
                );
171
            }
172
173
            $this->persistenceHandler->urlAliasHandler()->locationCopied(
174
                $loadedSubtree->id,
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
175
                $newLocation->id,
176
                $loadedTargetLocation->id
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
177
            );
178
179
            $this->repository->commit();
180
        } catch (Exception $e) {
181
            $this->repository->rollback();
182
            throw $e;
183
        }
184
185
        return $this->domainMapper->buildLocationDomainObject($newLocation);
186
    }
187
188
    /**
189
     * Loads a location object from its $locationId.
190
     *
191
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to read this location
192
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified location is not found
193
     *
194
     * @param mixed $locationId
195
     *
196
     * @return \eZ\Publish\API\Repository\Values\Content\Location
197
     */
198
    public function loadLocation($locationId)
199
    {
200
        $spiLocation = $this->persistenceHandler->locationHandler()->load($locationId);
201
        $location = $this->domainMapper->buildLocationDomainObject($spiLocation);
202
        if (!$this->repository->canUser('content', 'read', $location->getContentInfo(), $location)) {
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Repository\Repository::canUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::canUser() instead. Check if user has access to a given action on a given value object. Indicates if the current user is allowed to perform an action given by the function on the given
objects.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
203
            throw new UnauthorizedException('content', 'read');
204
        }
205
206
        return $location;
207
    }
208
209
    /**
210
     * Loads a location object from its $remoteId.
211
     *
212
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to read this location
213
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If more than one location with same remote ID was found
214
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified location is not found
215
     *
216
     * @param string $remoteId
217
     *
218
     * @return \eZ\Publish\API\Repository\Values\Content\Location
219
     */
220
    public function loadLocationByRemoteId($remoteId)
221
    {
222
        if (!is_string($remoteId)) {
223
            throw new InvalidArgumentValue('remoteId', $remoteId);
224
        }
225
226
        $spiLocation = $this->persistenceHandler->locationHandler()->loadByRemoteId($remoteId);
227
        $location = $this->domainMapper->buildLocationDomainObject($spiLocation);
228
        if (!$this->repository->canUser('content', 'read', $location->getContentInfo(), $location)) {
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Repository\Repository::canUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::canUser() instead. Check if user has access to a given action on a given value object. Indicates if the current user is allowed to perform an action given by the function on the given
objects.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
229
            throw new UnauthorizedException('content', 'read');
230
        }
231
232
        return $location;
233
    }
234
235
    /**
236
     * {@inheritdoc}
237
     */
238
    public function loadLocations(ContentInfo $contentInfo, APILocation $rootLocation = null)
239
    {
240
        if (!$contentInfo->published) {
241
            throw new BadStateException('$contentInfo', 'ContentInfo has no published versions');
242
        }
243
244
        $spiLocations = $this->persistenceHandler->locationHandler()->loadLocationsByContent(
245
            $contentInfo->id,
246
            $rootLocation !== null ? $rootLocation->id : null
247
        );
248
249
        $locations = [];
250 View Code Duplication
        foreach ($spiLocations as $spiLocation) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
251
            $location = $this->domainMapper->buildLocationDomainObject($spiLocation);
252
            if ($this->repository->canUser('content', 'read', $location->getContentInfo(), $location)) {
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Repository\Repository::canUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::canUser() instead. Check if user has access to a given action on a given value object. Indicates if the current user is allowed to perform an action given by the function on the given
objects.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
253
                $locations[] = $location;
254
            }
255
        }
256
257
        return $locations;
258
    }
259
260
    /**
261
     * Loads children which are readable by the current user of a location object sorted by sortField and sortOrder.
262
     *
263
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
264
     * @param int $offset the start offset for paging
265
     * @param int $limit the number of locations returned
266
     *
267
     * @return \eZ\Publish\API\Repository\Values\Content\LocationList
268
     */
269
    public function loadLocationChildren(APILocation $location, $offset = 0, $limit = 25)
270
    {
271
        if (!$this->domainMapper->isValidLocationSortField($location->sortField)) {
272
            throw new InvalidArgumentValue('sortField', $location->sortField, 'Location');
273
        }
274
275
        if (!$this->domainMapper->isValidLocationSortOrder($location->sortOrder)) {
276
            throw new InvalidArgumentValue('sortOrder', $location->sortOrder, 'Location');
277
        }
278
279
        if (!is_int($offset)) {
280
            throw new InvalidArgumentValue('offset', $offset);
281
        }
282
283
        if (!is_int($limit)) {
284
            throw new InvalidArgumentValue('limit', $limit);
285
        }
286
287
        $childLocations = array();
288
        $searchResult = $this->searchChildrenLocations($location, $offset, $limit);
289
        foreach ($searchResult->searchHits as $searchHit) {
290
            $childLocations[] = $searchHit->valueObject;
291
        }
292
293
        return new LocationList(
294
            array(
295
                'locations' => $childLocations,
296
                'totalCount' => $searchResult->totalCount,
297
            )
298
        );
299
    }
300
301
    /**
302
     * {@inheritdoc}
303
     */
304
    public function loadParentLocationsForDraftContent(VersionInfo $versionInfo)
305
    {
306
        if (!$versionInfo->isDraft()) {
307
            throw new BadStateException(
308
                '$contentInfo',
309
                sprintf(
310
                    'Content [%d] %s has been already published. Use LocationService::loadLocations instead.',
311
                    $versionInfo->contentInfo->id,
312
                    $versionInfo->contentInfo->name
313
                )
314
            );
315
        }
316
        $spiLocations = $this->persistenceHandler
317
            ->locationHandler()
318
            ->loadParentLocationsForDraftContent($versionInfo->contentInfo->id);
319
320
        $locations = [];
321
        $permissionResolver = $this->repository->getPermissionResolver();
322 View Code Duplication
        foreach ($spiLocations as $spiLocation) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
323
            $location = $this->domainMapper->buildLocationDomainObject($spiLocation);
324
            if ($permissionResolver->canUser('content', 'read', $location->getContentInfo(), [$location])) {
325
                $locations[] = $location;
326
            }
327
        }
328
329
        return $locations;
330
    }
331
332
    /**
333
     * Returns the number of children which are readable by the current user of a location object.
334
     *
335
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
336
     *
337
     * @return int
338
     */
339
    public function getLocationChildCount(APILocation $location)
340
    {
341
        $searchResult = $this->searchChildrenLocations($location, 0, 0);
342
343
        return $searchResult->totalCount;
344
    }
345
346
    /**
347
     * Searches children locations of the provided parent location id.
348
     *
349
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
350
     * @param int $offset
351
     * @param int $limit
352
     *
353
     * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult
354
     */
355
    protected function searchChildrenLocations(APILocation $location, $offset = 0, $limit = -1)
356
    {
357
        $query = new LocationQuery([
358
            'filter' => new Criterion\ParentLocationId($location->id),
359
            'offset' => $offset >= 0 ? (int)$offset : 0,
360
            'limit' => $limit >= 0 ? (int)$limit : null,
361
            'sortClauses' => $location->getSortClauses(),
362
        ]);
363
364
        return $this->repository->getSearchService()->findLocations($query);
365
    }
366
367
    /**
368
     * Creates the new $location in the content repository for the given content.
369
     *
370
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to create this location
371
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the content is already below the specified parent
372
     *                                        or the parent is a sub location of the location of the content
373
     *                                        or if set the remoteId exists already
374
     *
375
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
376
     * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $locationCreateStruct
377
     *
378
     * @return \eZ\Publish\API\Repository\Values\Content\Location the newly created Location
379
     */
380
    public function createLocation(ContentInfo $contentInfo, LocationCreateStruct $locationCreateStruct)
381
    {
382
        $content = $this->repository->getContentService()->loadContent($contentInfo->id);
383
        $parentLocation = $this->loadLocation($locationCreateStruct->parentLocationId);
384
385
        if (!$this->repository->canUser('content', 'create', $content->contentInfo, $parentLocation)) {
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Repository\Repository::canUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::canUser() instead. Check if user has access to a given action on a given value object. Indicates if the current user is allowed to perform an action given by the function on the given
objects.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
386
            throw new UnauthorizedException('content', 'create');
387
        }
388
389
        // Check if the parent is a sub location of one of the existing content locations (this also solves the
390
        // situation where parent location actually one of the content locations),
391
        // or if the content already has location below given location create struct parent
392
        $existingContentLocations = $this->loadLocations($content->contentInfo);
393
        if (!empty($existingContentLocations)) {
394
            foreach ($existingContentLocations as $existingContentLocation) {
395
                if (stripos($parentLocation->pathString, $existingContentLocation->pathString) !== false) {
0 ignored issues
show
Documentation introduced by
The property $pathString is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
396
                    throw new InvalidArgumentException(
397
                        '$locationCreateStruct',
398
                        'Specified parent is a sub location of one of the existing content locations.'
399
                    );
400
                }
401
                if ($parentLocation->id == $existingContentLocation->parentLocationId) {
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
402
                    throw new InvalidArgumentException(
403
                        '$locationCreateStruct',
404
                        'Content is already below the specified parent.'
405
                    );
406
                }
407
            }
408
        }
409
410
        $spiLocationCreateStruct = $this->domainMapper->buildSPILocationCreateStruct(
411
            $locationCreateStruct,
412
            $parentLocation,
413
            $content->contentInfo->mainLocationId !== null ? $content->contentInfo->mainLocationId : true,
414
            $content->contentInfo->id,
415
            $content->contentInfo->currentVersionNo
416
        );
417
418
        $this->repository->beginTransaction();
419
        try {
420
            $newLocation = $this->persistenceHandler->locationHandler()->create($spiLocationCreateStruct);
421
422
            $urlAliasNames = $this->nameSchemaService->resolveUrlAliasSchema($content);
423 View Code Duplication
            foreach ($urlAliasNames as $languageCode => $name) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
424
                $this->persistenceHandler->urlAliasHandler()->publishUrlAliasForLocation(
425
                    $newLocation->id,
426
                    $newLocation->parentId,
427
                    $name,
428
                    $languageCode,
429
                    $content->contentInfo->alwaysAvailable,
430
                    // @todo: this is legacy storage specific for updating ezcontentobject_tree.path_identification_string, to be removed
431
                    $languageCode === $content->contentInfo->mainLanguageCode
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison === seems to always evaluate to false as the types of $languageCode (integer) and $content->contentInfo->mainLanguageCode (string) can never be identical. Maybe you want to use a loose comparison == instead?
Loading history...
432
                );
433
            }
434
435
            $this->repository->commit();
436
        } catch (Exception $e) {
437
            $this->repository->rollback();
438
            throw $e;
439
        }
440
441
        return $this->domainMapper->buildLocationDomainObject($newLocation);
442
    }
443
444
    /**
445
     * Updates $location in the content repository.
446
     *
447
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to update this location
448
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException   if if set the remoteId exists already
449
     *
450
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
451
     * @param \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct $locationUpdateStruct
452
     *
453
     * @return \eZ\Publish\API\Repository\Values\Content\Location the updated Location
454
     */
455
    public function updateLocation(APILocation $location, LocationUpdateStruct $locationUpdateStruct)
456
    {
457
        if ($locationUpdateStruct->priority !== null && !is_int($locationUpdateStruct->priority)) {
458
            throw new InvalidArgumentValue('priority', $locationUpdateStruct->priority, 'LocationUpdateStruct');
459
        }
460
461
        if ($locationUpdateStruct->remoteId !== null && (!is_string($locationUpdateStruct->remoteId) || empty($locationUpdateStruct->remoteId))) {
462
            throw new InvalidArgumentValue('remoteId', $locationUpdateStruct->remoteId, 'LocationUpdateStruct');
463
        }
464
465
        if ($locationUpdateStruct->sortField !== null && !$this->domainMapper->isValidLocationSortField($locationUpdateStruct->sortField)) {
466
            throw new InvalidArgumentValue('sortField', $locationUpdateStruct->sortField, 'LocationUpdateStruct');
467
        }
468
469
        if ($locationUpdateStruct->sortOrder !== null && !$this->domainMapper->isValidLocationSortOrder($locationUpdateStruct->sortOrder)) {
470
            throw new InvalidArgumentValue('sortOrder', $locationUpdateStruct->sortOrder, 'LocationUpdateStruct');
471
        }
472
473
        $loadedLocation = $this->loadLocation($location->id);
474
475
        if ($locationUpdateStruct->remoteId !== null) {
476
            try {
477
                $existingLocation = $this->loadLocationByRemoteId($locationUpdateStruct->remoteId);
478
                if ($existingLocation !== null && $existingLocation->id !== $loadedLocation->id) {
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
479
                    throw new InvalidArgumentException('locationUpdateStruct', 'location with provided remote ID already exists');
480
                }
481
            } catch (APINotFoundException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
482
            }
483
        }
484
485
        if (!$this->repository->canUser('content', 'edit', $loadedLocation->getContentInfo(), $loadedLocation)) {
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Repository\Repository::canUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::canUser() instead. Check if user has access to a given action on a given value object. Indicates if the current user is allowed to perform an action given by the function on the given
objects.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
486
            throw new UnauthorizedException('content', 'edit');
487
        }
488
489
        $updateStruct = new UpdateStruct();
490
        $updateStruct->priority = $locationUpdateStruct->priority !== null ? $locationUpdateStruct->priority : $loadedLocation->priority;
0 ignored issues
show
Documentation introduced by
The property $priority is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
491
        $updateStruct->remoteId = $locationUpdateStruct->remoteId !== null ? trim($locationUpdateStruct->remoteId) : $loadedLocation->remoteId;
0 ignored issues
show
Documentation introduced by
The property $remoteId is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
492
        $updateStruct->sortField = $locationUpdateStruct->sortField !== null ? $locationUpdateStruct->sortField : $loadedLocation->sortField;
0 ignored issues
show
Documentation introduced by
The property $sortField is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
493
        $updateStruct->sortOrder = $locationUpdateStruct->sortOrder !== null ? $locationUpdateStruct->sortOrder : $loadedLocation->sortOrder;
0 ignored issues
show
Documentation introduced by
The property $sortOrder is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
494
495
        $this->repository->beginTransaction();
496
        try {
497
            $this->persistenceHandler->locationHandler()->update($updateStruct, $loadedLocation->id);
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
498
            $this->repository->commit();
499
        } catch (Exception $e) {
500
            $this->repository->rollback();
501
            throw $e;
502
        }
503
504
        return $this->loadLocation($loadedLocation->id);
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
505
    }
506
507
    /**
508
     * Swaps the contents held by $location1 and $location2.
509
     *
510
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to swap content
511
     *
512
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location1
513
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location2
514
     */
515
    public function swapLocation(APILocation $location1, APILocation $location2)
516
    {
517
        $loadedLocation1 = $this->loadLocation($location1->id);
518
        $loadedLocation2 = $this->loadLocation($location2->id);
519
520
        if (!$this->repository->canUser('content', 'edit', $loadedLocation1->getContentInfo(), $loadedLocation1)) {
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Repository\Repository::canUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::canUser() instead. Check if user has access to a given action on a given value object. Indicates if the current user is allowed to perform an action given by the function on the given
objects.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
521
            throw new UnauthorizedException('content', 'edit');
522
        }
523
        if (!$this->repository->canUser('content', 'edit', $loadedLocation2->getContentInfo(), $loadedLocation2)) {
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Repository\Repository::canUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::canUser() instead. Check if user has access to a given action on a given value object. Indicates if the current user is allowed to perform an action given by the function on the given
objects.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
524
            throw new UnauthorizedException('content', 'edit');
525
        }
526
527
        $this->repository->beginTransaction();
528
        try {
529
            $this->persistenceHandler->locationHandler()->swap($loadedLocation1->id, $loadedLocation2->id);
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
530
            $this->persistenceHandler->urlAliasHandler()->locationSwapped(
531
                $location1->id,
532
                $location1->parentLocationId,
533
                $location2->id,
534
                $location2->parentLocationId
535
            );
536
            $this->repository->commit();
537
        } catch (Exception $e) {
538
            $this->repository->rollback();
539
            throw $e;
540
        }
541
    }
542
543
    /**
544
     * Hides the $location and marks invisible all descendants of $location.
545
     *
546
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to hide this location
547
     *
548
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
549
     *
550
     * @return \eZ\Publish\API\Repository\Values\Content\Location $location, with updated hidden value
551
     */
552 View Code Duplication
    public function hideLocation(APILocation $location)
553
    {
554
        if (!$this->repository->canUser('content', 'hide', $location->getContentInfo(), $location)) {
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Repository\Repository::canUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::canUser() instead. Check if user has access to a given action on a given value object. Indicates if the current user is allowed to perform an action given by the function on the given
objects.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
555
            throw new UnauthorizedException('content', 'hide');
556
        }
557
558
        $this->repository->beginTransaction();
559
        try {
560
            $this->persistenceHandler->locationHandler()->hide($location->id);
561
            $this->repository->commit();
562
        } catch (Exception $e) {
563
            $this->repository->rollback();
564
            throw $e;
565
        }
566
567
        return $this->loadLocation($location->id);
568
    }
569
570
    /**
571
     * Unhides the $location.
572
     *
573
     * This method and marks visible all descendants of $locations
574
     * until a hidden location is found.
575
     *
576
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to unhide this location
577
     *
578
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
579
     *
580
     * @return \eZ\Publish\API\Repository\Values\Content\Location $location, with updated hidden value
581
     */
582 View Code Duplication
    public function unhideLocation(APILocation $location)
583
    {
584
        if (!$this->repository->canUser('content', 'hide', $location->getContentInfo(), $location)) {
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Repository\Repository::canUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::canUser() instead. Check if user has access to a given action on a given value object. Indicates if the current user is allowed to perform an action given by the function on the given
objects.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
585
            throw new UnauthorizedException('content', 'hide');
586
        }
587
588
        $this->repository->beginTransaction();
589
        try {
590
            $this->persistenceHandler->locationHandler()->unHide($location->id);
591
            $this->repository->commit();
592
        } catch (Exception $e) {
593
            $this->repository->rollback();
594
            throw $e;
595
        }
596
597
        return $this->loadLocation($location->id);
598
    }
599
600
    /**
601
     * Moves the subtree to $newParentLocation.
602
     *
603
     * If a user has the permission to move the location to a target location
604
     * he can do it regardless of an existing descendant on which the user has no permission.
605
     *
606
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to move this location to the target
607
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user does not have read access to the whole source subtree
608
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the new parent is in a subtree of the location
609
     *
610
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
611
     * @param \eZ\Publish\API\Repository\Values\Content\Location $newParentLocation
612
     */
613
    public function moveSubtree(APILocation $location, APILocation $newParentLocation)
614
    {
615
        $location = $this->loadLocation($location->id);
616
        $newParentLocation = $this->loadLocation($newParentLocation->id);
617
618
        // check create permission on target location
619
        if (!$this->repository->canUser('content', 'create', $location->getContentInfo(), $newParentLocation)) {
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Repository\Repository::canUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::canUser() instead. Check if user has access to a given action on a given value object. Indicates if the current user is allowed to perform an action given by the function on the given
objects.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
620
            throw new UnauthorizedException('content', 'create');
621
        }
622
623
        /** Check read access to whole source subtree
624
         * @var bool|\eZ\Publish\API\Repository\Values\Content\Query\Criterion
625
         */
626
        $contentReadCriterion = $this->permissionCriterionResolver->getPermissionsCriterion();
0 ignored issues
show
Bug introduced by
The call to getPermissionsCriterion() misses some required arguments starting with $module.
Loading history...
627 View Code Duplication
        if ($contentReadCriterion === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
628
            throw new UnauthorizedException('content', 'read');
629
        } elseif ($contentReadCriterion !== true) {
630
            // Query if there are any content in subtree current user don't have access to
631
            $query = new Query(
632
                array(
633
                    'limit' => 0,
634
                    'filter' => new CriterionLogicalAnd(
635
                        array(
636
                            new CriterionSubtree($location->pathString),
0 ignored issues
show
Documentation introduced by
The property $pathString is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
637
                            new CriterionLogicalNot($contentReadCriterion),
0 ignored issues
show
Bug introduced by
It seems like $contentReadCriterion defined by $this->permissionCriteri...tPermissionsCriterion() on line 626 can also be of type boolean; however, eZ\Publish\API\Repositor...gicalNot::__construct() does only seem to accept object<eZ\Publish\API\Re...ontent\Query\Criterion>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
638
                        )
639
                    ),
640
                )
641
            );
642
            $result = $this->repository->getSearchService()->findContent($query, array(), false);
643
            if ($result->totalCount > 0) {
644
                throw new UnauthorizedException('content', 'read');
645
            }
646
        }
647
648
        if (strpos($newParentLocation->pathString, $location->pathString) === 0) {
0 ignored issues
show
Documentation introduced by
The property $pathString is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
649
            throw new InvalidArgumentException(
650
                '$newParentLocation',
651
                'new parent location is in a subtree of the given $location'
652
            );
653
        }
654
655
        $this->repository->beginTransaction();
656
        try {
657
            $this->persistenceHandler->locationHandler()->move($location->id, $newParentLocation->id);
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
658
659
            $content = $this->repository->getContentService()->loadContent($location->contentId);
660
            $urlAliasNames = $this->nameSchemaService->resolveUrlAliasSchema($content);
661 View Code Duplication
            foreach ($urlAliasNames as $languageCode => $name) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
662
                $this->persistenceHandler->urlAliasHandler()->publishUrlAliasForLocation(
663
                    $location->id,
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
664
                    $newParentLocation->id,
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
665
                    $name,
666
                    $languageCode,
667
                    $content->contentInfo->alwaysAvailable
668
                );
669
            }
670
671
            $this->persistenceHandler->urlAliasHandler()->locationMoved(
672
                $location->id,
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
673
                $location->parentLocationId,
0 ignored issues
show
Documentation introduced by
The property $parentLocationId is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
674
                $newParentLocation->id
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
675
            );
676
677
            $this->repository->commit();
678
        } catch (Exception $e) {
679
            $this->repository->rollback();
680
            throw $e;
681
        }
682
    }
683
684
    /**
685
     * Deletes $location and all its descendants.
686
     *
687
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to delete this location or a descendant
688
     *
689
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
690
     */
691
    public function deleteLocation(APILocation $location)
692
    {
693
        $location = $this->loadLocation($location->id);
694
695
        if (!$this->repository->canUser('content', 'manage_locations', $location->getContentInfo())) {
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Repository\Repository::canUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::canUser() instead. Check if user has access to a given action on a given value object. Indicates if the current user is allowed to perform an action given by the function on the given
objects.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
696
            throw new UnauthorizedException('content', 'manage_locations');
697
        }
698
        if (!$this->repository->canUser('content', 'remove', $location->getContentInfo(), $location)) {
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Repository\Repository::canUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::canUser() instead. Check if user has access to a given action on a given value object. Indicates if the current user is allowed to perform an action given by the function on the given
objects.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
699
            throw new UnauthorizedException('content', 'remove');
700
        }
701
702
        /** Check remove access to descendants
703
         * @var bool|\eZ\Publish\API\Repository\Values\Content\Query\Criterion
704
         */
705
        $contentReadCriterion = $this->permissionCriterionResolver->getPermissionsCriterion('content', 'remove');
706 View Code Duplication
        if ($contentReadCriterion === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
707
            throw new UnauthorizedException('content', 'remove');
708
        } elseif ($contentReadCriterion !== true) {
709
            // Query if there are any content in subtree current user don't have access to
710
            $query = new Query(
711
                array(
712
                    'limit' => 0,
713
                    'filter' => new CriterionLogicalAnd(
714
                        array(
715
                            new CriterionSubtree($location->pathString),
0 ignored issues
show
Documentation introduced by
The property $pathString is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
716
                            new CriterionLogicalNot($contentReadCriterion),
0 ignored issues
show
Bug introduced by
It seems like $contentReadCriterion defined by $this->permissionCriteri...on('content', 'remove') on line 705 can also be of type boolean; however, eZ\Publish\API\Repositor...gicalNot::__construct() does only seem to accept object<eZ\Publish\API\Re...ontent\Query\Criterion>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
717
                        )
718
                    ),
719
                )
720
            );
721
            $result = $this->repository->getSearchService()->findContent($query, array(), false);
722
            if ($result->totalCount > 0) {
723
                throw new UnauthorizedException('content', 'remove');
724
            }
725
        }
726
727
        $this->repository->beginTransaction();
728
        try {
729
            $this->persistenceHandler->locationHandler()->removeSubtree($location->id);
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
730
            $this->persistenceHandler->urlAliasHandler()->locationDeleted($location->id);
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
731
            $this->repository->commit();
732
        } catch (Exception $e) {
733
            $this->repository->rollback();
734
            throw $e;
735
        }
736
    }
737
738
    /**
739
     * Instantiates a new location create class.
740
     *
741
     * @param mixed $parentLocationId the parent under which the new location should be created
742
     *
743
     * @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct
744
     */
745
    public function newLocationCreateStruct($parentLocationId)
746
    {
747
        return new LocationCreateStruct(
748
            array(
749
                'parentLocationId' => $parentLocationId,
750
            )
751
        );
752
    }
753
754
    /**
755
     * Instantiates a new location update class.
756
     *
757
     * @return \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct
758
     */
759
    public function newLocationUpdateStruct()
760
    {
761
        return new LocationUpdateStruct();
762
    }
763
}
764