Completed
Push — master ( 0b2259...8886fc )
by Jesse
02:25
created

Observe::hydrate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\Hydrator;
5
6
abstract class Observe implements Hydrates
7
{
8
    private $hydrator;
9
    private $observer;
10
11
    private function __construct(
12
        Hydrates $hydrator,
13
        ObservesHydration $observer
14
    ) {
15
        $this->hydrator = $hydrator;
16
        $this->observer = $observer;
17
    }
18
19
    public static function hydrating(
20
        Hydrates $hydrator,
21
        ObservesHydration $observer
22
    ): Hydrates {
23
        return new static($hydrator, $observer);
24
    }
25
26
    /** @throws CannotHydrate */
27
    final protected function hydrate(object $target, array $input): void
28
    {
29
        $this->hydrator->writeTo($target, $input);
30
    }
31
32
    final protected function observe(object $target, array $input): void
33
    {
34
        $this->observer->hydrating($target, $input);
35
    }
36
}
37