Passed
Push — master ( a565e0...939e78 )
by Gaetano
09:53
created

EzMatrix::hashToFieldValue()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 10
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 16
rs 9.9332
1
<?php
2
3
namespace Kaliop\eZMigrationBundle\Core\FieldHandler;
4
5
use Kaliop\eZMigrationBundle\API\FieldDefinitionConverterInterface;
6
use Kaliop\eZMigrationBundle\API\FieldValueConverterInterface;
7
8
/**
9
 * @todo make fieldSettings independent from version of ezmatrix in use, by converting them from a common format
10
 */
11
class EzMatrix extends AbstractFieldHandler implements FieldValueConverterInterface
12
{
13
    /**
14
     * @return bool
15
     */
16
    protected function usingLegacyFieldType()
17
    {
18
        return class_exists('EzSystems\MatrixBundle\FieldType\Matrix\Type');
19
    }
20
21
    public function hashToFieldValue($fieldValue, array $context = array())
22
    {
23
        /// @todo resolve refs ?
24
25
        if ($this->usingLegacyFieldType()) {
26
            $rows = array();
27
            foreach($fieldValue as $data) {
28
                $rows[] = new \EzSystems\MatrixBundle\FieldType\Matrix\Row($data);
0 ignored issues
show
Bug introduced by
The type EzSystems\MatrixBundle\FieldType\Matrix\Row was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
            }
30
            return new \EzSystems\MatrixBundle\FieldType\Matrix\Value($rows);
0 ignored issues
show
Bug introduced by
The type EzSystems\MatrixBundle\FieldType\Matrix\Value was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
        } else {
32
            $rows = array();
33
            foreach($fieldValue as $data) {
34
                $rows[] = new \EzSystems\EzPlatformMatrixFieldtype\FieldType\Value\Row($data);
0 ignored issues
show
Bug introduced by
The type EzSystems\EzPlatformMatr...ype\FieldType\Value\Row was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
            }
36
            return new \EzSystems\EzPlatformMatrixFieldtype\FieldType\Value($rows);
0 ignored issues
show
Bug introduced by
The type EzSystems\EzPlatformMatr...eldtype\FieldType\Value was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
37
        }
38
    }
39
40
    public function fieldValueToHash($fieldValue, array $context = array())
41
    {
42
        $data = array();
43
44
        if ($this->usingLegacyFieldType()) {
45
            foreach($fieldValue->getRows() as $row) {
46
                $data[] = $row->toArray();
47
            }
48
        } else {
49
            foreach($fieldValue->getRows() as $row) {
50
                $data[] = $row->getCells();
51
            }
52
        }
53
54
        return $data;
55
    }
56
}
57