Passed
Push — master ( 2fb416...eb1ffc )
by Gaetano
03:41
created

EzMatrix::hashToFieldValue()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 12
c 1
b 0
f 0
nc 6
nop 2
dl 0
loc 20
ccs 0
cts 17
cp 0
crap 56
rs 8.8333
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
            // BC with migrations which used to be valid before version 5.14 - see issue #250
28
            if (count($fieldValue) === 2 && isset($fieldValue['columns']) && isset($fieldValue['rows'])) {
29
                $fieldValue = $fieldValue['rows'];
30
            }
31
            foreach($fieldValue as $data) {
32
                $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...
33
            }
34
            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...
35
        } else {
36
            $rows = array();
37
            foreach($fieldValue as $data) {
38
                $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...
39
            }
40
            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...
41
        }
42
    }
43
44
    public function fieldValueToHash($fieldValue, array $context = array())
45
    {
46
        $data = array();
47
48
        if ($this->usingLegacyFieldType()) {
49
            foreach($fieldValue->getRows() as $row) {
50
                $data[] = $row->toArray();
51
            }
52
        } else {
53
            foreach($fieldValue->getRows() as $row) {
54
                $data[] = $row->getCells();
55
            }
56
        }
57
58
        return $data;
59
    }
60
}
61