Passed
Pull Request — master (#16)
by Matthew
01:54
created

RawHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handleRawType() 0 14 5
1
<?php
2
3
namespace Dynamic\Salsify\TypeHandler;
4
5
/**
6
 * Class RawHandler
7
 */
8
class RawHandler extends \SilverStripe\Core\Extension
9
{
10
    /**
11
     * @var array
12
     */
13
    private static $field_types = [
0 ignored issues
show
introduced by
The private property $field_types is not used, and could be removed.
Loading history...
14
        'Raw'
15
    ];
16
17
    /**
18
     * @param $value
19
     * @param string $field
20
     * @param string|\SilverStripe\ORM\DataObject $class
21
     * @return string|boolean|int|double
22
     */
23
    public function handleRawType($value, $field, $class)
24
    {
25
        if (!is_array($value)) {
26
            return $value;
27
        }
28
29
        $db = $class::config()->get('db');
30
        foreach ($db as $fieldTitle => $fieldType) {
31
            if ($field === $fieldTitle && $fieldType === 'HTMLText') {
32
                return '<p>' . implode('<p></p>', $value) . '</p>';
33
            }
34
        }
35
36
        return implode('\r\n', $value);
37
    }
38
}
39