Completed
Branch master (e35419)
by Gaetano
06:40
created

EzAuthor::hashToFieldValue()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5.5069

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 3
nop 2
dl 0
loc 19
ccs 8
cts 11
cp 0.7272
crap 5.5069
rs 9.6111
c 0
b 0
f 0
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 1
    public function hashToFieldValue($fieldValue, array $context = array())
22
    {
23 1
        $authors = array();
24
25
        /// @deprecated
26 1
        if (isset($fieldValue['authors'])) {
27
            foreach ($fieldValue['authors'] as $author) {
28
                $author = $this->referenceResolver->resolveReference($author);
29
                $authors[] = new Author($author);
30
            }
31 1
        } else if (is_array($fieldValue)) {
32
            /// same as what fromHash() does, really
33 1
            foreach ($fieldValue as $author) {
34 1
                $author = $this->referenceResolver->resolveReference($author);
35 1
                $authors[] = new Author($author);
36
            }
37
        }
38
39 1
        return new AuthorValue($authors);
40
    }
41
}
42