Completed
Push — ezp-26146_location_swap_incons... ( ba812b...4a02af )
by
unknown
83:29 queued 58:32
created

LocationService::loadLocation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
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
 * @version //autogentag//
10
 */
11
namespace eZ\Publish\Core\Repository;
12
13
use eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct;
14
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct;
15
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
16
use eZ\Publish\API\Repository\Values\Content\Location as APILocation;
17
use eZ\Publish\API\Repository\Values\Content\LocationList;
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\Values\Content\Query\SortClause;
29
use eZ\Publish\API\Repository\Exceptions\NotFoundException as APINotFoundException;
30
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue;
31
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException;
32
use eZ\Publish\Core\Base\Exceptions\BadStateException;
33
use eZ\Publish\Core\Base\Exceptions\UnauthorizedException;
34
use Exception;
35
36
/**
37
 * Location service, used for complex subtree operations.
38
 *
39
 * @example Examples/location.php
40
 */
41
class LocationService implements LocationServiceInterface
42
{
43
    /**
44
     * @var \eZ\Publish\Core\Repository\Repository
45
     */
46
    protected $repository;
47
48
    /**
49
     * @var \eZ\Publish\SPI\Persistence\Handler
50
     */
51
    protected $persistenceHandler;
52
53
    /**
54
     * @var array
55
     */
56
    protected $settings;
57
58
    /**
59
     * @var \eZ\Publish\Core\Repository\Helper\DomainMapper
60
     */
61
    protected $domainMapper;
62
63
    /**
64
     * @var \eZ\Publish\Core\Repository\Helper\NameSchemaService
65
     */
66
    protected $nameSchemaService;
67
68
    /**
69
     * @var \eZ\Publish\Core\Repository\PermissionsCriterionHandler
70
     */
71
    protected $permissionsCriterionHandler;
72
73
    /**
74
     * Setups service with reference to repository object that created it & corresponding handler.
75
     *
76
     * @param \eZ\Publish\API\Repository\Repository $repository
77
     * @param \eZ\Publish\SPI\Persistence\Handler $handler
78
     * @param \eZ\Publish\Core\Repository\Helper\DomainMapper $domainMapper
79
     * @param \eZ\Publish\Core\Repository\Helper\NameSchemaService $nameSchemaService
80
     * @param \eZ\Publish\Core\Repository\PermissionsCriterionHandler $permissionsCriterionHandler
81
     * @param array $settings
82
     */
83 View Code Duplication
    public function __construct(
84
        RepositoryInterface $repository,
85
        Handler $handler,
86
        Helper\DomainMapper $domainMapper,
87
        Helper\NameSchemaService $nameSchemaService,
88
        PermissionsCriterionHandler $permissionsCriterionHandler,
89
        array $settings = array()
90
    ) {
91
        $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...
92
        $this->persistenceHandler = $handler;
93
        $this->domainMapper = $domainMapper;
94
        $this->nameSchemaService = $nameSchemaService;
95
        // Union makes sure default settings are ignored if provided in argument
96
        $this->settings = $settings + array(
97
            //'defaultSetting' => array(),
98
        );
99
        $this->permissionsCriterionHandler = $permissionsCriterionHandler;
100
    }
101
102
    /**
103
     * Copies the subtree starting from $subtree as a new subtree of $targetLocation.
104
     *
105
     * Only the items on which the user has read access are copied.
106
     *
107
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed copy the subtree to the given parent location
108
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user does not have read access to the whole source subtree
109
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the target location is a sub location of the given location
110
     *
111
     * @param \eZ\Publish\API\Repository\Values\Content\Location $subtree - the subtree denoted by the location to copy
112
     * @param \eZ\Publish\API\Repository\Values\Content\Location $targetParentLocation - the target parent location for the copy operation
113
     *
114
     * @return \eZ\Publish\API\Repository\Values\Content\Location The newly created location of the copied subtree
115
     */
116
    public function copySubtree(APILocation $subtree, APILocation $targetParentLocation)
117
    {
118
        $loadedSubtree = $this->loadLocation($subtree->id);
119
        $loadedTargetLocation = $this->loadLocation($targetParentLocation->id);
120
121
        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...
122
            throw new InvalidArgumentException('targetParentLocation', 'target parent location is a sub location of the given subtree');
123
        }
124
125
        // check create permission on target
126
        if (!$this->repository->canUser('content', 'create', $loadedSubtree->getContentInfo(), $loadedTargetLocation)) {
127
            throw new UnauthorizedException('content', 'create');
128
        }
129
130
        /** Check read access to whole source subtree
131
         * @var bool|\eZ\Publish\API\Repository\Values\Content\Query\Criterion
132
         */
133
        $contentReadCriterion = $this->permissionsCriterionHandler->getPermissionsCriterion();
134 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...
135
            throw new UnauthorizedException('content', 'read');
136
        } elseif ($contentReadCriterion !== true) {
137
            // Query if there are any content in subtree current user don't have access to
138
            $query = new Query(
139
                array(
140
                    'limit' => 0,
141
                    'filter' => new CriterionLogicalAnd(
142
                        array(
143
                            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...
144
                            new CriterionLogicalNot($contentReadCriterion),
0 ignored issues
show
Bug introduced by
It seems like $contentReadCriterion defined by $this->permissionsCriter...tPermissionsCriterion() on line 133 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...
145
                        )
146
                    ),
147
                )
148
            );
149
            $result = $this->repository->getSearchService()->findContent($query, array(), false);
150
            if ($result->totalCount > 0) {
151
                throw new UnauthorizedException('content', 'read');
152
            }
153
        }
154
155
        $this->repository->beginTransaction();
156
        try {
157
            $newLocation = $this->persistenceHandler->locationHandler()->copySubtree(
158
                $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...
159
                $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...
160
            );
161
162
            $content = $this->repository->getContentService()->loadContent($newLocation->contentId);
163
            $urlAliasNames = $this->nameSchemaService->resolveUrlAliasSchema($content);
164 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...
165
                $this->persistenceHandler->urlAliasHandler()->publishUrlAliasForLocation(
166
                    $newLocation->id,
167
                    $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...
168
                    $name,
169
                    $languageCode,
170
                    $content->contentInfo->alwaysAvailable
171
                );
172
            }
173
174
            $this->persistenceHandler->urlAliasHandler()->locationCopied(
175
                $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...
176
                $newLocation->id,
177
                $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...
178
            );
179
180
            $this->repository->commit();
181
        } catch (Exception $e) {
182
            $this->repository->rollback();
183
            throw $e;
184
        }
185
186
        return $this->domainMapper->buildLocationDomainObject($newLocation);
187
    }
188
189
    /**
190
     * Loads a location object from its $locationId.
191
     *
192
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to read this location
193
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified location is not found
194
     *
195
     * @param mixed $locationId
196
     *
197
     * @return \eZ\Publish\API\Repository\Values\Content\Location
198
     */
199
    public function loadLocation($locationId)
200
    {
201
        $spiLocation = $this->persistenceHandler->locationHandler()->load($locationId);
202
        $location = $this->domainMapper->buildLocationDomainObject($spiLocation);
203
        if (!$this->repository->canUser('content', 'read', $location->getContentInfo(), $location)) {
204
            throw new UnauthorizedException('content', 'read');
205
        }
206
207
        return $location;
208
    }
209
210
    /**
211
     * Loads a location object from its $remoteId.
212
     *
213
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to read this location
214
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If more than one location with same remote ID was found
215
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified location is not found
216
     *
217
     * @param string $remoteId
218
     *
219
     * @return \eZ\Publish\API\Repository\Values\Content\Location
220
     */
221
    public function loadLocationByRemoteId($remoteId)
222
    {
223
        if (!is_string($remoteId)) {
224
            throw new InvalidArgumentValue('remoteId', $remoteId);
225
        }
226
227
        $spiLocation = $this->persistenceHandler->locationHandler()->loadByRemoteId($remoteId);
228
        $location = $this->domainMapper->buildLocationDomainObject($spiLocation);
229
        if (!$this->repository->canUser('content', 'read', $location->getContentInfo(), $location)) {
230
            throw new UnauthorizedException('content', 'read');
231
        }
232
233
        return $location;
234
    }
235
236
    /**
237
     * Loads the locations for the given content object.
238
     *
239
     * If a $rootLocation is given, only locations that belong to this location are returned.
240
     * The location list is also filtered by permissions on reading locations.
241
     *
242
     * @todo permissions check is missing
243
     *
244
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if there is no published version yet
245
     *
246
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
247
     * @param \eZ\Publish\API\Repository\Values\Content\Location $rootLocation
248
     *
249
     * @return \eZ\Publish\API\Repository\Values\Content\Location[] An array of {@link Location}
250
     */
251
    public function loadLocations(ContentInfo $contentInfo, APILocation $rootLocation = null)
252
    {
253
        if (!$contentInfo->published) {
254
            throw new BadStateException('$contentInfo', 'ContentInfo has no published versions');
255
        }
256
257
        $spiLocations = $this->persistenceHandler->locationHandler()->loadLocationsByContent(
258
            $contentInfo->id,
259
            $rootLocation !== null ? $rootLocation->id : null
260
        );
261
262
        $locations = array();
263
        foreach ($spiLocations as $spiLocation) {
264
            $locations[] = $this->domainMapper->buildLocationDomainObject($spiLocation);
265
        }
266
267
        return $locations;
268
    }
269
270
    /**
271
     * Loads children which are readable by the current user of a location object sorted by sortField and sortOrder.
272
     *
273
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
274
     * @param int $offset the start offset for paging
275
     * @param int $limit the number of locations returned
276
     *
277
     * @return \eZ\Publish\API\Repository\Values\Content\LocationList
278
     */
279
    public function loadLocationChildren(APILocation $location, $offset = 0, $limit = 25)
280
    {
281
        if (!$this->domainMapper->isValidLocationSortField($location->sortField)) {
282
            throw new InvalidArgumentValue('sortField', $location->sortField, 'Location');
283
        }
284
285
        if (!$this->domainMapper->isValidLocationSortOrder($location->sortOrder)) {
286
            throw new InvalidArgumentValue('sortOrder', $location->sortOrder, 'Location');
287
        }
288
289
        if (!is_int($offset)) {
290
            throw new InvalidArgumentValue('offset', $offset);
291
        }
292
293
        if (!is_int($limit)) {
294
            throw new InvalidArgumentValue('limit', $limit);
295
        }
296
297
        $childLocations = array();
298
        $searchResult = $this->searchChildrenLocations(
299
            $location->id,
300
            $location->sortField,
301
            $location->sortOrder,
302
            $offset,
303
            $limit
304
        );
305
        foreach ($searchResult->searchHits as $searchHit) {
306
            $childLocations[] = $searchHit->valueObject;
307
        }
308
309
        return new LocationList(
310
            array(
311
                'locations' => $childLocations,
312
                'totalCount' => $searchResult->totalCount,
313
            )
314
        );
315
    }
316
317
    /**
318
     * Returns the number of children which are readable by the current user of a location object.
319
     *
320
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
321
     *
322
     * @return int
323
     */
324
    public function getLocationChildCount(APILocation $location)
325
    {
326
        $searchResult = $this->searchChildrenLocations(
327
            $location->id,
328
            $location->sortField,
329
            $location->sortOrder,
330
            0,
331
            0
332
        );
333
334
        return $searchResult->totalCount;
335
    }
336
337
    /**
338
     * Searches children locations of the provided parent location id.
339
     *
340
     * @param mixed $parentLocationId
341
     * @param int $sortField
342
     * @param int $sortOrder
343
     * @param int $offset
344
     * @param int $limit
345
     *
346
     * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult
347
     */
348
    protected function searchChildrenLocations(
349
        $parentLocationId,
350
        $sortField = null,
351
        $sortOrder = APILocation::SORT_ORDER_ASC,
352
        $offset = 0,
353
        $limit = -1
354
    ) {
355
        $query = new LocationQuery(
356
            array(
357
                'filter' => new Criterion\ParentLocationId($parentLocationId),
358
                'offset' => $offset >= 0 ? (int)$offset : 0,
359
                'limit' => $limit >= 0 ? (int)$limit : null,
360
            )
361
        );
362
363
        if ($sortField !== null) {
364
            $query->sortClauses = array($this->getSortClauseBySortField($sortField, $sortOrder));
365
        }
366
367
        return $this->repository->getSearchService()->findLocations($query);
368
    }
369
370
    /**
371
     * Creates the new $location in the content repository for the given content.
372
     *
373
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to create this location
374
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the content is already below the specified parent
375
     *                                        or the parent is a sub location of the location of the content
376
     *                                        or if set the remoteId exists already
377
     *
378
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
379
     * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $locationCreateStruct
380
     *
381
     * @return \eZ\Publish\API\Repository\Values\Content\Location the newly created Location
382
     */
383
    public function createLocation(ContentInfo $contentInfo, LocationCreateStruct $locationCreateStruct)
384
    {
385
        $content = $this->repository->getContentService()->loadContent($contentInfo->id);
386
        $parentLocation = $this->loadLocation($locationCreateStruct->parentLocationId);
387
388
        if (!$this->repository->canUser('content', 'create', $content->contentInfo, $parentLocation)) {
389
            throw new UnauthorizedException('content', 'create');
390
        }
391
392
        // Check if the parent is a sub location of one of the existing content locations (this also solves the
393
        // situation where parent location actually one of the content locations),
394
        // or if the content already has location below given location create struct parent
395
        $existingContentLocations = $this->loadLocations($content->contentInfo);
396
        if (!empty($existingContentLocations)) {
397
            foreach ($existingContentLocations as $existingContentLocation) {
398
                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...
399
                    throw new InvalidArgumentException(
400
                        '$locationCreateStruct',
401
                        'Specified parent is a sub location of one of the existing content locations.'
402
                    );
403
                }
404
                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...
405
                    throw new InvalidArgumentException(
406
                        '$locationCreateStruct',
407
                        'Content is already below the specified parent.'
408
                    );
409
                }
410
            }
411
        }
412
413
        $spiLocationCreateStruct = $this->domainMapper->buildSPILocationCreateStruct(
414
            $locationCreateStruct,
415
            $parentLocation,
416
            $content->contentInfo->mainLocationId !== null ? $content->contentInfo->mainLocationId : true,
417
            $content->contentInfo->id,
418
            $content->contentInfo->currentVersionNo
419
        );
420
421
        $this->repository->beginTransaction();
422
        try {
423
            $newLocation = $this->persistenceHandler->locationHandler()->create($spiLocationCreateStruct);
424
425
            $urlAliasNames = $this->nameSchemaService->resolveUrlAliasSchema($content);
426 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...
427
                $this->persistenceHandler->urlAliasHandler()->publishUrlAliasForLocation(
428
                    $newLocation->id,
429
                    $newLocation->parentId,
430
                    $name,
431
                    $languageCode,
432
                    $content->contentInfo->alwaysAvailable,
433
                    // @todo: this is legacy storage specific for updating ezcontentobject_tree.path_identification_string, to be removed
434
                    $languageCode === $content->contentInfo->mainLanguageCode
435
                );
436
            }
437
438
            $this->repository->commit();
439
        } catch (Exception $e) {
440
            $this->repository->rollback();
441
            throw $e;
442
        }
443
444
        return $this->domainMapper->buildLocationDomainObject($newLocation);
445
    }
446
447
    /**
448
     * Updates $location in the content repository.
449
     *
450
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to update this location
451
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException   if if set the remoteId exists already
452
     *
453
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
454
     * @param \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct $locationUpdateStruct
455
     *
456
     * @return \eZ\Publish\API\Repository\Values\Content\Location the updated Location
457
     */
458
    public function updateLocation(APILocation $location, LocationUpdateStruct $locationUpdateStruct)
459
    {
460
        if ($locationUpdateStruct->priority !== null && !is_int($locationUpdateStruct->priority)) {
461
            throw new InvalidArgumentValue('priority', $locationUpdateStruct->priority, 'LocationUpdateStruct');
462
        }
463
464
        if ($locationUpdateStruct->remoteId !== null && (!is_string($locationUpdateStruct->remoteId) || empty($locationUpdateStruct->remoteId))) {
465
            throw new InvalidArgumentValue('remoteId', $locationUpdateStruct->remoteId, 'LocationUpdateStruct');
466
        }
467
468
        if ($locationUpdateStruct->sortField !== null && !$this->domainMapper->isValidLocationSortField($locationUpdateStruct->sortField)) {
469
            throw new InvalidArgumentValue('sortField', $locationUpdateStruct->sortField, 'LocationUpdateStruct');
470
        }
471
472
        if ($locationUpdateStruct->sortOrder !== null && !$this->domainMapper->isValidLocationSortOrder($locationUpdateStruct->sortOrder)) {
473
            throw new InvalidArgumentValue('sortOrder', $locationUpdateStruct->sortOrder, 'LocationUpdateStruct');
474
        }
475
476
        $loadedLocation = $this->loadLocation($location->id);
477
478
        if ($locationUpdateStruct->remoteId !== null) {
479
            try {
480
                $existingLocation = $this->loadLocationByRemoteId($locationUpdateStruct->remoteId);
481
                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...
482
                    throw new InvalidArgumentException('locationUpdateStruct', 'location with provided remote ID already exists');
483
                }
484
            } catch (APINotFoundException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
485
            }
486
        }
487
488
        if (!$this->repository->canUser('content', 'edit', $loadedLocation->getContentInfo(), $loadedLocation)) {
489
            throw new UnauthorizedException('content', 'edit');
490
        }
491
492
        $updateStruct = new UpdateStruct();
493
        $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...
494
        $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...
495
        $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...
496
        $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...
497
498
        $this->repository->beginTransaction();
499
        try {
500
            $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...
501
            $this->repository->commit();
502
        } catch (Exception $e) {
503
            $this->repository->rollback();
504
            throw $e;
505
        }
506
507
        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...
508
    }
509
510
    /**
511
     * Swaps the contents held by $location1 and $location2.
512
     *
513
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to swap content
514
     *
515
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location1
516
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location2
517
     */
518
    public function swapLocation(APILocation $location1, APILocation $location2)
519
    {
520
        $loadedLocation1 = $this->loadLocation($location1->id);
521
        $loadedLocation2 = $this->loadLocation($location2->id);
522
523
        if (!$this->repository->canUser('content', 'edit', $loadedLocation1->getContentInfo(), $loadedLocation1)) {
524
            throw new UnauthorizedException('content', 'edit');
525
        }
526
        if (!$this->repository->canUser('content', 'edit', $loadedLocation2->getContentInfo(), $loadedLocation2)) {
527
            throw new UnauthorizedException('content', 'edit');
528
        }
529
530
        $this->repository->beginTransaction();
531
        try {
532
            $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...
533
            $this->persistenceHandler->urlAliasHandler()->publishUrlAliasForLocation(
534
                $loadedLocation1->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...
535
                $loadedLocation1->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...
536
                $loadedLocation1->contentInfo->name,
0 ignored issues
show
Documentation introduced by
The property $contentInfo is declared protected in eZ\Publish\Core\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...
537
                $loadedLocation1->contentInfo->mainLanguageCode
0 ignored issues
show
Documentation introduced by
The property $contentInfo is declared protected in eZ\Publish\Core\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...
538
            );
539
            $this->persistenceHandler->urlAliasHandler()->publishUrlAliasForLocation(
540
                $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...
541
                $loadedLocation2->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...
542
                $loadedLocation2->contentInfo->name,
0 ignored issues
show
Documentation introduced by
The property $contentInfo is declared protected in eZ\Publish\Core\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...
543
                $loadedLocation2->contentInfo->mainLanguageCode
0 ignored issues
show
Documentation introduced by
The property $contentInfo is declared protected in eZ\Publish\Core\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...
544
            );
545
            $this->repository->commit();
546
        } catch (Exception $e) {
547
            $this->repository->rollback();
548
            throw $e;
549
        }
550
    }
551
552
    /**
553
     * Hides the $location and marks invisible all descendants of $location.
554
     *
555
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to hide this location
556
     *
557
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
558
     *
559
     * @return \eZ\Publish\API\Repository\Values\Content\Location $location, with updated hidden value
560
     */
561 View Code Duplication
    public function hideLocation(APILocation $location)
562
    {
563
        if (!$this->repository->canUser('content', 'hide', $location->getContentInfo(), $location)) {
564
            throw new UnauthorizedException('content', 'hide');
565
        }
566
567
        $this->repository->beginTransaction();
568
        try {
569
            $this->persistenceHandler->locationHandler()->hide($location->id);
570
            $this->repository->commit();
571
        } catch (Exception $e) {
572
            $this->repository->rollback();
573
            throw $e;
574
        }
575
576
        return $this->loadLocation($location->id);
577
    }
578
579
    /**
580
     * Unhides the $location.
581
     *
582
     * This method and marks visible all descendants of $locations
583
     * until a hidden location is found.
584
     *
585
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to unhide this location
586
     *
587
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
588
     *
589
     * @return \eZ\Publish\API\Repository\Values\Content\Location $location, with updated hidden value
590
     */
591 View Code Duplication
    public function unhideLocation(APILocation $location)
592
    {
593
        if (!$this->repository->canUser('content', 'hide', $location->getContentInfo(), $location)) {
594
            throw new UnauthorizedException('content', 'hide');
595
        }
596
597
        $this->repository->beginTransaction();
598
        try {
599
            $this->persistenceHandler->locationHandler()->unHide($location->id);
600
            $this->repository->commit();
601
        } catch (Exception $e) {
602
            $this->repository->rollback();
603
            throw $e;
604
        }
605
606
        return $this->loadLocation($location->id);
607
    }
608
609
    /**
610
     * Moves the subtree to $newParentLocation.
611
     *
612
     * If a user has the permission to move the location to a target location
613
     * he can do it regardless of an existing descendant on which the user has no permission.
614
     *
615
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to move this location to the target
616
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user does not have read access to the whole source subtree
617
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the new parent is in a subtree of the location
618
     *
619
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
620
     * @param \eZ\Publish\API\Repository\Values\Content\Location $newParentLocation
621
     */
622
    public function moveSubtree(APILocation $location, APILocation $newParentLocation)
623
    {
624
        $location = $this->loadLocation($location->id);
625
        $newParentLocation = $this->loadLocation($newParentLocation->id);
626
627
        // check create permission on target location
628
        if (!$this->repository->canUser('content', 'create', $location->getContentInfo(), $newParentLocation)) {
629
            throw new UnauthorizedException('content', 'create');
630
        }
631
632
        /** Check read access to whole source subtree
633
         * @var bool|\eZ\Publish\API\Repository\Values\Content\Query\Criterion
634
         */
635
        $contentReadCriterion = $this->permissionsCriterionHandler->getPermissionsCriterion();
636 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...
637
            throw new UnauthorizedException('content', 'read');
638
        } elseif ($contentReadCriterion !== true) {
639
            // Query if there are any content in subtree current user don't have access to
640
            $query = new Query(
641
                array(
642
                    'limit' => 0,
643
                    'filter' => new CriterionLogicalAnd(
644
                        array(
645
                            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...
646
                            new CriterionLogicalNot($contentReadCriterion),
0 ignored issues
show
Bug introduced by
It seems like $contentReadCriterion defined by $this->permissionsCriter...tPermissionsCriterion() on line 635 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...
647
                        )
648
                    ),
649
                )
650
            );
651
            $result = $this->repository->getSearchService()->findContent($query, array(), false);
652
            if ($result->totalCount > 0) {
653
                throw new UnauthorizedException('content', 'read');
654
            }
655
        }
656
657
        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...
658
            throw new InvalidArgumentException(
659
                '$newParentLocation',
660
                'new parent location is in a subtree of the given $location'
661
            );
662
        }
663
664
        $this->repository->beginTransaction();
665
        try {
666
            $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...
667
668
            $content = $this->repository->getContentService()->loadContent($location->contentId);
669
            $urlAliasNames = $this->nameSchemaService->resolveUrlAliasSchema($content);
670 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...
671
                $this->persistenceHandler->urlAliasHandler()->publishUrlAliasForLocation(
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
                    $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...
674
                    $name,
675
                    $languageCode,
676
                    $content->contentInfo->alwaysAvailable
677
                );
678
            }
679
680
            $this->persistenceHandler->urlAliasHandler()->locationMoved(
681
                $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...
682
                $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...
683
                $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...
684
            );
685
686
            $this->repository->commit();
687
        } catch (Exception $e) {
688
            $this->repository->rollback();
689
            throw $e;
690
        }
691
    }
692
693
    /**
694
     * Deletes $location and all its descendants.
695
     *
696
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to delete this location or a descendant
697
     *
698
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
699
     */
700
    public function deleteLocation(APILocation $location)
701
    {
702
        $location = $this->loadLocation($location->id);
703
704
        if (!$this->repository->canUser('content', 'manage_locations', $location->getContentInfo())) {
705
            throw new UnauthorizedException('content', 'manage_locations');
706
        }
707
        if (!$this->repository->canUser('content', 'remove', $location->getContentInfo(), $location)) {
708
            throw new UnauthorizedException('content', 'remove');
709
        }
710
711
        /** Check remove access to descendants
712
         * @var bool|\eZ\Publish\API\Repository\Values\Content\Query\Criterion
713
         */
714
        $contentReadCriterion = $this->permissionsCriterionHandler->getPermissionsCriterion('content', 'remove');
715 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...
716
            throw new UnauthorizedException('content', 'remove');
717
        } elseif ($contentReadCriterion !== true) {
718
            // Query if there are any content in subtree current user don't have access to
719
            $query = new Query(
720
                array(
721
                    'limit' => 0,
722
                    'filter' => new CriterionLogicalAnd(
723
                        array(
724
                            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...
725
                            new CriterionLogicalNot($contentReadCriterion),
0 ignored issues
show
Bug introduced by
It seems like $contentReadCriterion defined by $this->permissionsCriter...on('content', 'remove') on line 714 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...
726
                        )
727
                    ),
728
                )
729
            );
730
            $result = $this->repository->getSearchService()->findContent($query, array(), false);
731
            if ($result->totalCount > 0) {
732
                throw new UnauthorizedException('content', 'remove');
733
            }
734
        }
735
736
        $this->repository->beginTransaction();
737
        try {
738
            $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...
739
            $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...
740
            $this->repository->commit();
741
        } catch (Exception $e) {
742
            $this->repository->rollback();
743
            throw $e;
744
        }
745
    }
746
747
    /**
748
     * Instantiates a new location create class.
749
     *
750
     * @param mixed $parentLocationId the parent under which the new location should be created
751
     *
752
     * @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct
753
     */
754
    public function newLocationCreateStruct($parentLocationId)
755
    {
756
        return new LocationCreateStruct(
757
            array(
758
                'parentLocationId' => $parentLocationId,
759
            )
760
        );
761
    }
762
763
    /**
764
     * Instantiates a new location update class.
765
     *
766
     * @return \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct
767
     */
768
    public function newLocationUpdateStruct()
769
    {
770
        return new LocationUpdateStruct();
771
    }
772
773
    /**
774
     * Instantiates a correct sort clause object based on provided location sort field and sort order.
775
     *
776
     * @param int $sortField
777
     * @param int $sortOrder
778
     *
779
     * @return \eZ\Publish\API\Repository\Values\Content\Query\SortClause
780
     */
781
    protected function getSortClauseBySortField($sortField, $sortOrder = APILocation::SORT_ORDER_ASC)
782
    {
783
        $sortOrder = $sortOrder == APILocation::SORT_ORDER_DESC ? Query::SORT_DESC : Query::SORT_ASC;
784
        switch ($sortField) {
785
            case APILocation::SORT_FIELD_PATH:
786
                return new SortClause\Location\Path($sortOrder);
787
788
            case APILocation::SORT_FIELD_PUBLISHED:
789
                return new SortClause\DatePublished($sortOrder);
790
791
            case APILocation::SORT_FIELD_MODIFIED:
792
                return new SortClause\DateModified($sortOrder);
793
794
            case APILocation::SORT_FIELD_SECTION:
795
                return new SortClause\SectionIdentifier($sortOrder);
796
797
            case APILocation::SORT_FIELD_DEPTH:
798
                return new SortClause\Location\Depth($sortOrder);
799
800
            //@todo: sort clause not yet implemented
801
            // case APILocation::SORT_FIELD_CLASS_IDENTIFIER:
802
803
            //@todo: sort clause not yet implemented
804
            // case APILocation::SORT_FIELD_CLASS_NAME:
805
806
            case APILocation::SORT_FIELD_PRIORITY:
807
                return new SortClause\Location\Priority($sortOrder);
808
809
            case APILocation::SORT_FIELD_NAME:
810
                return new SortClause\ContentName($sortOrder);
811
812
            //@todo: sort clause not yet implemented
813
            // case APILocation::SORT_FIELD_MODIFIED_SUBNODE:
814
815
            case APILocation::SORT_FIELD_NODE_ID:
816
                return new SortClause\Location\Id($sortOrder);
817
818
            case APILocation::SORT_FIELD_CONTENTOBJECT_ID:
819
                return new SortClause\ContentId($sortOrder);
820
821
            default:
822
                return new SortClause\Location\Path($sortOrder);
823
        }
824
    }
825
}
826