Passed
Push — master ( 673916...a119ad )
by
unknown
02:00
created

src/Model/BrokenExternalLink.php (10 issues)

1
<?php
2
3
namespace SilverStripe\ExternalLinks\Model;
4
5
use SilverStripe\Control\HTTPResponse;
6
use SilverStripe\ExternalLinks\Model\BrokenExternalPageTrack;
7
use SilverStripe\ExternalLinks\Model\BrokenExternalPageTrackStatus;
8
use SilverStripe\ORM\DataObject;
9
use SilverStripe\Security\Permission;
10
use SilverStripe\Security\Security;
11
12
/**
13
 * Represents a single link checked for a single run that is broken
14
 *
15
 * @method BrokenExternalPageTrack Track()
16
 * @method BrokenExternalPageTrackStatus Status()
17
 */
18
class BrokenExternalLink extends DataObject
19
{
20
    private static $table_name = 'BrokenExternalLink';
0 ignored issues
show
The private property $table_name is not used, and could be removed.
Loading history...
21
22
    private static $db = array(
0 ignored issues
show
The private property $db is not used, and could be removed.
Loading history...
23
        'Link' => 'Varchar(2083)', // 2083 is the maximum length of a URL in Internet Explorer.
24
        'HTTPCode' =>'Int'
25
    );
26
27
    private static $has_one = array(
0 ignored issues
show
The private property $has_one is not used, and could be removed.
Loading history...
28
        'Track' => BrokenExternalPageTrack::class,
29
        'Status' => BrokenExternalPageTrackStatus::class
30
    );
31
32
    private static $summary_fields = array(
0 ignored issues
show
The private property $summary_fields is not used, and could be removed.
Loading history...
33
        'Created' => 'Checked',
34
        'Link' => 'External Link',
35
        'HTTPCodeDescription' => 'HTTP Error Code',
36
        'Page.Title' => 'Page link is on'
37
    );
38
39
    private static $searchable_fields = array(
0 ignored issues
show
The private property $searchable_fields is not used, and could be removed.
Loading history...
40
        'HTTPCode' => array('title' => 'HTTP Code')
41
    );
42
43
    /**
44
     * @return SiteTree
0 ignored issues
show
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...
45
     */
46
    public function Page()
47
    {
48
        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...
49
    }
50
51
    public function canEdit($member = false)
52
    {
53
        return false;
54
    }
55
56
    public function canView($member = false)
57
    {
58
        $member = $member ? $member : Security::getCurrentUser();
59
        $codes = array('content-authors', 'administrators');
60
        return Permission::checkMember($member, $codes);
61
    }
62
63
    /**
64
     * Retrieve a human readable description of a response code
65
     *
66
     * @return string
67
     */
68
    public function getHTTPCodeDescription()
69
    {
70
        $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...
71
72
        try {
73
            $response = HTTPResponse::create('', $code);
0 ignored issues
show
'' 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

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