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 eZ\Publish\API\Repository\Values\Content\Content; |
||
8 | use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition; |
||
9 | use eZ\Publish\Core\FieldType\ISBN\Value as IsbnValue; |
||
10 | use eZ\Publish\SPI\FieldType\Value; |
||
11 | use Netgen\Bundle\EzFormsBundle\Form\FieldTypeHandler; |
||
12 | use Symfony\Component\Form\Extension\Core\Type\TextType; |
||
13 | use Symfony\Component\Form\FormBuilderInterface; |
||
14 | use Symfony\Component\Validator\Constraints; |
||
15 | |||
16 | class Isbn extends FieldTypeHandler |
||
17 | { |
||
18 | public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): string |
||
19 | { |
||
20 | return $value->isbn; |
||
0 ignored issues
–
show
|
|||
21 | } |
||
22 | |||
23 | public function convertFieldValueFromForm($data): IsbnValue |
||
24 | { |
||
25 | if (empty($data)) { |
||
26 | $data = ''; |
||
27 | } |
||
28 | |||
29 | return new IsbnValue($data); |
||
30 | } |
||
31 | |||
32 | protected function buildFieldForm( |
||
33 | FormBuilderInterface $formBuilder, |
||
34 | FieldDefinition $fieldDefinition, |
||
35 | string $languageCode, |
||
36 | ?Content $content = null |
||
37 | ): void { |
||
38 | $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); |
||
39 | |||
40 | if ($fieldDefinition->fieldSettings['isISBN13']) { |
||
41 | $options['constraints'][] = new Constraints\Isbn( |
||
42 | [ |
||
43 | 'type' => 'isbn13', |
||
44 | ] |
||
45 | ); |
||
46 | } else { |
||
47 | $options['constraints'][] = new Constraints\Isbn(); |
||
48 | } |
||
49 | |||
50 | $formBuilder->add($fieldDefinition->identifier, TextType::class, $options); |
||
51 | } |
||
52 | } |
||
53 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: