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

FileHandler::handleFileType()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 14
rs 9.9666
cc 3
nc 3
nop 5
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
        'ManyFiles',
21
    ];
22
23
    /**
24
     * @param $data
25
     * @param $dataField
26
     * @param $config
27
     * @param $dbField
28
     * @param string |DataObject $class
29
     * @return string|int
30
     *
31
     * @throws \Exception
32
     */
33
    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

33
    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

33
    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...
34
    {
35
        $data = $this->getAssetBySalsifyID($data[$dataField]);
36
        if (!$data) {
0 ignored issues
show
introduced by
The condition $data is always false.
Loading history...
37
            return '';
38
        }
39
40
        $asset = $this->updateFile(
41
            $data['salsify:id'],
42
            $data['salsify:updated_at'],
43
            $data['salsify:url'],
44
            $data['salsify:name']
45
        );
46
        return preg_match('/ID$/', $dbField) ? $asset->ID : $asset;
47
    }
48
49
    /**
50
     * @param $data
51
     * @param $dataField
52
     * @param $config
53
     * @param $dbField
54
     * @param string |DataObject $class
55
     * @return array
56
     *
57
     * @throws \Exception
58
     */
59
    public function handleManyFilesType($data, $dataField, $config, $dbField, $class)
60
    {
61
        $files = [];
62
        $fieldData = $data[$dataField];
63
        foreach ($fieldData as $fileID) {
64
            $entryData = array_merge($data, [
65
                $dataField => $fileID
66
            ]);
67
            $files[] = $this->owner->handleFileType($entryData, $dataField, $config, $dbField, $class);
0 ignored issues
show
Bug introduced by
The method handleFileType() does not exist on Dynamic\Salsify\Model\Mapper. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

67
            /** @scrutinizer ignore-call */ 
68
            $files[] = $this->owner->handleFileType($entryData, $dataField, $config, $dbField, $class);
Loading history...
68
        }
69
        return $files;
70
    }
71
}
72