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

EzAuthor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 28
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A hashToFieldValue() 0 18 5
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