FailedURLRewriteObject::getBadImportData()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 16
rs 9.9666
cc 3
nc 3
nop 2
1
<?php
2
3
namespace PhpTek\Exodus\Model;
4
5
use SilverStripe\CMS\Model\SiteTree;
6
use SilverStripe\Core\Injector\Injectable;
7
use SilverStripe\ORM\DataObject;
8
use SilverStripe\ORM\ArrayList;
9
use SilverStripe\ORM\FieldType\DBVarchar;
10
11
/**
12
 * A model object that represents a single failed link-rewrite during the
13
 * running of the StaticSiteRewriteLinksTask. This data is then used to power the
14
 * {@link FailedURLRewriteReport}.
15
 *
16
 * @author Russell Michell <[email protected]>
17
 * @package phptek/silverstripe-exodus
18
 * @see {@link StaticSiteLinkRewriteTask}
19
 */
20
class FailedURLRewriteObject extends DataObject
21
{
22
    use Injectable;
23
24
    /**
25
     * @var string
26
     */
27
    private static $table_name = 'FailedURLRewriteObject';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
28
29
    /**
30
     *
31
     * @var array
32
     */
33
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
34
        "BadLinkType" => "Enum('ThirdParty, BadScheme, NotImported, Junk, Unknown', 'Unknown')",
35
        "OrigUrl" => DBVarchar::class,
36
    ];
37
38
    /**
39
     *
40
     * @var array
41
     */
42
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
43
        'Import' => StaticSiteImportDataObject::class,
44
        'ContainedIn' => SiteTree::class,
45
    ];
46
47
    /**
48
     * Customise the output of the FailedURLRewriteReport CSV export.
49
     *
50
     * @return array
51
     */
52
    public function summaryFields()
53
    {
54
        return [
55
            'ContainedIn.Title' => 'Imported page',
56
            'Import.Created' => 'Import date',
57
            'ThirdPartyTotal' => 'No. 3rd Party Urls',
58
            'BadSchemeTotal' => 'No. Urls with bad-scheme',
59
            'NotImportedTotal' => 'No. Unimported Urls',
60
            'JunkTotal' => 'No. Junk Urls',
61
        ];
62
    }
63
64
    /**
65
     * Fetch the related SiteTree object's Title property.
66
     *
67
     * @return string
68
     */
69
    public function Title()
70
    {
71
        return $this->ContainedIn()->Title;
0 ignored issues
show
Bug introduced by
The method ContainedIn() does not exist on PhpTek\Exodus\Model\FailedURLRewriteObject. 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

71
        return $this->/** @scrutinizer ignore-call */ ContainedIn()->Title;
Loading history...
72
    }
73
74
    /**
75
     * Get totals for each type of failed URL.
76
     *
77
     * @param number $importID
78
     * @param string $badLinkType e.g. 'NotImported'
79
     * @return SS_List
0 ignored issues
show
Bug introduced by
The type PhpTek\Exodus\Model\SS_List 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...
80
     */
81
    public function getBadImportData($importID, $badLinkType = null)
82
    {
83
        $default = ArrayList::create();
84
85
        $badLinks = DataObject::get(__CLASS__)
86
                ->filter('ImportID', $importID)
87
                ->sort('Created');
88
89
        if ($badLinks) {
0 ignored issues
show
introduced by
$badLinks is of type SilverStripe\ORM\DataList, thus it always evaluated to true.
Loading history...
90
            if ($badLinkType) {
91
                return $badLinks->filter('BadLinkType', $badLinkType);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $badLinks->filter...inkType', $badLinkType) returns the type SilverStripe\ORM\DataList which is incompatible with the documented return type PhpTek\Exodus\Model\SS_List.
Loading history...
92
            }
93
            return $badLinks;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $badLinks returns the type SilverStripe\ORM\DataList which is incompatible with the documented return type PhpTek\Exodus\Model\SS_List.
Loading history...
94
        }
95
96
        return $default;
97
    }
98
}
99