GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 0681d7...5c78ad )
by Edi
01:55
created

bundle/Form/FieldTypeHandler/DateAndTime.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Netgen\Bundle\EzFormsBundle\Form\FieldTypeHandler;
6
7
use DateTime;
8
use eZ\Publish\API\Repository\Values\Content\Content;
9
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition;
10
use eZ\Publish\Core\FieldType\DateAndTime as DTValue;
11
use eZ\Publish\SPI\FieldType\Value;
12
use Netgen\Bundle\EzFormsBundle\Form\FieldTypeHandler;
13
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
14
use Symfony\Component\Form\FormBuilderInterface;
15
use Symfony\Component\Validator\Constraints as Assert;
16
17
class DateAndTime extends FieldTypeHandler
18
{
19
    public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): DateTime
20
    {
21
        return $value->value;
0 ignored issues
show
Accessing value on the interface eZ\Publish\SPI\FieldType\Value suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
22
    }
23
24
    public function convertFieldValueFromForm($data): DTValue\Value
25
    {
26
        return new DTValue\Value($data);
27
    }
28
29
    protected function buildFieldForm(
30
        FormBuilderInterface $formBuilder,
31
        FieldDefinition $fieldDefinition,
32
        string $languageCode,
33
        ?Content $content = null
34
    ): void {
35
        $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content);
36
37
        $useSeconds = $fieldDefinition->getFieldSettings()['useSeconds'];
38
        $options['input'] = 'datetime';
39
        $options['date_widget'] = 'choice';
40
        $options['time_widget'] = 'choice';
41
        $options['with_seconds'] = $useSeconds;
42
        $options['constraints'][] = new Assert\DateTime();
43
44
        $formBuilder->add($fieldDefinition->identifier, DateTimeType::class, $options);
45
    }
46
}
47