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
introduced
by
Loading history...
|
|||||
21 | |||||
22 | private static $db = array( |
||||
0 ignored issues
–
show
|
|||||
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
|
|||||
28 | 'Track' => BrokenExternalPageTrack::class, |
||||
29 | 'Status' => BrokenExternalPageTrackStatus::class |
||||
30 | ); |
||||
31 | |||||
32 | private static $summary_fields = array( |
||||
0 ignored issues
–
show
|
|||||
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
|
|||||
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. 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
|
|||||
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
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
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
|
|||||
79 | $description = _t(__CLASS__ . '.UNKNOWNRESPONSE', 'Unknown Response Code'); |
||||
80 | } |
||||
81 | |||||
82 | return sprintf("%d (%s)", $code, $description); |
||||
83 | } |
||||
84 | } |
||||
85 |