These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * A blog category for generalising blog posts. |
||
5 | * |
||
6 | * @package silverstripe |
||
7 | * @subpackage blog |
||
8 | * |
||
9 | * @method Blog Blog() |
||
10 | * |
||
11 | * @property string $URLSegment |
||
12 | * @property int $BlogID |
||
13 | */ |
||
14 | View Code Duplication | class BlogCategory extends DataObject implements CategorisationObject |
|
15 | { |
||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | private static $db = array( |
||
20 | 'Title' => 'Varchar(255)', |
||
21 | ); |
||
22 | |||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | private static $has_one = array( |
||
27 | 'Blog' => 'Blog', |
||
28 | ); |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | private static $belongs_many_many = array( |
||
34 | 'BlogPosts' => 'BlogPost', |
||
35 | ); |
||
36 | |||
37 | /** |
||
38 | * @var array |
||
39 | */ |
||
40 | private static $extensions = array( |
||
41 | 'URLSegmentExtension', |
||
42 | ); |
||
43 | |||
44 | /** |
||
45 | * @return DataList |
||
46 | */ |
||
47 | public function BlogPosts() |
||
48 | { |
||
49 | $blogPosts = parent::BlogPosts(); |
||
50 | |||
51 | $this->extend("updateGetBlogPosts", $blogPosts); |
||
52 | |||
53 | return $blogPosts; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | public function getCMSFields() |
||
60 | { |
||
61 | $fields = new FieldList( |
||
62 | TextField::create('Title', _t('BlogCategory.Title', 'Title')) |
||
63 | ); |
||
64 | |||
65 | $this->extend('updateCMSFields', $fields); |
||
66 | |||
67 | return $fields; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Returns a relative link to this category. |
||
72 | * |
||
73 | * @return string |
||
74 | */ |
||
75 | public function getLink() |
||
76 | { |
||
77 | return Controller::join_links($this->Blog()->Link(), 'category', $this->URLSegment); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Inherits from the parent blog or can be overwritten using a DataExtension. |
||
82 | * |
||
83 | * @param null|Member $member |
||
84 | * |
||
85 | * @return bool |
||
86 | */ |
||
87 | public function canView($member = null) |
||
88 | { |
||
89 | $extended = $this->extendedCan(__FUNCTION__, $member); |
||
0 ignored issues
–
show
|
|||
90 | |||
91 | if ($extended !== null) { |
||
92 | return $extended; |
||
93 | } |
||
94 | |||
95 | return $this->Blog()->canView($member); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Inherits from the parent blog or can be overwritten using a DataExtension. |
||
100 | * |
||
101 | * @param null|Member $member |
||
102 | * |
||
103 | * @return bool |
||
104 | */ |
||
105 | public function canCreate($member = null) |
||
106 | { |
||
107 | $extended = $this->extendedCan(__FUNCTION__, $member); |
||
0 ignored issues
–
show
It seems like
$member defined by parameter $member on line 105 can be null ; however, DataObject::extendedCan() does not accept null , maybe add an additional type check?
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null. We recommend to add an additional type check (or disallow null for the parameter): function notNullable(stdClass $x) { }
// Unsafe
function withoutCheck(stdClass $x = null) {
notNullable($x);
}
// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
if ($x instanceof stdClass) {
notNullable($x);
}
}
// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
notNullable($x);
}
Loading history...
|
|||
108 | |||
109 | if ($extended !== null) { |
||
110 | return $extended; |
||
111 | } |
||
112 | |||
113 | $permission = Blog::config()->grant_user_permission; |
||
114 | |||
115 | return Permission::checkMember($member, $permission); |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * Inherits from the parent blog or can be overwritten using a DataExtension. |
||
120 | * |
||
121 | * @param null|Member $member |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | public function canDelete($member = null) |
||
126 | { |
||
127 | $extended = $this->extendedCan(__FUNCTION__, $member); |
||
0 ignored issues
–
show
It seems like
$member defined by parameter $member on line 125 can be null ; however, DataObject::extendedCan() does not accept null , maybe add an additional type check?
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null. We recommend to add an additional type check (or disallow null for the parameter): function notNullable(stdClass $x) { }
// Unsafe
function withoutCheck(stdClass $x = null) {
notNullable($x);
}
// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
if ($x instanceof stdClass) {
notNullable($x);
}
}
// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
notNullable($x);
}
Loading history...
|
|||
128 | |||
129 | if ($extended !== null) { |
||
130 | return $extended; |
||
131 | } |
||
132 | |||
133 | return $this->Blog()->canEdit($member); |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * Inherits from the parent blog or can be overwritten using a DataExtension. |
||
138 | * |
||
139 | * @param null|Member $member |
||
140 | * |
||
141 | * @return bool |
||
142 | */ |
||
143 | public function canEdit($member = null) |
||
144 | { |
||
145 | $extended = $this->extendedCan(__FUNCTION__, $member); |
||
0 ignored issues
–
show
It seems like
$member defined by parameter $member on line 143 can be null ; however, DataObject::extendedCan() does not accept null , maybe add an additional type check?
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null. We recommend to add an additional type check (or disallow null for the parameter): function notNullable(stdClass $x) { }
// Unsafe
function withoutCheck(stdClass $x = null) {
notNullable($x);
}
// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
if ($x instanceof stdClass) {
notNullable($x);
}
}
// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
notNullable($x);
}
Loading history...
|
|||
146 | |||
147 | if ($extended !== null) { |
||
148 | return $extended; |
||
149 | } |
||
150 | |||
151 | return $this->Blog()->canEdit($member); |
||
152 | } |
||
153 | } |
||
154 |
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):