* parsing of %*% variables * * @param $filter * @return array|bool */
($filter)
| 208 | * @return array|bool |
| 209 | */ |
| 210 | private function parseFilter($filter) { |
| 211 | preg_match_all("/(?<=%).*(?=%)/", $filter, $matches); |
| 212 | if (count($matches[0]) > 0) { |
| 213 | $filter = $matches[0][0]; |
| 214 | preg_match('/(first|second|third|fourth|last|next|current|to|yester)?/', $filter, $directionMatch); // direction |
| 215 | preg_match('/[0-9]+/', $filter, $offsetMatch); // how much |
| 216 | preg_match('/(day|days|week|weeks|month|months|year|years|quarter|quarters)$/', $filter, $unitMatch); // unit |
| 217 | |
| 218 | if (!$directionMatch[0] || !$unitMatch[0]) { |
| 219 | // no known text variables found |
| 220 | return false; |
| 221 | } |
| 222 | |
| 223 | // if no offset is specified, apply 1 as default |
| 224 | !isset($offsetMatch[0]) ? $offset = 1 : $offset = $offsetMatch[0]; |
| 225 | |
| 226 | // remove "s" to unify e.g. weeks => week |
| 227 | $unit = rtrim($unitMatch[0], 's'); |
| 228 | $direction = strtolower($directionMatch[0]); |
| 229 | |
| 230 | if ($unit === 'quarter') { |
| 231 | $currentMonth = (int)date('n'); |
| 232 | $currentYear = (int)date('Y'); |
| 233 | $currentQuarter = (int)ceil($currentMonth / 3); |
| 234 | |
| 235 | $targetQuarter = $currentQuarter; |
| 236 | $targetYear = $currentYear; |
| 237 | |
| 238 | switch ($direction) { |
| 239 | case 'first': |
| 240 | $targetQuarter = 1; |
| 241 | break; |
| 242 | case 'second': |
| 243 | $targetQuarter = 2; |
| 244 | break; |
| 245 | case 'third': |
| 246 | $targetQuarter = 3; |
| 247 | break; |
| 248 | case 'fourth': |
| 249 | $targetQuarter = 4; |
| 250 | break; |
| 251 | case 'last': |
| 252 | case 'yester': |
| 253 | $targetQuarter = $currentQuarter - $offset; |
| 254 | while ($targetQuarter < 1) { |
| 255 | $targetQuarter += 4; |
| 256 | $targetYear -= 1; |
| 257 | } |
| 258 | break; |
| 259 | case 'next': |
| 260 | $targetQuarter = $currentQuarter + $offset; |
| 261 | while ($targetQuarter > 4) { |
| 262 | $targetQuarter -= 4; |
| 263 | $targetYear += 1; |
| 264 | } |
| 265 | break; |
| 266 | case 'current': |
| 267 | default: |
no outgoing calls
no test coverage detected