Completed
Pull Request — master (#48)
by Claudio
10:22 queued 04:51
created

TableValueFactory::createByCheckingData()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 15
rs 10
cc 4
nc 2
nop 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