Completed
Push — ezp25003-trash_subitems_count_... ( e4ea85...5e3f64 )
by André
54:00
created

PathStringRouteBasedLimitationParser   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 3
Bugs 2 Features 0
Metric Value
dl 0
loc 20
rs 10
c 3
b 2
f 0
wmc 2
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseIdFromHref() 0 8 2
1
<?php
2
/**
3
 * @license For full copyright and license information view LICENSE file distributed with this source code.
4
 */
5
namespace eZ\Publish\Core\REST\Server\Input\Parser\Limitation;
6
7
use eZ\Publish\API\Repository\Values;
8
use eZ\Publish\Core\REST\Common\Exceptions;
9
10
/**
11
 * Generic limitation value parser.
12
 *
13
 * Instances are built with:
14
 * - The name of a route parameter, that will be searched for limitation values
15
 *   Example: "sectionId" from "/content/section/{sectionId}"
16
 * - The FQN of the limitation value object that the parser builds
17
 */
18
class PathStringRouteBasedLimitationParser extends RouteBasedLimitationParser
19
{
20
    /**
21
     * Prefixes the value parsed by the parent with a '/'.
22
     *
23
     * @throws \eZ\Publish\Core\REST\Common\Exceptions\Parser if the '_href' attribute doesn't end with a slash, since 6.4
24
     *
25
     * @param $limitationValue
26
     *
27
     * @return false|mixed
28
     */
29
    protected function parseIdFromHref($limitationValue)
30
    {
31
        if (substr($limitationValue['_href'], -1) !== '/') {
32
            throw new Exceptions\Parser("The '_href' attribute must end with a slash.");
33
        }
34
35
        return '/' . ltrim(parent::parseIdFromHref($limitationValue), '/');
36
    }
37
}
38