Completed
Push — master ( 5a501b...3982a6 )
by Gaetano
08:04
created

EzAuthor::hashToFieldValue()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 14
cp 0
rs 9.3554
c 0
b 0
f 0
cc 5
nc 3
nop 2
crap 30
1
<?php
2
3
namespace Kaliop\eZMigrationBundle\Core\FieldHandler;
4
5
use eZ\Publish\Core\FieldType\Author\Value as AuthorValue;
6
use eZ\Publish\Core\FieldType\Author\Author;
7
use Kaliop\eZMigrationBundle\API\FieldValueImporterInterface;
8
9
/**
10
 * @todo is this needed at all ?
11
 */
12
class EzAuthor extends AbstractFieldHandler implements FieldValueImporterInterface
13
{
14
    /**
15
     * Creates a value object to use as the field value when setting an author field type.
16
     *
17
     * @param array $fieldValue The definition of the 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 hashToFieldValue($fieldValue, array $context = array())
22
    {
23
        $authors = array();
24
25
        /// @deprecated
26
        if (isset($fieldValue['authors'])) {
27
            foreach ($fieldValue['authors'] as $author) {
28
                $authors[] = new Author($author);
29
            }
30
        } else if (is_array($fieldValue)) {
31
            /// same as what fromHash() does, really
32
            foreach ($fieldValue as $author) {
33
                $authors[] = new Author($author);
34
            }
35
        }
36
37
        return new AuthorValue($authors);
38
    }
39
}
40