Completed
Push — ezp28048_trash_move_when_cant_... ( e40bc7 )
by
unknown
16:14
created

TrashService   B

Complexity

Total Complexity 47

Size/Duplication

Total Lines 326
Duplicated Lines 16.26 %

Coupling/Cohesion

Components 1
Dependencies 12

Importance

Changes 0
Metric Value
dl 53
loc 326
rs 8.439
c 0
b 0
f 0
wmc 47
lcom 1
cbo 12

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A loadTrashItem() 0 14 3
B trash() 0 33 6
C recover() 0 48 10
A emptyTrash() 16 16 3
A deleteTrashItem() 19 19 4
D findTrashItems() 0 45 18
A buildDomainTrashItemObject() 18 18 1
A getDateTime() 0 7 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like TrashService often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use TrashService, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * File containing the eZ\Publish\Core\Repository\TrashService class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Repository;
10
11
use eZ\Publish\API\Repository\TrashService as TrashServiceInterface;
12
use eZ\Publish\API\Repository\Repository as RepositoryInterface;
13
use eZ\Publish\SPI\Persistence\Handler;
14
use eZ\Publish\API\Repository\Values\Content\Location;
15
use eZ\Publish\Core\Repository\Values\Content\TrashItem;
16
use eZ\Publish\API\Repository\Values\Content\TrashItem as APITrashItem;
17
use eZ\Publish\API\Repository\Values\Content\Query;
18
use eZ\Publish\SPI\Persistence\Content\Location\Trashed;
19
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue;
20
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
21
use eZ\Publish\Core\Base\Exceptions\UnauthorizedException;
22
use eZ\Publish\API\Repository\Values\Content\SearchResult;
23
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
24
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
25
use DateTime;
26
use Exception;
27
28
/**
29
 * Trash service, used for managing trashed content.
30
 */
31
class TrashService implements TrashServiceInterface
32
{
33
    /**
34
     * @var \eZ\Publish\API\Repository\Repository|\eZ\Publish\Core\Repository\Repository
35
     */
36
    protected $repository;
37
38
    /**
39
     * @var \eZ\Publish\SPI\Persistence\Handler
40
     */
41
    protected $persistenceHandler;
42
43
    /**
44
     * @var array
45
     */
46
    protected $settings;
47
48
    /**
49
     * @var \eZ\Publish\Core\Repository\Helper\NameSchemaService
50
     */
51
    protected $nameSchemaService;
52
53
    /**
54
     * Setups service with reference to repository object that created it & corresponding handler.
55
     *
56
     * @param \eZ\Publish\API\Repository\Repository $repository
57
     * @param \eZ\Publish\SPI\Persistence\Handler $handler
58
     * @param \eZ\Publish\Core\Repository\Helper\NameSchemaService $nameSchemaService
59
     * @param array $settings
60
     */
61
    public function __construct(
62
        RepositoryInterface $repository,
63
        Handler $handler,
64
        Helper\NameSchemaService $nameSchemaService,
65
        array $settings = array()
66
    ) {
67
        $this->repository = $repository;
68
        $this->persistenceHandler = $handler;
69
        $this->nameSchemaService = $nameSchemaService;
70
        // Union makes sure default settings are ignored if provided in argument
71
        $this->settings = $settings + array(
72
            //'defaultSetting' => array(),
73
        );
74
    }
75
76
    /**
77
     * Loads a trashed location object from its $id.
78
     *
79
     * Note that $id is identical to original location, which has been previously trashed
80
     *
81
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the trashed location
82
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the location with the given id does not exist
83
     *
84
     * @param mixed $trashItemId
85
     *
86
     * @return \eZ\Publish\API\Repository\Values\Content\TrashItem
87
     */
88
    public function loadTrashItem($trashItemId)
89
    {
90
        if ($this->repository->hasAccess('content', 'restore') !== true) {
91
            throw new UnauthorizedException('content', 'restore');
92
        }
93
94
        $spiTrashItem = $this->persistenceHandler->trashHandler()->loadTrashItem($trashItemId);
95
        $trash = $this->buildDomainTrashItemObject($spiTrashItem);
96
        if (!$this->repository->canUser('content', 'read', $trash->getContentInfo())) {
97
            throw new UnauthorizedException('content', 'read');
98
        }
99
100
        return $trash;
101
    }
102
103
    /**
104
     * Sends $location and all its children to trash and returns the corresponding trash item.
105
     *
106
     * Content is left untouched.
107
     *
108
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to trash the given location
109
     *
110
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
111
     *
112
     * @return null|\eZ\Publish\API\Repository\Values\Content\TrashItem null if location was deleted, otherwise TrashItem
113
     */
114
    public function trash(Location $location)
115
    {
116
        if (!is_numeric($location->id)) {
117
            throw new InvalidArgumentValue('id', $location->id, 'Location');
118
        }
119
120
        if ($this->repository->canUser('content', 'manage_locations', $location->getContentInfo(), $location) !== true) {
121
            throw new UnauthorizedException('content', 'manage_locations');
122
        }
123
124
        $this->repository->beginTransaction();
125
        try {
126
            $spiTrashItem = $this->persistenceHandler->trashHandler()->trashSubtree($location->id);
127
            $this->persistenceHandler->urlAliasHandler()->locationDeleted($location->id);
128
            $this->repository->commit();
129
        } catch (Exception $e) {
130
            $this->repository->rollback();
131
            throw $e;
132
        }
133
134
        // Use sudo as we want a trash item regardless of user access to the trash.
135
        try {
136
            return isset($spiTrashItem)
137
                ? $this->repository->sudo(
138
                    function () use ($spiTrashItem) {
139
                        return $this->buildDomainTrashItemObject($spiTrashItem);
140
                    }
141
                )
142
                : null;
143
        } catch (Exception $e) {
144
            return null;
145
        }
146
    }
147
148
    /**
149
     * Recovers the $trashedLocation at its original place if possible.
150
     *
151
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to recover the trash item at the parent location location
152
     *
153
     * If $newParentLocation is provided, $trashedLocation will be restored under it.
154
     *
155
     * @param \eZ\Publish\API\Repository\Values\Content\TrashItem $trashItem
156
     * @param \eZ\Publish\API\Repository\Values\Content\Location $newParentLocation
157
     *
158
     * @return \eZ\Publish\API\Repository\Values\Content\Location the newly created or recovered location
159
     */
160
    public function recover(APITrashItem $trashItem, Location $newParentLocation = null)
161
    {
162
        if (!is_numeric($trashItem->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...
163
            throw new InvalidArgumentValue('id', $trashItem->id, 'TrashItem');
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...
164
        }
165
166
        if ($newParentLocation === null && !is_numeric($trashItem->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...
167
            throw new InvalidArgumentValue('parentLocationId', $trashItem->parentLocationId, 'TrashItem');
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...
168
        }
169
170
        if ($newParentLocation !== null && !is_numeric($newParentLocation->id)) {
171
            throw new InvalidArgumentValue('parentLocationId', $newParentLocation->id, 'Location');
172
        }
173
174
        if ($this->repository->hasAccess('content', 'restore') !== true) {
175
            throw new UnauthorizedException('content', 'restore');
176
        }
177
178
        $this->repository->beginTransaction();
179
        try {
180
            $newParentLocationId = $newParentLocation ? $newParentLocation->id : $trashItem->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...
181
            $newLocationId = $this->persistenceHandler->trashHandler()->recover(
182
                $trashItem->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...
183
                $newParentLocationId
184
            );
185
186
            $content = $this->repository->getContentService()->loadContent($trashItem->contentId);
187
            $urlAliasNames = $this->nameSchemaService->resolveUrlAliasSchema($content);
188
189
            // Publish URL aliases for recovered location
190
            foreach ($urlAliasNames as $languageCode => $name) {
191
                $this->persistenceHandler->urlAliasHandler()->publishUrlAliasForLocation(
192
                    $newLocationId,
193
                    $newParentLocationId,
194
                    $name,
195
                    $languageCode,
196
                    $content->contentInfo->alwaysAvailable
197
                );
198
            }
199
200
            $this->repository->commit();
201
        } catch (Exception $e) {
202
            $this->repository->rollback();
203
            throw $e;
204
        }
205
206
        return $this->repository->getLocationService()->loadLocation($newLocationId);
207
    }
208
209
    /**
210
     * Empties trash.
211
     *
212
     * All locations contained in the trash will be removed. Content objects will be removed
213
     * if all locations of the content are gone.
214
     *
215
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to empty the trash
216
     */
217 View Code Duplication
    public function emptyTrash()
218
    {
219
        if ($this->repository->hasAccess('content', 'cleantrash') !== true) {
220
            throw new UnauthorizedException('content', 'cleantrash');
221
        }
222
223
        $this->repository->beginTransaction();
224
        try {
225
            // Persistence layer takes care of deleting content objects
226
            $this->persistenceHandler->trashHandler()->emptyTrash();
227
            $this->repository->commit();
228
        } catch (Exception $e) {
229
            $this->repository->rollback();
230
            throw $e;
231
        }
232
    }
233
234
    /**
235
     * Deletes a trash item.
236
     *
237
     * The corresponding content object will be removed
238
     *
239
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to delete this trash item
240
     *
241
     * @param \eZ\Publish\API\Repository\Values\Content\TrashItem $trashItem
242
     */
243 View Code Duplication
    public function deleteTrashItem(APITrashItem $trashItem)
244
    {
245
        if ($this->repository->hasAccess('content', 'cleantrash') !== true) {
246
            throw new UnauthorizedException('content', 'cleantrash');
247
        }
248
249
        if (!is_numeric($trashItem->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...
250
            throw new InvalidArgumentValue('id', $trashItem->id, 'TrashItem');
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...
251
        }
252
253
        $this->repository->beginTransaction();
254
        try {
255
            $this->persistenceHandler->trashHandler()->deleteTrashItem($trashItem->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...
256
            $this->repository->commit();
257
        } catch (Exception $e) {
258
            $this->repository->rollback();
259
            throw $e;
260
        }
261
    }
262
263
    /**
264
     * Returns a collection of Trashed locations contained in the trash.
265
     *
266
     * $query allows to filter/sort the elements to be contained in the collection.
267
     *
268
     * @param \eZ\Publish\API\Repository\Values\Content\Query $query
269
     *
270
     * @return \eZ\Publish\API\Repository\Values\Content\SearchResult
271
     */
272
    public function findTrashItems(Query $query)
273
    {
274
        if ($query->filter !== null && !$query->filter instanceof Criterion) {
275
            throw new InvalidArgumentValue('query->filter', $query->filter, 'Query');
276
        }
277
278
        if ($query->sortClauses !== null) {
279
            if (!is_array($query->sortClauses)) {
280
                throw new InvalidArgumentValue('query->sortClauses', $query->sortClauses, 'Query');
281
            }
282
283
            foreach ($query->sortClauses as $sortClause) {
284
                if (!$sortClause instanceof SortClause) {
285
                    throw new InvalidArgumentValue('query->sortClauses', 'only instances of SortClause class are allowed');
286
                }
287
            }
288
        }
289
290
        if ($query->offset !== null && !is_numeric($query->offset)) {
291
            throw new InvalidArgumentValue('query->offset', $query->offset, 'Query');
292
        }
293
294
        if ($query->limit !== null && !is_numeric($query->limit)) {
295
            throw new InvalidArgumentValue('query->limit', $query->limit, 'Query');
296
        }
297
298
        $spiTrashItems = $this->persistenceHandler->trashHandler()->findTrashItems(
299
            $query->filter !== null ? $query->filter : null,
300
            $query->offset !== null && $query->offset > 0 ? (int)$query->offset : 0,
301
            $query->limit !== null && $query->limit >= 1 ? (int)$query->limit : null,
302
            $query->sortClauses !== null ? $query->sortClauses : null
0 ignored issues
show
Bug introduced by
It seems like $query->sortClauses !== ...ery->sortClauses : null can also be of type array; however, eZ\Publish\SPI\Persisten...ndler::findTrashItems() does only seem to accept null|array<integer,objec...tent\Query\SortClause>>, 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...
303
        );
304
305
        $trashItems = array();
306
        foreach ($spiTrashItems as $spiTrashItem) {
307
            $trashItems[] = $this->buildDomainTrashItemObject($spiTrashItem);
308
        }
309
310
        $searchResult = new SearchResult();
0 ignored issues
show
Deprecated Code introduced by
The class eZ\Publish\API\Repositor...es\Content\SearchResult has been deprecated with message: This class is returned by find methods providing a result of a search.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
311
        $searchResult->count = count($trashItems);
312
        $searchResult->items = $trashItems;
313
        $searchResult->query = $query;
314
315
        return $searchResult;
316
    }
317
318
    /**
319
     * Builds the domain TrashItem object from provided persistence trash item.
320
     *
321
     * @param \eZ\Publish\SPI\Persistence\Content\Location\Trashed $spiTrashItem
322
     *
323
     * @return \eZ\Publish\API\Repository\Values\Content\TrashItem
324
     */
325 View Code Duplication
    protected function buildDomainTrashItemObject(Trashed $spiTrashItem)
326
    {
327
        return new TrashItem(
328
            array(
329
                'contentInfo' => $this->repository->getContentService()->loadContentInfo($spiTrashItem->contentId),
330
                'id' => $spiTrashItem->id,
331
                'priority' => $spiTrashItem->priority,
332
                'hidden' => $spiTrashItem->hidden,
333
                'invisible' => $spiTrashItem->invisible,
334
                'remoteId' => $spiTrashItem->remoteId,
335
                'parentLocationId' => $spiTrashItem->parentId,
336
                'pathString' => $spiTrashItem->pathString,
337
                'depth' => $spiTrashItem->depth,
338
                'sortField' => $spiTrashItem->sortField,
339
                'sortOrder' => $spiTrashItem->sortOrder,
340
            )
341
        );
342
    }
343
344
    /**
345
     * @param int $timestamp
346
     *
347
     * @return \DateTime
348
     */
349
    protected function getDateTime($timestamp)
350
    {
351
        $dateTime = new DateTime();
352
        $dateTime->setTimestamp($timestamp);
353
354
        return $dateTime;
355
    }
356
}
357