Passed
Pull Request — master (#16)
by Matthew
04:28 queued 50s
created

FileHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
c 1
b 0
f 0
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handleFileType() 0 14 3
1
<?php
2
3
namespace Dynamic\Salsify\TypeHandler\Asset;
4
5
use SilverStripe\ORM\DataObject;
6
7
/**
8
 * Class FileHandler
9
 * @package Dynamic\Salsify\TypeHandler
10
 *
11
 * @property-read \Dynamic\Salsify\Model\Mapper|\Dynamic\Salsify\TypeHandler\Asset\FileHandler $owner
12
 */
13
class FileHandler extends AssetHandler
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
        'File'
20
    ];
21
22
    /**
23
     * @param $data
24
     * @param $dataField
25
     * @param $config
26
     * @param $dbField
27
     * @param string |DataObject $class
28
     * @return string|int
29
     *
30
     * @throws \Exception
31
     */
32
    public function handleFileType($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

32
    public function handleFileType($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...
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

32
    public function handleFileType($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...
33
    {
34
        $data = $this->getAssetBySalsifyID($data[$dataField]);
35
        if (!$data) {
0 ignored issues
show
introduced by
The condition $data is always false.
Loading history...
36
            return '';
37
        }
38
39
        $asset = $this->updateFile(
40
            $data['salsify:id'],
41
            $data['salsify:updated_at'],
42
            $data['salsify:url'],
43
            $data['salsify:name']
44
        );
45
        return preg_match('/ID$/', $dbField) ? $asset->ID : $asset;
46
    }
47
}
48