From 2dec5618a638fb082f168e5c21e4b3a19c3b06fd Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 23 Mar 2018 12:33:50 +0100 Subject: [PATCH] =?UTF-8?q?DateTime:=20added=20immutable=20usage=20detecto?= =?UTF-8?q?r=E2=84=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Dibi/DateTime.php | 60 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/Dibi/DateTime.php b/src/Dibi/DateTime.php index c582cb02..d80a31a1 100644 --- a/src/Dibi/DateTime.php +++ b/src/Dibi/DateTime.php @@ -43,4 +43,64 @@ class DateTime extends \DateTimeImmutable { return $this->format('Y-m-d H:i:s.u'); } + + + /********************* immutable usage detector ****************d*g**/ + + + public function __destruct() + { + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); + if (isset($trace[0]['file'], $trace[1]['function']) && $trace[0]['file'] === __FILE__ && $trace[1]['function'] !== '__construct') { + trigger_error(__CLASS__ . ' is immutable now, check how it is used in ' . $trace[1]['file'] . ':' . $trace[1]['line'], E_USER_WARNING); + } + } + + + public function add($interval) + { + return parent::add($interval); + } + + + public function modify($modify) + { + return parent::modify($modify); + } + + + public function setDate($year, $month, $day) + { + return parent::setDate($year, $month, $day); + } + + + public function setISODate($year, $week, $day = 1) + { + return parent::setISODate($year, $week, $day); + } + + + public function setTime($hour, $minute, $second = 0, $micro = 0) + { + return parent::setTime($hour, $minute, $second, $micro); + } + + + public function setTimestamp($unixtimestamp) + { + return parent::setTimestamp($unixtimestamp); + } + + + public function setTimezone($timezone) + { + return parent::setTimezone($timezone); + } + + + public function sub($interval) + { + return parent::sub($interval); + } }