Completed
Pull Request — master (#1893)
by
unknown
03:34
created

DateProcessor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 65
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setField() 0 4 1
A setFormats() 0 4 1
A setTargetField() 0 4 1
A setTimezone() 0 4 1
A setLocale() 0 4 1
1
<?php
2
3
namespace Elastica\Processor;
4
5
/**
6
 * Elastica Date Processor.
7
 *
8
 * @author Federico Panini <[email protected]>
9
 *
10
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/date-processor.html
11
 */
12
class DateProcessor extends AbstractProcessor
13
{
14
    public const DEFAULT_TARGET_FIELD_VALUE = '@timestamp';
15
    public const DEFAULT_TIMEZONE_VALUE = 'UTC';
16
    public const DEFAULT_LOCALE_VALUE = 'ENGLISH';
17
18
    /**
19
     * Date constructor.
20
     */
21
    public function __construct(string $field, array $formats)
22
    {
23
        $this->setField($field);
24
        $this->setFormats($formats);
25
    }
26
27
    /**
28
     * Set field.
29
     *
30
     * @return $this
31
     */
32
    public function setField(string $field): self
33
    {
34
        return $this->setParam('field', $field);
35
    }
36
37
    /**
38
     * Set field format. Joda pattern or one of the following formats ISO8601, UNIX, UNIX_MS, or TAI64N.
39
     *
40
     * @return $this
41
     */
42
    public function setFormats(array $formats): self
43
    {
44
        return $this->setParam('formats', $formats);
45
    }
46
47
    /**
48
     * Set target_field. Default value @timestamp.
49
     *
50
     * @return $this
51
     */
52
    public function setTargetField(string $targetField): self
53
    {
54
        return $this->setParam('target_field', $targetField);
55
    }
56
57
    /**
58
     * Set the timezone use when parsing the date. Default UTC.
59
     *
60
     * @return $this
61
     */
62
    public function setTimezone(string $timezone): self
63
    {
64
        return $this->setParam('timezone', $timezone);
65
    }
66
67
    /**
68
     * Set the locale to use when parsing the date.
69
     *
70
     * @return $this
71
     */
72
    public function setLocale(string $locale): self
73
    {
74
        return $this->setParam('locale', $locale);
75
    }
76
}
77