/** * @return Timestamp * Emulates PostgreSQL's date_trunc() function **/ public function truncate(Date $time, $ceil = false) { $time = $time->toTimestamp(); $function = $ceil ? 'ceil' : 'floor'; if ($this->seconds) { if ($this->seconds < 1) { return $time->spawn(); } $truncated = (int) ($function($time->toStamp() / $this->seconds) * $this->seconds); return Timestamp::create($truncated); } elseif ($this->days) { $epochStartTruncated = Date::create('1970-01-05'); $truncatedDate = Date::create($time->toDate()); if ($ceil && $truncatedDate->toStamp() < $time->toStamp()) { $truncatedDate->modify('+1 day'); } $difference = Date::dayDifference($epochStartTruncated, $truncatedDate); $truncated = (int) ($function($difference / $this->days) * $this->days); return Timestamp::create($epochStartTruncated->spawn($truncated . ' days')->toStamp()); } elseif ($this->months) { $monthsCount = $time->getYear() * 12 + ($time->getMonth() - 1); if ($ceil && $time->getDay() - 1 + $time->getHour() + $time->getMinute() + $time->getSecond() > 0) { $monthsCount += 0.1; } // delta $truncated = (int) ($function($monthsCount / $this->months) * $this->months); $months = $truncated % 12; $years = ($truncated - $months) / 12; Assert::isEqual($years, (int) $years); $years = (int) $years; $months = $months + 1; return Timestamp::create("{$years}-{$months}-01 00:00:00"); } Assert::isUnreachable(); }
public function toSetter(MetaClass $class, MetaClassProperty $property, MetaClassProperty $holder = null) { $name = $property->getName(); $methodName = 'set' . ucfirst($name); $default = $property->isRequired() ? '' : ' = null'; if ($holder) { Assert::isUnreachable(); } else { return <<<EOT /** * @return {$class->getName()} **/ public function {$methodName}(array \${$name}{$default}) { \t\$this->{$name} = \${$name}; \treturn \$this; } EOT; } Assert::isUnreachable(); }
public function importValue($value) { Assert::isUnreachable('No import value!'); return $this; }
/** * @return CustomizableDaoSynchronizer **/ public function run() { $masterIterator = new DaoIterator(); $slaveIterator = new DaoIterator(); $masterIterator->setDao($this->master); $slaveIterator->setDao($this->slave); if ($this->masterKeyProperty) { $masterIterator->setKeyProperty($this->masterKeyProperty); } if ($this->slaveKeyProperty) { $slaveIterator->setKeyProperty($this->slaveKeyProperty); } if ($this->masterProjection) { $masterIterator->setProjection($this->masterProjection); } if ($this->slaveProjection) { $slaveIterator->setProjection($this->slaveProjection); } $this->totalDeleted = 0; $this->totalInserted = 0; $this->totalUpdated = 0; while ($masterIterator->valid() || $slaveIterator->valid()) { $masterObject = $masterIterator->current(); $slaveObject = $slaveIterator->current(); $masterObject = $this->convertMasterObjectToSlave($masterObject); $masterGetter = 'get' . ucfirst($this->masterKeyProperty); $slaveGetter = 'get' . ucfirst($this->slaveKeyProperty); if ($masterObject && $slaveObject && $masterObject->{$masterGetter}() == $slaveObject->{$slaveGetter}()) { if ($this->sync($slaveObject, $masterObject)) { $this->totalUpdated++; } $masterIterator->next(); $slaveIterator->next(); } elseif (!$masterObject || $slaveObject && $this->compareKeys($masterObject->{$masterGetter}(), $slaveObject->{$slaveGetter}()) > 0) { if ($this->delete($slaveObject)) { $this->totalDeleted++; } $slaveIterator->next(); } elseif (!$slaveObject || $masterObject && $this->compareKeys($masterObject->{$masterGetter}(), $slaveObject->{$slaveGetter}()) < 0) { if ($this->insert($masterObject)) { $this->totalInserted++; } $masterIterator->next(); } else { Assert::isUnreachable('how did you get here?'); } } return $this; }
/** * @thows WrongArgumentException * @return AMQPInterface */ protected function getCurrentItem() { if ($this->current && $this->pool[$this->current]->isAlive()) { return $this->pool[$this->current]; } Assert::isUnreachable("no current connection"); }
/** * @return MetaConfiguration **/ private function checkClassSanity(MetaClass $class, \ReflectionClass $info) { switch ($class->getTypeId()) { case null: break; case MetaClassType::CLASS_ABSTRACT: Assert::isTrue($info->isAbstract(), 'class ' . $info->getName() . ' expected to be abstract'); Assert::isTrue($class->getPattern() instanceof AbstractClassPattern, 'class ' . $info->getName() . ' must use AbstractClassPattern'); break; case MetaClassType::CLASS_FINAL: Assert::isTrue($info->isFinal(), 'class ' . $info->getName() . ' expected to be final'); break; case MetaClassType::CLASS_SPOOKED: default: Assert::isUnreachable(); break; } if ($public = $info->getProperties(\ReflectionProperty::IS_PUBLIC)) { Assert::isUnreachable($class->getName() . ' contains properties with evil visibility:' . "\n" . print_r($public, true)); } return $this; }