Completed
Push — master ( 9ea506...789ce9 )
by Robbie
13s
created

BrokenExternalLink::Page()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\ExternalLinks\Model;
4
5
use SilverStripe\ExternalLinks\Model\BrokenExternalPageTrack;
6
use SilverStripe\ExternalLinks\Model\BrokenExternalPageTrackStatus;
7
use SilverStripe\Security\Member;
8
use SilverStripe\Security\Permission;
9
use SilverStripe\Core\Config\Config;
10
use SilverStripe\Control\HTTPResponse;
11
use SilverStripe\ORM\DataObject;
12
13
/**
14
 * Represents a single link checked for a single run that is broken
15
 *
16
 * @method BrokenExternalPageTrack Track()
17
 * @method BrokenExternalPageTrackStatus Status()
18
 */
19
class BrokenExternalLink extends DataObject
20
{
21
    private static $table_name = 'BrokenExternalLink';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
22
23
    private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
24
        'Link' => 'Varchar(2083)', // 2083 is the maximum length of a URL in Internet Explorer.
25
        'HTTPCode' =>'Int'
26
    );
27
28
    private static $has_one = array(
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
29
        'Track' => BrokenExternalPageTrack::class,
30
        'Status' => BrokenExternalPageTrackStatus::class
31
    );
32
33
    private static $summary_fields = array(
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
34
        'Created' => 'Checked',
35
        'Link' => 'External Link',
36
        'HTTPCodeDescription' => 'HTTP Error Code',
37
        'Page.Title' => 'Page link is on'
38
    );
39
40
    private static $searchable_fields = array(
0 ignored issues
show
introduced by
The private property $searchable_fields is not used, and could be removed.
Loading history...
41
        'HTTPCode' => array('title' => 'HTTP Code')
42
    );
43
44
    /**
45
     * @return SiteTree
0 ignored issues
show
Bug introduced by
The type SilverStripe\ExternalLinks\Model\SiteTree 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...
46
     */
47
    public function Page()
48
    {
49
        return $this->Track()->Page();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->Track()->Page() returns the type SilverStripe\CMS\Model\SiteTree which is incompatible with the documented return type SilverStripe\ExternalLinks\Model\SiteTree.
Loading history...
50
    }
51
52
    public function canEdit($member = false)
53
    {
54
        return false;
55
    }
56
57
    public function canView($member = false)
58
    {
59
        $member = $member ? $member : Member::currentUser();
0 ignored issues
show
Deprecated Code introduced by
The function SilverStripe\Security\Member::currentUser() has been deprecated: 5.0.0 use Security::getCurrentUser() ( Ignorable by Annotation )

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

59
        $member = $member ? $member : /** @scrutinizer ignore-deprecated */ Member::currentUser();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
60
        $codes = array('content-authors', 'administrators');
61
        return Permission::checkMember($member, $codes);
62
    }
63
64
    /**
65
     * Retrieve a human readable description of a response code
66
     *
67
     * @return string
68
     */
69
    public function getHTTPCodeDescription()
70
    {
71
        $code = $this->HTTPCode;
0 ignored issues
show
Bug Best Practice introduced by
The property HTTPCode does not exist on SilverStripe\ExternalLin...odel\BrokenExternalLink. Since you implemented __get, consider adding a @property annotation.
Loading history...
72
73
        try {
74
            $response = HTTPResponse::create('', $code);
0 ignored issues
show
Bug introduced by
'' of type string is incompatible with the type array expected by parameter $args of SilverStripe\Control\HTTPResponse::create(). ( Ignorable by Annotation )

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

74
            $response = HTTPResponse::create(/** @scrutinizer ignore-type */ '', $code);
Loading history...
75
            // Assume that $code = 0 means there was no response
76
            $description = $code ?
77
                $response->getStatusDescription() :
78
                _t(__CLASS__ . '.NOTAVAILABLE', 'Server Not Available');
79
        } catch (InvalidArgumentException $e) {
0 ignored issues
show
Bug introduced by
The type SilverStripe\ExternalLin...nvalidArgumentException was not found. Did you mean InvalidArgumentException? If so, make sure to prefix the type with \.
Loading history...
80
            $description = _t(__CLASS__ . '.UNKNOWNRESPONSE', 'Unknown Response Code');
81
        }
82
83
        return sprintf("%d (%s)", $code, $description);
84
    }
85
}
86