Completed
Pull Request — master (#48)
by Claudio
07:27
created

TableValueFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 22
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supportedAttributeType() 0 3 1
A createByCheckingData() 0 15 4
1
<?php
2
3
namespace Flagbit\Bundle\TableAttributeBundle\Component\Product\Factory\Value;
4
5
use Akeneo\Pim\Enrichment\Component\Product\Factory\Value\ScalarValueFactory;
6
use Akeneo\Pim\Enrichment\Component\Product\Model\ValueInterface;
7
use Akeneo\Pim\Structure\Component\Query\PublicApi\AttributeType\Attribute;
8
use Akeneo\Tool\Component\StorageUtils\Exception\InvalidPropertyTypeException;
9
use Flagbit\Bundle\TableAttributeBundle\AttributeType\TableType;
10
11
final class TableValueFactory extends ScalarValueFactory
12
{
13
    public function createByCheckingData(
14
        Attribute $attribute,
15
        ?string $channelCode,
16
        ?string $localeCode,
17
        $data
18
    ): ValueInterface {
19
        if (!is_scalar($data) || (is_string($data) && '' === trim($data))) {
20
            throw InvalidPropertyTypeException::stringExpected(
21
                $attribute->code(),
22
                static::class,
23
                $data
24
            );
25
        }
26
27
        return parent::createWithoutCheckingData($attribute, $channelCode, $localeCode, $data);
28
    }
29
30
    public function supportedAttributeType(): string
31
    {
32
        return TableType::FLAGBIT_CATALOG_TABLE;
33
    }
34
}
35