1 | <?php |
||||
2 | |||||
3 | /* |
||||
4 | * @copyright 2018 Mautic Contributors. All rights reserved |
||||
5 | * @author Mautic |
||||
6 | * |
||||
7 | * @link http://mautic.org |
||||
8 | * |
||||
9 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||||
10 | */ |
||||
11 | |||||
12 | namespace Mautic\LeadBundle\Segment\Decorator\Date; |
||||
13 | |||||
14 | use Mautic\LeadBundle\Segment\ContactSegmentFilterCrate; |
||||
15 | use Mautic\LeadBundle\Segment\Decorator\Date\Day\DateDayToday; |
||||
16 | use Mautic\LeadBundle\Segment\Decorator\Date\Day\DateDayTomorrow; |
||||
17 | use Mautic\LeadBundle\Segment\Decorator\Date\Day\DateDayYesterday; |
||||
18 | use Mautic\LeadBundle\Segment\Decorator\Date\Month\DateMonthLast; |
||||
19 | use Mautic\LeadBundle\Segment\Decorator\Date\Month\DateMonthNext; |
||||
20 | use Mautic\LeadBundle\Segment\Decorator\Date\Month\DateMonthThis; |
||||
21 | use Mautic\LeadBundle\Segment\Decorator\Date\Other\DateAnniversary; |
||||
22 | use Mautic\LeadBundle\Segment\Decorator\Date\Other\DateDefault; |
||||
23 | use Mautic\LeadBundle\Segment\Decorator\Date\Other\DateRelativeInterval; |
||||
24 | use Mautic\LeadBundle\Segment\Decorator\Date\Week\DateWeekLast; |
||||
25 | use Mautic\LeadBundle\Segment\Decorator\Date\Week\DateWeekNext; |
||||
26 | use Mautic\LeadBundle\Segment\Decorator\Date\Week\DateWeekThis; |
||||
27 | use Mautic\LeadBundle\Segment\Decorator\Date\Year\DateYearLast; |
||||
28 | use Mautic\LeadBundle\Segment\Decorator\Date\Year\DateYearNext; |
||||
29 | use Mautic\LeadBundle\Segment\Decorator\Date\Year\DateYearThis; |
||||
30 | use Mautic\LeadBundle\Segment\Decorator\DateDecorator; |
||||
31 | use Mautic\LeadBundle\Segment\Decorator\FilterDecoratorInterface; |
||||
32 | use Mautic\LeadBundle\Segment\RelativeDate; |
||||
33 | |||||
34 | class DateOptionFactory |
||||
35 | { |
||||
36 | /** |
||||
37 | * @var DateDecorator |
||||
38 | */ |
||||
39 | private $dateDecorator; |
||||
40 | |||||
41 | /** |
||||
42 | * @var RelativeDate |
||||
43 | */ |
||||
44 | private $relativeDate; |
||||
45 | |||||
46 | /** |
||||
47 | * @var TimezoneResolver |
||||
48 | */ |
||||
49 | private $timezoneResolver; |
||||
50 | |||||
51 | public function __construct( |
||||
52 | DateDecorator $dateDecorator, |
||||
53 | RelativeDate $relativeDate, |
||||
54 | TimezoneResolver $timezoneResolver |
||||
55 | ) { |
||||
56 | $this->dateDecorator = $dateDecorator; |
||||
57 | $this->relativeDate = $relativeDate; |
||||
58 | $this->timezoneResolver = $timezoneResolver; |
||||
59 | } |
||||
60 | |||||
61 | /** |
||||
62 | * @return FilterDecoratorInterface |
||||
63 | */ |
||||
64 | public function getDateOption(ContactSegmentFilterCrate $leadSegmentFilterCrate) |
||||
65 | { |
||||
66 | $originalValue = $leadSegmentFilterCrate->getFilter(); |
||||
67 | $relativeDateStrings = $this->relativeDate->getRelativeDateStrings(); |
||||
68 | |||||
69 | $dateOptionParameters = new DateOptionParameters($leadSegmentFilterCrate, $relativeDateStrings, $this->timezoneResolver); |
||||
70 | |||||
71 | $timeframe = $dateOptionParameters->getTimeframe(); |
||||
72 | |||||
73 | if (!$timeframe) { |
||||
74 | return new DateDefault($this->dateDecorator, $originalValue); |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
75 | } |
||||
76 | |||||
77 | switch ($timeframe) { |
||||
78 | case 'birthday': |
||||
79 | case 'anniversary': |
||||
80 | case $timeframe && ( |
||||
81 | false !== strpos($timeframe, 'anniversary') || |
||||
82 | false !== strpos($timeframe, 'birthday') |
||||
83 | ): |
||||
84 | return new DateAnniversary($this->dateDecorator, $dateOptionParameters); |
||||
85 | case 'today': |
||||
86 | return new DateDayToday($this->dateDecorator, $dateOptionParameters); |
||||
87 | case 'tomorrow': |
||||
88 | return new DateDayTomorrow($this->dateDecorator, $dateOptionParameters); |
||||
89 | case 'yesterday': |
||||
90 | return new DateDayYesterday($this->dateDecorator, $dateOptionParameters); |
||||
91 | case 'week_last': |
||||
92 | return new DateWeekLast($this->dateDecorator, $dateOptionParameters); |
||||
93 | case 'week_next': |
||||
94 | return new DateWeekNext($this->dateDecorator, $dateOptionParameters); |
||||
95 | case 'week_this': |
||||
96 | return new DateWeekThis($this->dateDecorator, $dateOptionParameters); |
||||
97 | case 'month_last': |
||||
98 | return new DateMonthLast($this->dateDecorator, $dateOptionParameters); |
||||
99 | case 'month_next': |
||||
100 | return new DateMonthNext($this->dateDecorator, $dateOptionParameters); |
||||
101 | case 'month_this': |
||||
102 | return new DateMonthThis($this->dateDecorator, $dateOptionParameters); |
||||
103 | case 'year_last': |
||||
104 | return new DateYearLast($this->dateDecorator, $dateOptionParameters); |
||||
105 | case 'year_next': |
||||
106 | return new DateYearNext($this->dateDecorator, $dateOptionParameters); |
||||
107 | case 'year_this': |
||||
108 | return new DateYearThis($this->dateDecorator, $dateOptionParameters); |
||||
109 | case $timeframe && ( |
||||
110 | false !== strpos($timeframe[0], '-') || // -5 days |
||||
111 | false !== strpos($timeframe[0], '+') || // +5 days |
||||
112 | false !== strpos($timeframe, ' ago') // 5 days ago |
||||
113 | ): |
||||
114 | return new DateRelativeInterval($this->dateDecorator, $originalValue, $dateOptionParameters); |
||||
0 ignored issues
–
show
It seems like
$originalValue can also be of type array ; however, parameter $originalValue of Mautic\LeadBundle\Segmen...Interval::__construct() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
115 | default: |
||||
116 | return new DateDefault($this->dateDecorator, $originalValue); |
||||
117 | } |
||||
118 | } |
||||
119 | } |
||||
120 |