for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Component\Grid\FieldTypes;
use Sylius\Component\Grid\DataExtractor\DataExtractorInterface;
use Sylius\Component\Grid\Definition\Field;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Webmozart\Assert\Assert;
/**
* @author Mateusz Zalewski <[email protected]>
final class DatetimeFieldType implements FieldTypeInterface
{
* @var DataExtractorInterface
private $dataExtractor;
* @param DataExtractorInterface $dataExtractor
public function __construct(DataExtractorInterface $dataExtractor)
$this->dataExtractor = $dataExtractor;
}
* {@inheritdoc}
public function render(Field $field, $data, array $options)
$value = $this->dataExtractor->get($field, $data);
if (null === $value) {
return null;
Assert::isInstanceOf($value, \DateTime::class);
return $value->format($options['format']);
public function configureOptions(OptionsResolver $resolver)
$resolver->setDefaults([
'format' => 'Y:m:d H:i:s'
]);
$resolver->setAllowedTypes([
array('format' => 'string')
array<string,string,{"format":"string"}>
string
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
'format' => 'string'
public function getName()
return 'datetime';
public function getBlockPrefix()
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: