RawHandler::handleRawType()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 15
rs 9.6111
cc 5
nc 4
nop 5
1
<?php
2
3
namespace Dynamic\Salsify\TypeHandler;
4
5
use SilverStripe\Core\Extension;
6
7
/**
8
 * Class RawHandler
9
 *
10
 * @property-read \Dynamic\Salsify\Model\Mapper|RawHandler $owner
11
 */
12
class RawHandler extends Extension
13
{
14
15
    /**
16
     * @var array
17
     */
18
    private static $field_types = [
0 ignored issues
show
introduced by
The private property $field_types is not used, and could be removed.
Loading history...
19
        'Raw' => [
20
            'requiresWrite' => false,
21
            'requiresSalsifyObjects' => false,
22
            'allowsModification' => true,
23
        ],
24
        'SalsifyID' => [
25
            'requiresWrite' => false,
26
            'requiresSalsifyObjects' => false,
27
            'allowsModification' => false,
28
            'fallback' => 'Raw',
29
        ],
30
        'SalsifyUpdatedAt' => [
31
            'requiresWrite' => false,
32
            'requiresSalsifyObjects' => false,
33
            'allowsModification' => false,
34
            'fallback' => 'Raw',
35
        ],
36
    ];
37
38
    /**
39
     * @param string|SilverStripe\ORM\DataObject $class
0 ignored issues
show
Bug introduced by
The type Dynamic\Salsify\TypeHand...erStripe\ORM\DataObject was not found. Did you mean SilverStripe\ORM\DataObject? If so, make sure to prefix the type with \.
Loading history...
40
     * @param $data
41
     * @param $dataField
42
     * @param $config
43
     * @param $dbField
44
     * @return string|int
45
     *
46
     * @return string|boolean|int|double
47
     */
48
    public function handleRawType($class, $data, $dataField, $config, $dbField)
0 ignored issues
show
Unused Code introduced by
The parameter $config 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

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

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...
49
    {
50
        $value = $data[$dataField];
51
        if (!is_array($value)) {
52
            return $value;
53
        }
54
55
        $db = $class::config()->get('db');
56
        foreach ($this->owner->yieldKeyVal($db) as $fieldTitle => $fieldType) {
0 ignored issues
show
Bug introduced by
The method yieldKeyVal() does not exist on Dynamic\Salsify\TypeHandler\RawHandler. ( Ignorable by Annotation )

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

56
        foreach ($this->owner->/** @scrutinizer ignore-call */ yieldKeyVal($db) as $fieldTitle => $fieldType) {

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...
57
            if ($dbField === $fieldTitle && $fieldType === 'HTMLText') {
58
                return '<p>' . implode('<p></p>', $value) . '</p>';
59
            }
60
        }
61
62
        return implode('\r\n', $value);
63
    }
64
}
65