for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Pkvs package
*
* @package Pkvs
* @author Peter Gribanov <[email protected]>
*/
namespace GpsLab\Component\Interval\Persistence\Doctrine\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\TextType;
use GpsLab\Component\Interval\Exception\InvalidIntervalFormatException;
use GpsLab\Component\Interval\IntervalInterface;
abstract class BaseType extends TextType
{
* @param IntervalInterface|null $value
* @param AbstractPlatform $platform
* @return null|string
public function convertToDatabaseValue($value, AbstractPlatform $platform)
$class = $this->getIntervalClass();
return $value instanceof $class ? (string)$value : null;
}
* @throws ConversionException
* @param mixed $value
* @return null|IntervalInterface
public function convertToPHPValue($value, AbstractPlatform $platform)
if ($value === null) {
return null;
try {
return call_user_func([$this->getIntervalClass(), 'fromString'], $value);
} catch (InvalidIntervalFormatException $e) {
throw ConversionException::conversionFailed($value, $this->getName());
* @return string
public function getName()
return basename($this->getIntervalClass());
abstract protected function getIntervalClass();