FlatRate   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 30
c 2
b 0
f 0
dl 0
loc 61
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B getPossiblePostage() 0 46 6
1
<?php
2
3
namespace SilverCommerce\Postage\Model;
4
5
use SilverStripe\ORM\ArrayList;
6
use SilverStripe\ORM\DataObject;
7
use SilverCommerce\Postage\Helpers\Parcel;
8
use SilverCommerce\Postage\Model\PostageType;
9
use SilverCommerce\Postage\Helpers\PostageOption;
10
11
/**
12
 * Represents a flat shipping cost, based on the selected regions.
13
 *
14
 * NOTE If you dont select any regions, this rate will be applied to
15
 * ALL regions
16
 */
17
class FlatRate extends PostageType
18
{
19
    private static $table_name = 'PostageType_FlatRate';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
20
21
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
22
        "Price" => "Currency"
23
    ];
24
25
    /**
26
     * If the current parcel is located in an area that we
27
     * allow flat rate
28
     *
29
     * @param Parcel
30
     * @return SSList
0 ignored issues
show
Bug introduced by
The type SilverCommerce\Postage\Model\SSList was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
     */
32
    public function getPossiblePostage(Parcel $parcel)
33
    {
34
        $return = ArrayList::create();
35
        $locations = $this->Locations();
0 ignored issues
show
Bug introduced by
The method Locations() does not exist on SilverCommerce\Postage\Model\FlatRate. 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

35
        /** @scrutinizer ignore-call */ 
36
        $locations = $this->Locations();
Loading history...
36
        $exclude = $this->Exclusions();
0 ignored issues
show
Bug introduced by
The method Exclusions() does not exist on SilverCommerce\Postage\Model\FlatRate. 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

36
        /** @scrutinizer ignore-call */ 
37
        $exclude = $this->Exclusions();
Loading history...
37
        $country = $parcel->getCountry();
38
        $region = $parcel->getRegion();
39
        $tax = null;
40
41
        if ($this->Tax()->exists()) {
0 ignored issues
show
Bug introduced by
The method Tax() does not exist on SilverCommerce\Postage\Model\FlatRate. 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

41
        if ($this->/** @scrutinizer ignore-call */ Tax()->exists()) {
Loading history...
42
            $tax = $this->Tax()->ValidTax();
43
        }
44
45
        $postage = PostageOption::create(
46
            $this->Name,
0 ignored issues
show
Bug Best Practice introduced by
The property Name does not exist on SilverCommerce\Postage\Model\FlatRate. Since you implemented __get, consider adding a @property annotation.
Loading history...
47
            $this->Price,
0 ignored issues
show
Bug Best Practice introduced by
The property Price does not exist on SilverCommerce\Postage\Model\FlatRate. Since you implemented __get, consider adding a @property annotation.
Loading history...
48
            $tax
49
        );
50
51
        if ($exclude->exists()) {
52
            $exclude = $exclude->filter(
53
                [
54
                    "Regions.CountryCode" => $country,
55
                    "Regions.Code" => $region
56
                ]
57
            );
58
        }
59
60
        if (!$exclude->exists()) {
61
            if ($locations->exists()) {
62
                $locations = $locations->filter(
63
                    [
64
                        "Regions.CountryCode" => $country,
65
                        "Regions.Code" => $region
66
                    ]
67
                );
68
69
                if ($locations->exists()) {
70
                    $return->add($postage);
71
                }
72
            } else {
73
                $return->add($postage);
74
            }
75
        }
76
77
        return $return;
78
    }
79
}
80