Completed
Push — master ( eefbf1...ab6c28 )
by Tobias
03:54 queued 01:15
created

Hydrator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 63.64%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 33
ccs 7
cts 11
cp 0.6364
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toMessage() 0 16 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Happyr\MessageSerializer\Hydrator;
6
7
use Happyr\MessageSerializer\Hydrator\Exception\HydratorException;
8
use Happyr\MessageSerializer\Hydrator\Exception\HydratorNotFoundException;
9
10
final class Hydrator implements ArrayToMessageInterface
11
{
12
    /**
13
     * @var HydratorInterface[]
14
     */
15
    private $hydrators;
16
17 1
    public function __construct(iterable $hydrators)
18
    {
19 1
        $this->hydrators = $hydrators;
20 1
    }
21
22
    /**
23
     * @throws HydratorNotFoundException
24
     * @throws HydratorException
25
     */
26 1
    public function toMessage(array $data)
27
    {
28 1
        foreach ($this->hydrators as $hydrator) {
29 1
            if (!$hydrator->supports($data['identifier'] ?? '', $data['version'] ?? 0)) {
30
                continue;
31
            }
32
33
            try {
34 1
                return $hydrator->toMessage($data['payload'] ?? [], $data['version'] ?? 0);
35
            } catch (\Throwable $throwable) {
0 ignored issues
show
Bug introduced by
The class Throwable does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
36
                throw new HydratorException(sprintf('Transformer "%s" failed to transform a message.', get_class($hydrator)), 0, $throwable);
37
            }
38
        }
39
40
        throw new HydratorNotFoundException();
41
    }
42
}
43