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

DateIndexNameProcessor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 86
c 0
b 0
f 0
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setField() 0 4 1
A setDateRounding() 0 4 1
A setDateFormats() 0 4 1
A setIndexNamePrefix() 0 4 1
A setIndexNameFormat() 0 4 1
A setTimezone() 0 4 1
A setLocale() 0 4 1
1
<?php
2
3
namespace Elastica\Processor;
4
5
/**
6
 * Elastica DateIndexName Processor.
7
 *
8
 * @author Federico Panini <[email protected]>
9
 *
10
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/date-index-name-processor.html
11
 * @deprecated since version 7.1.0, use the DateIndexNameProcessor class instead.
12
 */
13
class DateIndexNameProcessor extends AbstractProcessor
14
{
15
    public const DEFAULT_DATE_FORMATS_VALUE = ['ISO8601'];
16
    public const DEFAULT_INDEX_NAME_FORMAT_VALUE = 'yyyy-MM-dd';
17
    public const DEFAULT_TIMEZONE_VALUE = 'UTC';
18
    public const DEFAULT_LOCALE_VALUE = 'ENGLISH';
19
20
    /**
21
     * DateIndexName constructor.
22
     */
23
    public function __construct(string $field, string $dateRounding)
24
    {
25
        $this->setField($field);
26
        $this->setDateRounding($dateRounding);
27
    }
28
29
    /**
30
     * Set field.
31
     *
32
     * @return $this
33
     */
34
    public function setField(string $field): self
35
    {
36
        return $this->setParam('field', $field);
37
    }
38
39
    /**
40
     * Set date_rounding. Valid values are: y (year), M (month), w (week), d (day), h (hour), m (minute) and s (second).
41
     *
42
     * @return $this
43
     */
44
    public function setDateRounding(string $dateRounding): self
45
    {
46
        return $this->setParam('date_rounding', $dateRounding);
47
    }
48
49
    /**
50
     * Set field formats. Joda pattern or one of the following formats ISO8601, UNIX, UNIX_MS, or TAI64N.
51
     *
52
     * @return $this
53
     */
54
    public function setDateFormats(array $formats): self
55
    {
56
        return $this->setParam('date_formats', $formats);
57
    }
58
59
    /**
60
     * Set index_prefix_name.
61
     *
62
     * @return $this
63
     */
64
    public function setIndexNamePrefix(string $indexPrefixName): self
65
    {
66
        return $this->setParam('index_name_prefix', $indexPrefixName);
67
    }
68
69
    /**
70
     * Set format to be used when printing parsed date. An valid Joda pattern is expected here. Default yyyy-MM-dd.
71
     *
72
     * @return $this
73
     */
74
    public function setIndexNameFormat(string $indexNameFormat): self
75
    {
76
        return $this->setParam('index_name_format', $indexNameFormat);
77
    }
78
79
    /**
80
     * Set the timezone use when parsing the date. Default UTC.
81
     *
82
     * @return $this
83
     */
84
    public function setTimezone(string $timezone): self
85
    {
86
        return $this->setParam('timezone', $timezone);
87
    }
88
89
    /**
90
     * Set the locale to use when parsing the date.
91
     *
92
     * @return $this
93
     */
94
    public function setLocale(string $locale): self
95
    {
96
        return $this->setParam('locale', $locale);
97
    }
98
}
99