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

injectHydratorStrategies()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 6
nc 4
nop 1
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
}