Passed
Pull Request — master (#16)
by Matthew
02:08
created

RawHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 34
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handleRawType() 0 15 5
1
<?php
2
3
namespace Dynamic\Salsify\TypeHandler;
4
5
use \SilverStripe\Core\Extension;
6
7
/**
8
 * Class RawHandler
9
 */
10
class RawHandler extends Extension
11
{
12
    /**
13
     * @var array
14
     */
15
    private static $field_types = [
0 ignored issues
show
introduced by
The private property $field_types is not used, and could be removed.
Loading history...
16
        'Raw'
17
    ];
18
19
    /**
20
     * @param $data
21
     * @param $dataField
22
     * @param $config
23
     * @param $dbField
24
     * @param string |\SilverStripe\ORM\DataObject $class
25
     * @return string|int
26
     *
27
     * @return string|boolean|int|double
28
     */
29
    public function handleRawType($data, $dataField, $config, $dbField, $class)
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

29
    public function handleRawType($data, $dataField, /** @scrutinizer ignore-unused */ $config, $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...
30
    {
31
        $value = $data[$dataField];
32
        if (!is_array($value)) {
33
            return $value;
34
        }
35
36
        $db = $class::config()->get('db');
37
        foreach ($db as $fieldTitle => $fieldType) {
38
            if ($dbField === $fieldTitle && $fieldType === 'HTMLText') {
39
                return '<p>' . implode('<p></p>', $value) . '</p>';
40
            }
41
        }
42
43
        return implode('\r\n', $value);
44
    }
45
}
46