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

Isbn   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 5
dl 0
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A convertFieldValueToForm() 0 4 1
A convertFieldValueFromForm() 0 8 2
A buildFieldForm() 0 20 2
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
Bug introduced by
Accessing isbn 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...
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