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

ForeachProcessor::setField()   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
    protected const PROCESSOR_NAME = 'foreach';
17
18
    /**
19
     * @param AbstractProcessor|array $processor
20
     */
21
    public function __construct(string $field, $processor)
22
    {
23
        $this->setField($field);
24
25
        if ($processor instanceof AbstractProcessor) {
26
            $this->setProcessor($processor);
27
        } elseif (\is_array($processor)) {
28
            $this->setRawProcessor($processor);
29
        } else {
30
            throw new \TypeError('Expected Elastica\Processor\AbstractProcessor or array');
0 ignored issues
show
Unused Code introduced by
The call to TypeError::__construct() has too many arguments starting with 'Expected Elastica\\Proc...ractProcessor or array'.

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...
31
        }
32
    }
33
34
    /**
35
     * Set field.
36
     *
37
     * @return $this
38
     */
39
    public function setField(string $field): self
40
    {
41
        return $this->setParam('field', $field);
42
    }
43
44
    /**
45
     * Set processor.
46
     *
47
     * @param AbstractProcessor
48
     *
49
     * @return $this
50
     */
51
    public function setProcessor(?AbstractProcessor $processor): self
52
    {
53
        return $this->setParam('processor', $processor);
54
    }
55
56
    /**
57
     * Set raw processor.
58
     * Example : ['remove' => ['field' => 'user_agent']].
59
     *
60
     * @return $this
61
     */
62
    public function setRawProcessor(array $processor): self
63
    {
64
        return $this->setParam('processor', $processor);
65
    }
66
67
    /**
68
     * Set ignore_missing. Default value false.
69
     *
70
     * If true and field does not exist or is null, the processor quietly exits without modifying the document
71
     *
72
     * @return $this
73
     */
74
    public function setIgnoreMissing(bool $ignoreMissing): self
75
    {
76
        return $this->setParam('ignore_missing', $ignoreMissing);
77
    }
78
79
    /**
80
     * Param's name
81
     * Picks the last part of the class name and makes it snake_case
82
     * You can override this method if you want to change the name.
83
     *
84
     * @return string name
85
     */
86
    protected function _getBaseName()
87
    {
88
        return self::PROCESSOR_NAME;
89
    }
90
}
91