* parsing of %*% variables * * @param $filter * @return array|bool */
($filter)
| 187 | * @return array|bool |
| 188 | */ |
| 189 | private function parseFilter($filter) { |
| 190 | preg_match_all("/(?<=%).*(?=%)/", $filter, $matches); |
| 191 | if (count($matches[0]) > 0) { |
| 192 | $filter = $matches[0][0]; |
| 193 | preg_match('/(first|second|third|fourth|last|next|current|to|yester)?/', $filter, $directionMatch); // direction |
| 194 | preg_match('/[0-9]+/', $filter, $offsetMatch); // how much |
| 195 | preg_match('/(day|days|week|weeks|month|months|year|years|quarter|quarters)$/', $filter, $unitMatch); // unit |
| 196 | |
| 197 | if (!$directionMatch[0] || !$unitMatch[0]) { |
| 198 | // no known text variables found |
| 199 | return false; |
| 200 | } |
| 201 | |
| 202 | // if no offset is specified, apply 1 as default |
| 203 | !isset($offsetMatch[0]) ? $offset = 1 : $offset = $offsetMatch[0]; |
| 204 | |
| 205 | // remove "s" to unify e.g. weeks => week |
| 206 | $unit = rtrim($unitMatch[0], 's'); |
| 207 | $direction = strtolower($directionMatch[0]); |
| 208 | |
| 209 | if ($unit === 'quarter') { |
| 210 | $currentMonth = (int)date('n'); |
| 211 | $currentYear = (int)date('Y'); |
| 212 | $currentQuarter = (int)ceil($currentMonth / 3); |
| 213 | |
| 214 | $targetQuarter = $currentQuarter; |
| 215 | $targetYear = $currentYear; |
| 216 | |
| 217 | switch ($direction) { |
| 218 | case 'first': |
| 219 | $targetQuarter = 1; |
| 220 | break; |
| 221 | case 'second': |
| 222 | $targetQuarter = 2; |
| 223 | break; |
| 224 | case 'third': |
| 225 | $targetQuarter = 3; |
| 226 | break; |
| 227 | case 'fourth': |
| 228 | $targetQuarter = 4; |
| 229 | break; |
| 230 | case 'last': |
| 231 | case 'yester': |
| 232 | $targetQuarter = $currentQuarter - $offset; |
| 233 | while ($targetQuarter < 1) { |
| 234 | $targetQuarter += 4; |
| 235 | $targetYear -= 1; |
| 236 | } |
| 237 | break; |
| 238 | case 'next': |
| 239 | $targetQuarter = $currentQuarter + $offset; |
| 240 | while ($targetQuarter > 4) { |
| 241 | $targetQuarter -= 4; |
| 242 | $targetYear += 1; |
| 243 | } |
| 244 | break; |
| 245 | case 'current': |
| 246 | default: |
no outgoing calls
no test coverage detected