Completed
Push — master ( 12f48c...b47ac0 )
by Gaetano
06:59
created

EzAuthor::createValue()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 5
eloc 9
c 3
b 0
f 0
nc 3
nop 2
dl 0
loc 18
rs 8.8571
1
<?php
2
3
namespace Kaliop\eZMigrationBundle\Core\ComplexField;
4
5
use eZ\Publish\Core\FieldType\Author\Value as AuthorValue;
6
use eZ\Publish\Core\FieldType\Author\Author;
7
use Kaliop\eZMigrationBundle\API\ComplexFieldInterface;
8
9
/**
10
 * @todo is this needed at all ?
11
 */
12
class EzAuthor extends AbstractComplexField implements ComplexFieldInterface
13
{
14
    /**
15
     * Creates a value object to use as the field value when setting an author field type.
16
     *
17
     * @param array $fieldValueArray The definition of teh field value, structured in the yml file
18
     * @param array $context The context for execution of the current migrations. Contains f.e. the path to the migration
19
     * @return AuthorValue
20
     */
21
    public function createValue(array $fieldValueArray, array $context = array())
22
    {
23
        $authors = array();
24
25
        /// @deprecated
26
        if (isset($fieldValueArray['authors'])) {
27
            foreach($fieldValueArray['authors'] as $author) {
28
                $authors[] = new Author($author);
29
            }
30
        } else if (is_array($fieldValueArray)) {
31
            /// same as what fromHash() does, really
32
            foreach($fieldValueArray as $author) {
33
                $authors[] = new Author($author);
34
            }
35
        }
36
37
        return new AuthorValue($authors);
38
    }
39
}
40