Completed
Pull Request — master (#1813)
by
unknown
02:47
created

ForeachProcessor::setIgnoreMissing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Elastica\Processor;
4
5
/**
6
 * Elastica Foreach Processor.
7
 *
8
 * @author Federico Panini <[email protected]>
9
 * @author Thibaut Simon-Fine <[email protected]>
10
 *
11
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/foreach-processor.html
12
 */
13
class ForeachProcessor extends AbstractProcessor
14
{
15
    public const DEFAULT_IGNORE_MISSING_VALUE = false;
16
17
    /**
18
     * @param AbstractProcessor|array $processor
19
     */
20
    public function __construct(string $field, $processor)
21
    {
22
        $this->setField($field);
23
24
        if ($processor instanceof AbstractProcessor) {
25
            $this->setProcessor($processor);
26
        } elseif (\is_array($processor)) {
27
            $this->setRawProcessor($processor);
28
        } else {
29
            throw new \TypeError(\sprintf('Argument 2 passed to %s::__construct() must be of type %s|array, %s given.', self::class, AbstractProcessor::class, \is_object($processor) ? \get_class($processor) : \gettype($processor)));
0 ignored issues
show
Unused Code introduced by
The call to TypeError::__construct() has too many arguments starting with \sprintf('Argument 2 pas...: \gettype($processor)).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
30
        }
31
    }
32
33
    /**
34
     * Set field.
35
     *
36
     * @return $this
37
     */
38
    public function setField(string $field): self
39
    {
40
        return $this->setParam('field', $field);
41
    }
42
43
    /**
44
     * Set processor.
45
     *
46
     * @param AbstractProcessor
47
     *
48
     * @return $this
49
     */
50
    public function setProcessor(AbstractProcessor $processor): self
51
    {
52
        return $this->setParam('processor', $processor);
53
    }
54
55
    /**
56
     * Set raw processor.
57
     * Example : ['remove' => ['field' => 'user_agent']].
58
     *
59
     * @return $this
60
     */
61
    public function setRawProcessor(array $processor): self
62
    {
63
        return $this->setParam('processor', $processor);
64
    }
65
66
    /**
67
     * Set ignore_missing. Default value false.
68
     *
69
     * If true and field does not exist or is null, the processor quietly exits without modifying the document
70
     *
71
     * @return $this
72
     */
73
    public function setIgnoreMissing(bool $ignoreMissing): self
74
    {
75
        return $this->setParam('ignore_missing', $ignoreMissing);
76
    }
77
}
78