Completed
Push — location_references ( 47d67d )
by
unknown
13:55
created

LimitedLocationService::loadLocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace eZ\Publish\Core\LocationReference;
6
7
use eZ\Publish\API\Repository\LocationService;
8
use eZ\Publish\API\Repository\Values\Content\Location;
9
10
/**
11
 * Limited (readonly) location service.
12
 *
13
 * @internal
14
 */
15
final class LimitedLocationService
16
{
17
    /** @var \eZ\Publish\API\Repository\LocationService */
18
    private $locationService;
19
20
    public function __construct(LocationService $locationService)
21
    {
22
        $this->locationService = $locationService;
23
    }
24
25
    public function loadLocation(int $locationId): Location
26
    {
27
        return $this->locationService->loadLocation($locationId);
28
    }
29
30
    public function loadLocationByRemoteId(string $remoteId): Location
31
    {
32
        return $this->locationService->loadLocationByRemoteId($remoteId);
33
    }
34
35
    public function loadLocationByPathString(string $path): Location
36
    {
37
        return $this->locationService->loadLocation(
38
            $this->extractIdFromPath($path)
39
        );
40
    }
41
42
    public function loadParentLocation(Location $location): Location
43
    {
44
        return $this->locationService->loadLocation($location->parentLocationId);
45
    }
46
47
    /**
48
     * Extracts location ID from path.
49
     *
50
     * @param string $path
51
     *
52
     * @return int
53
     */
54
    private function extractIdFromPath(string $path): int
55
    {
56
        $ids = explode('/', trim($path, '/'));
57
58
        return (int)end($ids);
59
    }
60
}
61