Passed
Pull Request — master (#173)
by Matthew
13:34
created

LocationCsvBulkLoader   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 48
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getCategoryByName() 0 11 2
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
        'Category' => 'Category.Name',
22
        'Import_ID' => 'Import_ID',
23
    );
24
25
    /**
26
     * @var array
27
     */
28
    public $duplicateChecks = array(
29
        'Import_ID' => 'Import_ID'
30
    );
31
32
    /**
33
     * @var array
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...
49
    {
50
        $val = Convert::raw2sql($val);
51
        $category = LocationCategory::get()->filter(array('Name' => $val))->First();
52
        if (!$category) {
53
            $category = LocationCategory::create();
54
            $category->Name = $val;
55
            $category->write();
56
        }
57
58
        return $category;
59
    }
60
}
61