Total Complexity | 6 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | class EntityPatcher { |
||
17 | |||
18 | /** |
||
19 | * @var EntityPatcherStrategy[] |
||
20 | */ |
||
21 | private $patcherStrategies; |
||
22 | |||
23 | 3 | public function __construct() { |
|
24 | 3 | $this->registerEntityPatcherStrategy( new ItemPatcher() ); |
|
25 | 3 | $this->registerEntityPatcherStrategy( new PropertyPatcher() ); |
|
26 | 3 | } |
|
27 | |||
28 | 3 | public function registerEntityPatcherStrategy( EntityPatcherStrategy $patcherStrategy ) { |
|
29 | 3 | $this->patcherStrategies[] = $patcherStrategy; |
|
30 | 3 | } |
|
31 | |||
32 | /** |
||
33 | * @param EntityDocument $entity |
||
34 | * @param EntityDiff $patch |
||
35 | * |
||
36 | * @throws InvalidArgumentException |
||
37 | * @throws RuntimeException |
||
38 | */ |
||
39 | 3 | public function patchEntity( EntityDocument $entity, EntityDiff $patch ) { |
|
40 | 3 | $this->getPatcherStrategy( $entity->getType() )->patchEntity( $entity, $patch ); |
|
41 | 2 | } |
|
42 | |||
43 | /** |
||
44 | * @param string $entityType |
||
45 | * |
||
46 | * @throws RuntimeException |
||
47 | * @return EntityPatcherStrategy |
||
48 | */ |
||
49 | 3 | private function getPatcherStrategy( $entityType ) { |
|
57 | } |
||
58 | |||
59 | } |
||
60 |