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
Pull Request — master (#73)
by
unknown
14:32
created

CountryFieldHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 20
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 4 1
A toString() 0 4 1
A getLegacyValue() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Netgen\InformationCollection\Core\Persistence\FieldHandler\Custom;
6
7
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition;
8
use eZ\Publish\Core\FieldType\Country\Value as CountryValue;
9
use eZ\Publish\Core\FieldType\Value;
10
use \Netgen\InformationCollection\API\FieldHandler\CustomLegacyFieldHandlerInterface;
11
use Netgen\InformationCollection\API\Value\Legacy\FieldValue;
12
13
/**
14
 * Overrides the original country handler to save country alpha2 code to collected info
15
 * attribute instead of the country name.
16
 */
17
final class CountryFieldHandler implements CustomLegacyFieldHandlerInterface
18
{
19
    public function supports(Value $value): bool
20
    {
21
        return $value instanceof CountryValue;
22
    }
23
24
    public function toString(Value $value, FieldDefinition $fieldDefinition): string
25
    {
26
        return (string)$value;
27
    }
28
29
    /**
30
     * @param \eZ\Publish\Core\FieldType\Country\Value $value
31
     */
32
    public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition): FieldValue
33
    {
34
        return FieldValue::withStringValue($fieldDefinition->id, implode(', ', array_column($value->countries, 'Alpha2')));
35
    }
36
}
37