BrokenExternalLinksReport   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A title() 0 3 1
A getColumns() 0 3 1
A columns() 0 23 1
A getCMSFields() 0 17 1
A sourceRecords() 0 7 2
1
<?php
2
3
namespace SilverStripe\ExternalLinks\Reports;
4
5
use SilverStripe\Core\Convert;
6
use SilverStripe\ExternalLinks\Model\BrokenExternalPageTrackStatus;
7
use SilverStripe\Forms\LiteralField;
8
use SilverStripe\Forms\FormAction;
9
use SilverStripe\ORM\ArrayList;
10
use SilverStripe\Reports\Report;
11
use SilverStripe\View\Requirements;
12
13
/**
14
 * Content side-report listing pages with external broken links
15
 * @package externallinks
16
 */
17
18
class BrokenExternalLinksReport extends Report
19
{
20
21
    /**
22
     * Returns the report title
23
     *
24
     * @return string
25
     */
26
    public function title()
27
    {
28
        return _t(__CLASS__ . '.EXTERNALBROKENLINKS', "External broken links report");
29
    }
30
31
    public function columns()
32
    {
33
        return array(
34
            "Created" => "Checked",
35
            'Link' => array(
36
                'title' => 'External Link',
37
                'formatting' => function ($value, $item) {
38
                    return sprintf(
39
                        '<a target="_blank" href="%s">%s</a>',
40
                        Convert::raw2att($item->Link),
0 ignored issues
show
Bug introduced by
It seems like SilverStripe\Core\Convert::raw2att($item->Link) can also be of type array and array; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

40
                        /** @scrutinizer ignore-type */ Convert::raw2att($item->Link),
Loading history...
41
                        Convert::raw2xml($item->Link)
42
                    );
43
                }
44
            ),
45
            'HTTPCodeDescription' => 'HTTP Error Code',
46
            "Title" => array(
47
                "title" => 'Page link is on',
48
                'formatting' => function ($value, $item) {
49
                    $page = $item->Page();
50
                    return sprintf(
51
                        '<a href="%s">%s</a>',
52
                        Convert::raw2att($page->CMSEditLink()),
0 ignored issues
show
Bug introduced by
It seems like SilverStripe\Core\Conver...t($page->CMSEditLink()) can also be of type array and array; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

52
                        /** @scrutinizer ignore-type */ Convert::raw2att($page->CMSEditLink()),
Loading history...
53
                        Convert::raw2xml($page->Title)
54
                    );
55
                }
56
            )
57
        );
58
    }
59
60
    /**
61
     * Alias of columns(), to support the export to csv action
62
     * in {@link GridFieldExportButton} generateExportFileData method.
63
     * @return array
64
     */
65
    public function getColumns()
66
    {
67
        return $this->columns();
68
    }
69
70
    public function sourceRecords()
71
    {
72
        $track = BrokenExternalPageTrackStatus::get_latest();
73
        if ($track) {
0 ignored issues
show
introduced by
$track is of type SilverStripe\ExternalLin...ExternalPageTrackStatus, thus it always evaluated to true.
Loading history...
74
            return $track->BrokenLinks();
75
        }
76
        return ArrayList::create();
77
    }
78
79
    public function getCMSFields()
80
    {
81
        Requirements::css('silverstripe/externallinks: css/BrokenExternalLinksReport.css');
82
        Requirements::javascript('silverstripe/externallinks: javascript/BrokenExternalLinksReport.js');
83
84
        $fields = parent::getCMSFields();
85
86
        $runReportButton = FormAction::create('createReport', _t(__CLASS__ . '.RUNREPORT', 'Create new report'))
87
            ->addExtraClass('btn-primary external-links-report__create-report')
88
            ->setUseButtonTag(true);
89
        $fields->push($runReportButton);
90
91
        $reportResultSpan = '<p class="external-links-report__report-progress"></p>';
92
        $reportResult = LiteralField::create('ResultTitle', $reportResultSpan);
93
        $fields->push($reportResult);
94
95
        return $fields;
96
    }
97
}
98