SimpleConverter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 6
c 1
b 0
f 0
dl 0
loc 17
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A convert() 0 7 2
A __construct() 0 5 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