Skip to content

Commit 67e6b07

Browse files
committed
Extract AbstractPlatform::DATE_INTERVAL_UNIT_* constants into DateIntervalUnit class
1 parent 56d65cf commit 67e6b07

File tree

7 files changed

+86
-54
lines changed

7 files changed

+86
-54
lines changed

UPGRADE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Upgrade to 2.7
22

3+
## Doctrine\DBAL\Platforms\AbstractPlatform::DATE_INTERVAL_UNIT_* constants deprecated
4+
5+
``Doctrine\DBAL\Platforms\AbstractPlatform::DATE_INTERVAL_UNIT_*`` constants were moved into ``Doctrine\DBAL\Platforms\DateIntervalUnit`` class without the ``DATE_INTERVAL_UNIT_`` prefix.
6+
37
## Doctrine\DBAL\Platforms\AbstractPlatform::TRIM_* constants deprecated
48

59
``Doctrine\DBAL\Platforms\AbstractPlatform::TRIM_*`` constants were moved into ``Doctrine\DBAL\Platforms\TrimMode`` class without the ``TRIM_`` prefix.

lib/Doctrine/DBAL/Platforms/AbstractPlatform.php

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,44 +70,44 @@ abstract class AbstractPlatform
7070
const CREATE_FOREIGNKEYS = 2;
7171

7272
/**
73-
* @var string
73+
* @deprecated Use DateIntervalUnit::INTERVAL_UNIT_SECOND.
7474
*/
75-
const DATE_INTERVAL_UNIT_SECOND = 'SECOND';
75+
public const DATE_INTERVAL_UNIT_SECOND = DateIntervalUnit::SECOND;
7676

7777
/**
78-
* @var string
78+
* @deprecated Use DateIntervalUnit::MINUTE.
7979
*/
80-
const DATE_INTERVAL_UNIT_MINUTE = 'MINUTE';
80+
public const DATE_INTERVAL_UNIT_MINUTE = DateIntervalUnit::MINUTE;
8181

8282
/**
83-
* @var string
83+
* @deprecated Use DateIntervalUnit::HOUR.
8484
*/
85-
const DATE_INTERVAL_UNIT_HOUR = 'HOUR';
85+
public const DATE_INTERVAL_UNIT_HOUR = DateIntervalUnit::HOUR;
8686

8787
/**
88-
* @var string
88+
* @deprecated Use DateIntervalUnit::DAY.
8989
*/
90-
const DATE_INTERVAL_UNIT_DAY = 'DAY';
90+
public const DATE_INTERVAL_UNIT_DAY = DateIntervalUnit::DAY;
9191

9292
/**
93-
* @var string
93+
* @deprecated Use DateIntervalUnit::WEEK.
9494
*/
95-
const DATE_INTERVAL_UNIT_WEEK = 'WEEK';
95+
public const DATE_INTERVAL_UNIT_WEEK = DateIntervalUnit::WEEK;
9696

9797
/**
98-
* @var string
98+
* @deprecated Use DateIntervalUnit::MONTH.
9999
*/
100-
const DATE_INTERVAL_UNIT_MONTH = 'MONTH';
100+
public const DATE_INTERVAL_UNIT_MONTH = DateIntervalUnit::MONTH;
101101

102102
/**
103-
* @var string
103+
* @deprecated Use DateIntervalUnit::QUARTER.
104104
*/
105-
const DATE_INTERVAL_UNIT_QUARTER = 'QUARTER';
105+
public const DATE_INTERVAL_UNIT_QUARTER = DateIntervalUnit::QUARTER;
106106

107107
/**
108-
* @var string
108+
* @deprecated Use DateIntervalUnit::QUARTER.
109109
*/
110-
const DATE_INTERVAL_UNIT_YEAR = 'YEAR';
110+
public const DATE_INTERVAL_UNIT_YEAR = DateIntervalUnit::YEAR;
111111

112112
/**
113113
* @deprecated Use TrimMode::UNSPECIFIED.
@@ -1049,7 +1049,7 @@ public function getDateDiffExpression($date1, $date2)
10491049
*/
10501050
public function getDateAddSecondsExpression($date, $seconds)
10511051
{
1052-
return $this->getDateArithmeticIntervalExpression($date, '+', $seconds, self::DATE_INTERVAL_UNIT_SECOND);
1052+
return $this->getDateArithmeticIntervalExpression($date, '+', $seconds, DateIntervalUnit::SECOND);
10531053
}
10541054

10551055
/**
@@ -1064,7 +1064,7 @@ public function getDateAddSecondsExpression($date, $seconds)
10641064
*/
10651065
public function getDateSubSecondsExpression($date, $seconds)
10661066
{
1067-
return $this->getDateArithmeticIntervalExpression($date, '-', $seconds, self::DATE_INTERVAL_UNIT_SECOND);
1067+
return $this->getDateArithmeticIntervalExpression($date, '-', $seconds, DateIntervalUnit::SECOND);
10681068
}
10691069

10701070
/**
@@ -1079,7 +1079,7 @@ public function getDateSubSecondsExpression($date, $seconds)
10791079
*/
10801080
public function getDateAddMinutesExpression($date, $minutes)
10811081
{
1082-
return $this->getDateArithmeticIntervalExpression($date, '+', $minutes, self::DATE_INTERVAL_UNIT_MINUTE);
1082+
return $this->getDateArithmeticIntervalExpression($date, '+', $minutes, DateIntervalUnit::MINUTE);
10831083
}
10841084

10851085
/**
@@ -1094,7 +1094,7 @@ public function getDateAddMinutesExpression($date, $minutes)
10941094
*/
10951095
public function getDateSubMinutesExpression($date, $minutes)
10961096
{
1097-
return $this->getDateArithmeticIntervalExpression($date, '-', $minutes, self::DATE_INTERVAL_UNIT_MINUTE);
1097+
return $this->getDateArithmeticIntervalExpression($date, '-', $minutes, DateIntervalUnit::MINUTE);
10981098
}
10991099

11001100
/**
@@ -1109,7 +1109,7 @@ public function getDateSubMinutesExpression($date, $minutes)
11091109
*/
11101110
public function getDateAddHourExpression($date, $hours)
11111111
{
1112-
return $this->getDateArithmeticIntervalExpression($date, '+', $hours, self::DATE_INTERVAL_UNIT_HOUR);
1112+
return $this->getDateArithmeticIntervalExpression($date, '+', $hours, DateIntervalUnit::HOUR);
11131113
}
11141114

11151115
/**
@@ -1124,7 +1124,7 @@ public function getDateAddHourExpression($date, $hours)
11241124
*/
11251125
public function getDateSubHourExpression($date, $hours)
11261126
{
1127-
return $this->getDateArithmeticIntervalExpression($date, '-', $hours, self::DATE_INTERVAL_UNIT_HOUR);
1127+
return $this->getDateArithmeticIntervalExpression($date, '-', $hours, DateIntervalUnit::HOUR);
11281128
}
11291129

11301130
/**
@@ -1139,7 +1139,7 @@ public function getDateSubHourExpression($date, $hours)
11391139
*/
11401140
public function getDateAddDaysExpression($date, $days)
11411141
{
1142-
return $this->getDateArithmeticIntervalExpression($date, '+', $days, self::DATE_INTERVAL_UNIT_DAY);
1142+
return $this->getDateArithmeticIntervalExpression($date, '+', $days, DateIntervalUnit::DAY);
11431143
}
11441144

11451145
/**
@@ -1154,7 +1154,7 @@ public function getDateAddDaysExpression($date, $days)
11541154
*/
11551155
public function getDateSubDaysExpression($date, $days)
11561156
{
1157-
return $this->getDateArithmeticIntervalExpression($date, '-', $days, self::DATE_INTERVAL_UNIT_DAY);
1157+
return $this->getDateArithmeticIntervalExpression($date, '-', $days, DateIntervalUnit::DAY);
11581158
}
11591159

11601160
/**
@@ -1169,7 +1169,7 @@ public function getDateSubDaysExpression($date, $days)
11691169
*/
11701170
public function getDateAddWeeksExpression($date, $weeks)
11711171
{
1172-
return $this->getDateArithmeticIntervalExpression($date, '+', $weeks, self::DATE_INTERVAL_UNIT_WEEK);
1172+
return $this->getDateArithmeticIntervalExpression($date, '+', $weeks, DateIntervalUnit::WEEK);
11731173
}
11741174

11751175
/**
@@ -1184,7 +1184,7 @@ public function getDateAddWeeksExpression($date, $weeks)
11841184
*/
11851185
public function getDateSubWeeksExpression($date, $weeks)
11861186
{
1187-
return $this->getDateArithmeticIntervalExpression($date, '-', $weeks, self::DATE_INTERVAL_UNIT_WEEK);
1187+
return $this->getDateArithmeticIntervalExpression($date, '-', $weeks, DateIntervalUnit::WEEK);
11881188
}
11891189

11901190
/**
@@ -1199,7 +1199,7 @@ public function getDateSubWeeksExpression($date, $weeks)
11991199
*/
12001200
public function getDateAddMonthExpression($date, $months)
12011201
{
1202-
return $this->getDateArithmeticIntervalExpression($date, '+', $months, self::DATE_INTERVAL_UNIT_MONTH);
1202+
return $this->getDateArithmeticIntervalExpression($date, '+', $months, DateIntervalUnit::MONTH);
12031203
}
12041204

12051205
/**
@@ -1214,7 +1214,7 @@ public function getDateAddMonthExpression($date, $months)
12141214
*/
12151215
public function getDateSubMonthExpression($date, $months)
12161216
{
1217-
return $this->getDateArithmeticIntervalExpression($date, '-', $months, self::DATE_INTERVAL_UNIT_MONTH);
1217+
return $this->getDateArithmeticIntervalExpression($date, '-', $months, DateIntervalUnit::MONTH);
12181218
}
12191219

12201220
/**
@@ -1229,7 +1229,7 @@ public function getDateSubMonthExpression($date, $months)
12291229
*/
12301230
public function getDateAddQuartersExpression($date, $quarters)
12311231
{
1232-
return $this->getDateArithmeticIntervalExpression($date, '+', $quarters, self::DATE_INTERVAL_UNIT_QUARTER);
1232+
return $this->getDateArithmeticIntervalExpression($date, '+', $quarters, DateIntervalUnit::QUARTER);
12331233
}
12341234

12351235
/**
@@ -1244,7 +1244,7 @@ public function getDateAddQuartersExpression($date, $quarters)
12441244
*/
12451245
public function getDateSubQuartersExpression($date, $quarters)
12461246
{
1247-
return $this->getDateArithmeticIntervalExpression($date, '-', $quarters, self::DATE_INTERVAL_UNIT_QUARTER);
1247+
return $this->getDateArithmeticIntervalExpression($date, '-', $quarters, DateIntervalUnit::QUARTER);
12481248
}
12491249

12501250
/**
@@ -1259,7 +1259,7 @@ public function getDateSubQuartersExpression($date, $quarters)
12591259
*/
12601260
public function getDateAddYearsExpression($date, $years)
12611261
{
1262-
return $this->getDateArithmeticIntervalExpression($date, '+', $years, self::DATE_INTERVAL_UNIT_YEAR);
1262+
return $this->getDateArithmeticIntervalExpression($date, '+', $years, DateIntervalUnit::YEAR);
12631263
}
12641264

12651265
/**
@@ -1274,7 +1274,7 @@ public function getDateAddYearsExpression($date, $years)
12741274
*/
12751275
public function getDateSubYearsExpression($date, $years)
12761276
{
1277-
return $this->getDateArithmeticIntervalExpression($date, '-', $years, self::DATE_INTERVAL_UNIT_YEAR);
1277+
return $this->getDateArithmeticIntervalExpression($date, '-', $years, DateIntervalUnit::YEAR);
12781278
}
12791279

12801280
/**

lib/Doctrine/DBAL/Platforms/DB2Platform.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,14 @@ public function getBitOrComparisonExpression($value1, $value2)
193193
protected function getDateArithmeticIntervalExpression($date, $operator, $interval, $unit)
194194
{
195195
switch ($unit) {
196-
case self::DATE_INTERVAL_UNIT_WEEK:
196+
case DateIntervalUnit::WEEK:
197197
$interval *= 7;
198-
$unit = self::DATE_INTERVAL_UNIT_DAY;
198+
$unit = DateIntervalUnit::DAY;
199199
break;
200200

201-
case self::DATE_INTERVAL_UNIT_QUARTER:
201+
case DateIntervalUnit::QUARTER:
202202
$interval *= 3;
203-
$unit = self::DATE_INTERVAL_UNIT_MONTH;
203+
$unit = DateIntervalUnit::MONTH;
204204
break;
205205
}
206206

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Platforms;
6+
7+
final class DateIntervalUnit
8+
{
9+
public const SECOND = 'SECOND';
10+
11+
public const MINUTE = 'MINUTE';
12+
13+
public const HOUR = 'HOUR';
14+
15+
public const DAY = 'DAY';
16+
17+
public const WEEK = 'WEEK';
18+
19+
public const MONTH = 'MONTH';
20+
21+
public const QUARTER = 'QUARTER';
22+
23+
public const YEAR = 'YEAR';
24+
25+
private function __construct()
26+
{
27+
}
28+
}

lib/Doctrine/DBAL/Platforms/OraclePlatform.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ public function getGuidExpression()
107107
protected function getDateArithmeticIntervalExpression($date, $operator, $interval, $unit)
108108
{
109109
switch ($unit) {
110-
case self::DATE_INTERVAL_UNIT_MONTH:
111-
case self::DATE_INTERVAL_UNIT_QUARTER:
112-
case self::DATE_INTERVAL_UNIT_YEAR:
110+
case DateIntervalUnit::MONTH:
111+
case DateIntervalUnit::QUARTER:
112+
case DateIntervalUnit::YEAR:
113113
switch ($unit) {
114-
case self::DATE_INTERVAL_UNIT_QUARTER:
114+
case DateIntervalUnit::QUARTER:
115115
$interval *= 3;
116116
break;
117117

118-
case self::DATE_INTERVAL_UNIT_YEAR:
118+
case DateIntervalUnit::YEAR:
119119
$interval *= 12;
120120
break;
121121
}
@@ -126,19 +126,19 @@ protected function getDateArithmeticIntervalExpression($date, $operator, $interv
126126
$calculationClause = '';
127127

128128
switch ($unit) {
129-
case self::DATE_INTERVAL_UNIT_SECOND:
129+
case DateIntervalUnit::SECOND:
130130
$calculationClause = '/24/60/60';
131131
break;
132132

133-
case self::DATE_INTERVAL_UNIT_MINUTE:
133+
case DateIntervalUnit::MINUTE:
134134
$calculationClause = '/24/60';
135135
break;
136136

137-
case self::DATE_INTERVAL_UNIT_HOUR:
137+
case DateIntervalUnit::HOUR:
138138
$calculationClause = '/24';
139139
break;
140140

141-
case self::DATE_INTERVAL_UNIT_WEEK:
141+
case DateIntervalUnit::WEEK:
142142
$calculationClause = '*7';
143143
break;
144144
}

lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ public function getLocateExpression($str, $substr, $startPos = false)
129129
*/
130130
protected function getDateArithmeticIntervalExpression($date, $operator, $interval, $unit)
131131
{
132-
if (self::DATE_INTERVAL_UNIT_QUARTER === $unit) {
132+
if (DateIntervalUnit::QUARTER === $unit) {
133133
$interval *= 3;
134-
$unit = self::DATE_INTERVAL_UNIT_MONTH;
134+
$unit = DateIntervalUnit::MONTH;
135135
}
136136

137137
return "(" . $date ." " . $operator . " (" . $interval . " || ' " . $unit . "')::interval)";

lib/Doctrine/DBAL/Platforms/SqlitePlatform.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,21 @@ public function getLocateExpression($str, $substr, $startPos = false)
132132
protected function getDateArithmeticIntervalExpression($date, $operator, $interval, $unit)
133133
{
134134
switch ($unit) {
135-
case self::DATE_INTERVAL_UNIT_SECOND:
136-
case self::DATE_INTERVAL_UNIT_MINUTE:
137-
case self::DATE_INTERVAL_UNIT_HOUR:
135+
case DateIntervalUnit::SECOND:
136+
case DateIntervalUnit::MINUTE:
137+
case DateIntervalUnit::HOUR:
138138
return "DATETIME(" . $date . ",'" . $operator . $interval . " " . $unit . "')";
139139

140140
default:
141141
switch ($unit) {
142-
case self::DATE_INTERVAL_UNIT_WEEK:
142+
case DateIntervalUnit::WEEK:
143143
$interval *= 7;
144-
$unit = self::DATE_INTERVAL_UNIT_DAY;
144+
$unit = DateIntervalUnit::DAY;
145145
break;
146146

147-
case self::DATE_INTERVAL_UNIT_QUARTER:
147+
case DateIntervalUnit::QUARTER:
148148
$interval *= 3;
149-
$unit = self::DATE_INTERVAL_UNIT_MONTH;
149+
$unit = DateIntervalUnit::MONTH;
150150
break;
151151
}
152152

0 commit comments

Comments
 (0)