| Total Complexity | 20 | 
| Total Lines | 38 | 
| Duplicated Lines | 0 % | 
| Changes | 2 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php | ||
| 4 | class DateInjector { | ||
| 5 | private $processCache; | ||
| 6 | |||
| 7 | 	public function replaceDates($obj, $reset = true) { | ||
| 8 | //prevent infinite recursion, only process each object once | ||
| 9 | if ($this->checkCache($obj, $reset)) return $obj; | ||
| 10 | |||
| 11 | if ($this->isIterable($obj)) foreach ($obj as &$o) $o = $this->replaceDates($o, false); | ||
| 12 | if ($this->isPossiblyDateString($obj)) $obj = $this->tryToGetDateObjFromString($obj); | ||
| 13 | return $obj; | ||
| 14 | } | ||
| 15 | |||
| 16 |     private function tryToGetDateObjFromString($obj) { | ||
| 17 |         try { | ||
| 18 | $date = new \DateTime($obj); | ||
| 19 |             if ($date->format('Y-m-d H:i:s') == substr($obj, 0, 20) || $date->format('Y-m-d') == substr($obj, 0, 10)) $obj = $date; | ||
| 20 | } | ||
| 21 |         catch (\Exception $e) {	//Doesn't need to do anything as the try/catch is working out whether $obj is a date | ||
| 22 | } | ||
| 23 | return $obj; | ||
| 24 | } | ||
| 25 | |||
| 26 |     private function isIterable($obj) { | ||
| 27 | return is_array($obj) || (is_object($obj) && ($obj instanceof \Iterator)); | ||
| 28 | } | ||
| 29 | |||
| 30 |     private function isPossiblyDateString($obj) { | ||
| 32 | } | ||
| 33 | |||
| 34 | 	private function checkCache($obj, $reset) { | ||
| 42 | } | ||
| 43 | } | ||
| 44 |