SimpleConverter::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 3
nc 2
nop 1
crap 3
1
<?php
2
3
namespace ExternalFeedParser\Converters;
4
5
use ExternalFeedParser\Contracts\Converter;
6
use ExternalFeedParser\Entity\ExternalEntity;
7
use InvalidArgumentException;
8
9
class SimpleConverter implements Converter
10
{
11 4
    public function __construct(
12
        protected ?string $entityClass = null
13
    ) {
14 4
        if ($entityClass && !is_a($entityClass, ExternalEntity::class, true)) {
15 1
            throw new InvalidArgumentException("External Entity has wrong class [{$entityClass}].");
16
        }
17 3
    }
18
19 3
    public function convert($data): ?ExternalEntity
20
    {
21 3
        if ($this->entityClass) {
22 2
            return new $this->entityClass((array) $data);
23
        }
24
25 1
        return new ExternalEntity((array) $data);
26
    }
27
}
28