Code Duplication    Length = 47-49 lines in 2 locations

eZ/Publish/API/Repository/Values/Content/Query/Criterion/Ancestor.php 1 location

@@ 20-68 (lines=49) @@
17
 *
18
 * Content will be matched if it is part of at least one of the given subtree path strings.
19
 */
20
class Ancestor extends Criterion
21
{
22
    /**
23
     * Creates a new Ancestor criterion.
24
     *
25
     * @param string $value Location path string
26
     *
27
     * @throws \InvalidArgumentException if a non integer or string id is given
28
     * @throws \InvalidArgumentException if the value type doesn't match the operator
29
     */
30
    public function __construct($value)
31
    {
32
        foreach ((array)$value as $pathString) {
33
            if (preg_match('/^(\/\w+)+\/$/', $pathString) !== 1) {
34
                throw new InvalidArgumentException(
35
                    "value '$pathString' must follow the pathString format, eg /1/2/"
36
                );
37
            }
38
        }
39
40
        parent::__construct(null, null, $value);
41
    }
42
43
    public function getSpecifications()
44
    {
45
        return [
46
            new Specifications(
47
                Operator::EQ,
48
                Specifications::FORMAT_SINGLE,
49
                Specifications::TYPE_STRING
50
            ),
51
            new Specifications(
52
                Operator::IN,
53
                Specifications::FORMAT_ARRAY,
54
                Specifications::TYPE_STRING
55
            ),
56
        ];
57
    }
58
59
    /**
60
     * @deprecated since 7.2, will be removed in 8.0. Use the constructor directly instead.
61
     */
62
    public static function createFromQueryBuilder($target, $operator, $value)
63
    {
64
        @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 7.2 and will be removed in 8.0.', E_USER_DEPRECATED);
65
66
        return new self($value);
67
    }
68
}
69

eZ/Publish/API/Repository/Values/Content/Query/Criterion/Subtree.php 1 location

@@ 20-66 (lines=47) @@
17
 *
18
 * Content will be matched if it is part of at least one of the given subtree path strings
19
 */
20
class Subtree extends Criterion
21
{
22
    /**
23
     * Creates a new SubTree criterion.
24
     *
25
     * @param string|string[] $value an array of subtree path strings, eg: /1/2/
26
     *
27
     * @throws InvalidArgumentException if a non path string is given
28
     * @throws InvalidArgumentException if the value type doesn't match the operator
29
     */
30
    public function __construct($value)
31
    {
32
        foreach ((array)$value as $pathString) {
33
            if (preg_match('/^(\/\w+)+\/$/', $pathString) !== 1) {
34
                throw new InvalidArgumentException("value '$pathString' must follow the pathString format, eg /1/2/");
35
            }
36
        }
37
38
        parent::__construct(null, null, $value);
39
    }
40
41
    public function getSpecifications()
42
    {
43
        return [
44
            new Specifications(
45
                Operator::EQ,
46
                Specifications::FORMAT_SINGLE,
47
                Specifications::TYPE_STRING
48
            ),
49
            new Specifications(
50
                Operator::IN,
51
                Specifications::FORMAT_ARRAY,
52
                Specifications::TYPE_STRING
53
            ),
54
        ];
55
    }
56
57
    /**
58
     * @deprecated since 7.2, will be removed in 8.0. Use the constructor directly instead.
59
     */
60
    public static function createFromQueryBuilder($target, $operator, $value)
61
    {
62
        @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 7.2 and will be removed in 8.0.', E_USER_DEPRECATED);
63
64
        return new self($value);
65
    }
66
}
67