Completed
Push — ezp-30928-as_a_developer_i_wan... ( 4d81da...f06b29 )
by
unknown
14:36
created

Ancestor::createFromQueryBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 6
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the eZ Publish Kernel package.
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\API\Repository\Values\Content\Query\Criterion;
10
11
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
12
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications;
13
use InvalidArgumentException;
14
15
/**
16
 * A criterion that matches content that is ancestor to the given Location path string.
17
 *
18
 * Content will be matched if it is part of at least one of the given subtree path strings.
19
 */
20 View Code Duplication
class Ancestor extends Criterion
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
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);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
65
66
        return new self($value);
67
    }
68
}
69