Passed
Push — master ( f45a11...606bf7 )
by Matthew
01:41
created

ManyHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 14
c 1
b 0
f 0
dl 0
loc 37
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handleManyRelationType() 0 18 4
1
<?php
2
3
namespace Dynamic\Salsify\TypeHandler\Relation;
4
5
use SilverStripe\Core\Extension;
6
use SilverStripe\ORM\DataObject;
7
8
/**
9
 * Class RelationHandler
10
 * @package Dynamic\Salsify\TypeHandler
11
 *
12
 * @property-read \Dynamic\Salsify\TypeHandler\Relation\ManyHandler|\Dynamic\Salsify\Model\Mapper $owner
13
 */
14
class ManyHandler extends Extension
15
{
16
    /**
17
     * @var array
18
     */
19
    private static $field_types = [
0 ignored issues
show
introduced by
The private property $field_types is not used, and could be removed.
Loading history...
20
        'ManyRelation'
21
    ];
22
23
    /**
24
     * @param $data
25
     * @param $dataField
26
     * @param $config
27
     * @param $dbField
28
     * @param string |\SilverStripe\ORM\DataObject $class
29
     *
30
     * @return int|DataObject|array
31
     * @throws \Exception
32
     */
33
    public function handleManyRelationType($data, $dataField, $config, $dbField, $class)
0 ignored issues
show
Unused Code introduced by
The parameter $class is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

33
    public function handleManyRelationType($data, $dataField, $config, $dbField, /** @scrutinizer ignore-unused */ $class)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $dbField is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

33
    public function handleManyRelationType($data, $dataField, $config, /** @scrutinizer ignore-unused */ $dbField, $class)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
    {
35
        if (!array_key_exists('relation', $config) || !is_array($config['relation'])) {
36
            return [];
37
        }
38
39
        $fieldData = $data[$dataField];
40
        $related = [];
41
42
        foreach ($fieldData as $entry) {
43
            $entryData = array_merge($data, [
44
                $dataField => $entry
45
            ]);
46
            $relationConfig = $config['relation'];
47
            $relatedClass = array_key_first($relationConfig);
48
            $related[] = $this->owner->mapToObject($relatedClass, $relationConfig[$relatedClass], $entryData);
0 ignored issues
show
Bug introduced by
The method mapToObject() does not exist on Dynamic\Salsify\TypeHandler\Relation\ManyHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
            /** @scrutinizer ignore-call */ 
49
            $related[] = $this->owner->mapToObject($relatedClass, $relationConfig[$relatedClass], $entryData);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
        }
50
        return $related;
51
    }
52
}
53