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