Passed
Push — master ( affe64...6c9189 )
by Jason
02:51
created

LocationCsvBulkLoader::getCategoryByName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 3
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\Locator;
4
5
use SilverStripe\Dev\CsvBulkLoader;
6
use SilverStripe\Core\Convert;
7
8
/**
9
 * Class LocationCsvBulkLoader
10
 */
11
class LocationCsvBulkLoader extends CsvBulkLoader
12
{
13
14
    /**
15
     * @var array
16
     */
17
    public $columnMap = array(
18
        'Name' => 'Title',
19
        'City' => 'Suburb',
20
        'EmailAddress' => 'Email',
21
        'Import_ID' => 'Import_ID',
22
    );
23
24
    /**
25
     * @var array
26
     */
27
    public $duplicateChecks = array(
28
        'Import_ID' => 'Import_ID'
29
    );
30
31
    /**
32
     * @var array
33
     */
34
    /*
35
    public $relationCallbacks = array(
36
       'Category.Name' => array(
37
           'relationname' => 'Category',
38
           'callback' => 'getCategoryByName',
39
        ),
40
    );*/
41
42
    /**
43
     * @param $obj
44
     * @param $val
45
     * @param $record
46
     * @return \SilverStripe\ORM\DataObject|static
47
     */
48
    public static function getCategoryByName(&$obj, $val, $record)
0 ignored issues
show
Unused Code introduced by
The parameter $record 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 static function getCategoryByName(&$obj, $val, /** @scrutinizer ignore-unused */ $record)

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 $obj 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 static function getCategoryByName(/** @scrutinizer ignore-unused */ &$obj, $val, $record)

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
        $val = Convert::raw2sql($val);
51
        $category = LocationCategory::get()->filter(array('Name' => $val))->First();
52
        if (!$category) {
0 ignored issues
show
introduced by
$category is of type SilverStripe\ORM\DataObject, thus it always evaluated to true.
Loading history...
53
            $category = LocationCategory::create();
54
            $category->Name = $val;
55
            $category->write();
56
        }
57
58
        return $category;
59
    }
60
}
61