Resource   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 6
dl 0
loc 32
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 4 1
A hydrate() 0 10 4
A append() 0 4 1
1
<?php
2
3
namespace Shrikeh\PagerDuty\Hydrator\ContactMethod;
4
5
use stdClass;
6
use IteratorIterator;
7
use Shrikeh\PagerDuty\Hydrator;
8
use Shrikeh\PagerDuty\Collection;
9
use Shrikeh\Collection\NamedConstructorsTrait;
10
use Shrikeh\Collection\ObjectStorageTrait;
11
use Shrikeh\Collection\ImmutableCollectionTrait;
12
use Shrikeh\Collection\ClosedOuterIteratorTrait;
13
use Shrikeh\Collection\OuterIteratorTrait;
14
use Shrikeh\PagerDuty\Collection\Traits\ThrowImmutable;
15
16
class Resource extends IteratorIterator implements Collection, Hydrator
17
{
18
    use NamedConstructorsTrait;
19
    use ObjectStorageTrait;
20
    use ImmutableCollectionTrait;
21
    use ClosedOuterIteratorTrait;
22
    use OuterIteratorTrait;
23
    use ThrowImmutable {
24
        ThrowImmutable::throwImmutable insteadof ImmutableCollectionTrait;
25
    }
26
27
    public function hydrate(stdClass $dto)
28
    {
29
        if (isset($dto->type)) {
30
            foreach ($this->getStorage() as $hydrator) {
31
                if ($hydrator->supports($dto->type)) {
32
                    return $hydrator->hydrate($dto);
33
                }
34
            }
35
        }
36
    }
37
38
    public function supports($token)
39
    {
40
        return 'type' === $token;
41
    }
42
43
    protected function append(Hydrator $hydrator)
44
    {
45
        $this->getStorage()->attach($hydrator);
46
    }
47
}
48