Completed
Push — develop ( 3af89d...cb4d39 )
by
unknown
07:47
created

JobManagerStrategy::hydrate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
rs 9.2
cc 3
eloc 14
nc 2
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 Jobs\Form\Hydrator\Strategy;
12
13
use Zend\Hydrator\Strategy\StrategyInterface;
14
15
/**
16
 * ${CARET}
17
 * 
18
 * @author Mathias Gelhausen <[email protected]>
19
 * @todo write test 
20
 */
21
class JobManagerStrategy implements StrategyInterface
22
{
23
    /**
24
     *
25
     *
26
     * @var array
27
     */
28
    private $metaData = [];
29
30
31
    public function extract($value)
32
    {
33
        $this->metaData = $value;
0 ignored issues
show
Documentation Bug introduced by
It seems like $value of type * is incompatible with the declared type array of property $metaData.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
34
35
        if (!isset($value['organizations:managers'])) { return []; }
36
37
        $ids = [];
38
        foreach ($value['organizations:managers'] as $manager) {
39
            $ids[] = $manager['id'];
40
        }
41
42
        return $ids;
43
    }
44
45
    /**
46
     * Converts the given value so that it can be hydrated by the hydrator.
47
     *
48
     * @param mixed $value The original value.
49
     * @param array $data  (optional) The original data for context.
0 ignored issues
show
Bug introduced by
There is no parameter named $data. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
50
     *
51
     * @return mixed Returns the value that should be hydrated.
52
     */
53
    public function hydrate($value)
54
    {
55
        $metaData = $this->metaData;
56
        $managers = [];
57
58
        if ('__empty__' == $value) {
59
            unset($metaData['organizations:managers']);
60
61
        } else {
62
            foreach ($value as $manager) {
63
                list($id, $name, $email) = explode('|', $manager, 3);
64
                $managers[] = [
65
                    'id' => $id,
66
                    'name' => $name,
67
                    'email' => $email,
68
                ];
69
            }
70
            $metaData['organizations:managers'] = $managers;
71
        }
72
73
        return $metaData;
74
    }
75
}