Completed
Push — develop ( 515643...e2e58e )
by
unknown
08:08
created

HydratorStrategyAwareTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setHydrator() 0 8 1
B injectHydratorStrategies() 0 13 5
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2017 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Core\Form;
12
13
use Core\Form\Hydrator\HydratorStrategyProviderInterface;
14
use Zend\Hydrator\HydratorInterface;
15
use Zend\Hydrator\StrategyEnabledInterface;
16
17
/**
18
 * ${CARET}
19
 * 
20
 * @author Mathias Gelhausen <[email protected]>
21
 * @todo write test 
22
 */
23
trait HydratorStrategyAwareTrait
24
{
25
26
    public function setHydrator(HydratorInterface $hydrator)
27
    {
28
        $this->injectHydratorStrategies($hydrator);
29
30
        /** @noinspection PhpUndefinedClassInspection */
31
        /** @noinspection PhpUndefinedMethodInspection */
32
        return parent::setHydrator($hydrator);
33
    }
34
35
    protected function injectHydratorStrategies(HydratorInterface $hydrator)
36
    {
37
        if ($hydrator instanceOf StrategyEnabledInterface) {
38
            foreach ($this as $name => $elementOrFieldset) {
0 ignored issues
show
Bug introduced by
The expression $this of type this<Core\Form\HydratorStrategyAwareTrait> is not traversable.
Loading history...
39
                if ($elementOrFieldset instanceOf HydratorStrategyProviderInterface
40
                    && !$hydrator->hasStrategy($name)
41
                ) {
42
                    $hydrator->addStrategy($name, $elementOrFieldset->getHydratorStrategy());
43
                }
44
            }
45
        }
46
47
    }
48
    
49
}