ForumThread::incNumViews()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
3
/**
4
 * A representation of a forum thread. A forum thread is 1 topic on the forum
5
 * which has multiple posts underneath it.
6
 *
7
 * @package forum
8
 */
9
10
class ForumThread extends DataObject
11
{
12
13
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
14
        "Title" => "Varchar(255)",
15
        "NumViews" => "Int",
16
        "IsSticky" => "Boolean",
17
        "IsReadOnly" => "Boolean",
18
        "IsGlobalSticky" => "Boolean"
19
    );
20
21
    private static $has_one = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
22
        'Forum' => 'Forum'
23
    );
24
25
    private static $has_many = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
26
        'Posts' => 'Post'
27
    );
28
29
    private static $defaults = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
30
        'NumViews' => 0,
31
        'IsSticky' => false,
32
        'IsReadOnly' => false,
33
        'IsGlobalSticky' => false
34
    );
35
36
    private static $indexes = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
37
        'IsSticky' => true,
38
        'IsGlobalSticky' => true
39
    );
40
41
    /**
42
     * @var null|boolean Per-request cache, whether we should display signatures on a post.
43
     */
44
    private static $_cache_displaysignatures = null;
45
46
    /**
47
     * Check if the user can create new threads and add responses
48
     */
49
    public function canPost($member = null)
50
    {
51
        if (!$member) {
52
            $member = Member::currentUser();
53
        }
54
        return ($this->Forum()->canPost($member) && !$this->IsReadOnly);
0 ignored issues
show
Documentation introduced by
The property IsReadOnly does not exist on object<ForumThread>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation Bug introduced by
The method Forum does not exist on object<ForumThread>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
55
    }
56
57
    /**
58
     * Check if user can moderate this thread
59
     */
60
    public function canModerate($member = null)
61
    {
62
        if (!$member) {
63
            $member = Member::currentUser();
64
        }
65
        return $this->Forum()->canModerate($member);
0 ignored issues
show
Documentation Bug introduced by
The method Forum does not exist on object<ForumThread>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
66
    }
67
68
    /**
69
     * Check if user can view the thread
70
     */
71
    public function canView($member = null)
72
    {
73
        if (!$member) {
74
            $member = Member::currentUser();
75
        }
76
        return $this->Forum()->canView($member);
0 ignored issues
show
Documentation Bug introduced by
The method Forum does not exist on object<ForumThread>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
77
    }
78
79
    /**
80
     * Hook up into moderation.
81
     */
82
    public function canEdit($member = null)
83
    {
84
        if (!$member) {
85
            $member = Member::currentUser();
86
        }
87
        return $this->canModerate($member);
88
    }
89
90
    /**
91
     * Hook up into moderation - users cannot delete their own posts/threads because
92
     * we will loose history this way.
93
     */
94
    public function canDelete($member = null)
95
    {
96
        if (!$member) {
97
            $member = Member::currentUser();
98
        }
99
        return $this->canModerate($member);
100
    }
101
102
    /**
103
     * Hook up into canPost check
104
     */
105
    public function canCreate($member = null)
106
    {
107
        if (!$member) {
108
            $member = Member::currentUser();
109
        }
110
        return $this->canPost($member);
111
    }
112
113
    /**
114
     * Are Forum Signatures on Member profiles allowed.
115
     * This only needs to be checked once, so we cache the initial value once per-request.
116
     *
117
     * @return bool
118
     */
119
    public function getDisplaySignatures()
120
    {
121
        if (isset(self::$_cache_displaysignatures) && self::$_cache_displaysignatures !== null) {
122
            return self::$_cache_displaysignatures;
123
        }
124
125
        $result = $this->Forum()->Parent()->DisplaySignatures;
0 ignored issues
show
Documentation Bug introduced by
The method Forum does not exist on object<ForumThread>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
126
        self::$_cache_displaysignatures = $result;
127
        return $result;
128
    }
129
130
    /**
131
     * Get the latest post from this thread. Nicer way then using an control
132
     * from the template
133
     *
134
     * @return Post
135
     */
136
    public function getLatestPost()
137
    {
138
        return DataObject::get_one('Post', "\"ThreadID\" = '$this->ID'", true, '"ID" DESC');
139
    }
140
141
    /**
142
     * Return the first post from the thread. Useful to working out the original author
143
     *
144
     * @return Post
145
     */
146
    public function getFirstPost()
147
    {
148
        return DataObject::get_one('Post', "\"ThreadID\" = '$this->ID'", true, '"ID" ASC');
149
    }
150
151
    /**
152
     * Return the number of posts in this thread. We could use count on
153
     * the dataobject set but that is slower and causes a performance overhead
154
     *
155
     * @return int
156
     */
157
    public function getNumPosts()
158
    {
159
        $sqlQuery = new SQLQuery();
0 ignored issues
show
Deprecated Code introduced by
The class SQLQuery has been deprecated with message: since version 4.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
160
        $sqlQuery->setFrom('"Post"');
161
        $sqlQuery->setSelect('COUNT("Post"."ID")');
162
        $sqlQuery->addInnerJoin('Member', '"Post"."AuthorID" = "Member"."ID"');
163
        $sqlQuery->addWhere('"Member"."ForumStatus" = \'Normal\'');
164
        $sqlQuery->addWhere('"ThreadID" = ' . $this->ID);
165
        return $sqlQuery->execute()->value();
166
    }
167
168
    /**
169
     * Check if they have visited this thread before. If they haven't increment
170
     * the NumViews value by 1 and set visited to true.
171
     *
172
     * @return void
173
     */
174
    public function incNumViews()
175
    {
176
        if (Session::get('ForumViewed-' . $this->ID)) {
177
            return false;
178
        }
179
180
        Session::set('ForumViewed-' . $this->ID, 'true');
181
182
        $this->NumViews++;
0 ignored issues
show
Documentation introduced by
The property NumViews does not exist on object<ForumThread>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
183
        $SQL_numViews = Convert::raw2sql($this->NumViews);
0 ignored issues
show
Documentation introduced by
The property NumViews does not exist on object<ForumThread>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
184
185
        DB::query("UPDATE \"ForumThread\" SET \"NumViews\" = '$SQL_numViews' WHERE \"ID\" = $this->ID");
186
    }
187
188
    /**
189
     * Link to this forum thread
190
     *
191
     * @return String
192
     */
193
    public function Link($action = "show", $showID = true)
194
    {
195
        $forum = DataObject::get_by_id("Forum", $this->ForumID);
0 ignored issues
show
Documentation introduced by
The property ForumID does not exist on object<ForumThread>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
196
        if ($forum) {
197
            $baseLink = $forum->Link();
198
            $extra = ($showID) ? '/'.$this->ID : '';
199
            return ($action) ? $baseLink . $action . $extra : $baseLink;
200
        } else {
201
            user_error("Bad ForumID '$this->ForumID'", E_USER_WARNING);
0 ignored issues
show
Documentation introduced by
The property ForumID does not exist on object<ForumThread>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
202
        }
203
    }
204
205
    /**
206
     * Check to see if the user has subscribed to this thread
207
     *
208
     * @return bool
209
     */
210
    public function getHasSubscribed()
211
    {
212
        $member = Member::currentUser();
213
214
        return ($member) ? ForumThread_Subscription::already_subscribed($this->ID, $member->ID) : false;
215
    }
216
217
    /**
218
     * Before deleting the thread remove all the posts
219
     */
220
    public function onBeforeDelete()
221
    {
222
        parent::onBeforeDelete();
223
224
        if ($posts = $this->Posts()) {
0 ignored issues
show
Documentation Bug introduced by
The method Posts does not exist on object<ForumThread>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
225
            foreach ($posts as $post) {
226
                // attachment deletion is handled by the {@link Post::onBeforeDelete}
227
                $post->delete();
228
            }
229
        }
230
    }
231
232
    public function onAfterWrite()
233
    {
234
        if ($this->isChanged('ForumID', 2)) {
235
            $posts = $this->Posts();
0 ignored issues
show
Documentation Bug introduced by
The method Posts does not exist on object<ForumThread>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
236
            if ($posts && $posts->count()) {
237
                foreach ($posts as $post) {
238
                    $post->ForumID=$this->ForumID;
0 ignored issues
show
Documentation introduced by
The property ForumID does not exist on object<ForumThread>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
239
                    $post->write();
240
                }
241
            }
242
        }
243
        parent::onAfterWrite();
244
    }
245
246
    /**
247
     * @return Text
248
     */
249
    public function getEscapedTitle()
250
    {
251
        //return DBField::create('Text', $this->dbObject('Title')->XML());
252
        return DBField::create_field('Text', $this->dbObject('Title')->XML());
253
    }
254
}
255
256
257
/**
258
 * Forum Thread Subscription: Allows members to subscribe to this thread
259
 * and receive email notifications when these topics are replied to.
260
 *
261
 * @package forum
262
 */
263
class ForumThread_Subscription extends DataObject
264
{
265
266
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
267
        "LastSent" => "SS_Datetime"
268
    );
269
270
    private static $has_one = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
271
        "Thread" => "ForumThread",
272
        "Member" => "Member"
273
    );
274
275
    /**
276
     * Checks to see if a Member is already subscribed to this thread
277
     *
278
     * @param int $threadID The ID of the thread to check
279
     * @param int $memberID The ID of the currently logged in member (Defaults to Member::currentUserID())
280
     *
281
     * @return bool true if they are subscribed, false if they're not
282
     */
283
    static function already_subscribed($threadID, $memberID = null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
284
    {
285
        if (!$memberID) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $memberID of type integer|null is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
286
            $memberID = Member::currentUserID();
287
        }
288
        $SQL_threadID = Convert::raw2sql($threadID);
289
        $SQL_memberID = Convert::raw2sql($memberID);
290
291
        if ($SQL_threadID=='' || $SQL_memberID=='') {
292
            return false;
293
        }
294
295
        return (DB::query("
296
			SELECT COUNT(\"ID\")
297
			FROM \"ForumThread_Subscription\"
298
			WHERE \"ThreadID\" = '$SQL_threadID' AND \"MemberID\" = $SQL_memberID")->value() > 0) ? true : false;
299
    }
300
301
    /**
302
     * Notifies everybody that has subscribed to this topic that a new post has been added.
303
     * To get emailed, people subscribed to this topic must have visited the forum
304
     * since the last time they received an email
305
     *
306
     * @param Post $post The post that has just been added
307
     */
308
    static function notify(Post $post)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
309
    {
310
        $list = DataObject::get(
311
            "ForumThread_Subscription",
312
            "\"ThreadID\" = '". $post->ThreadID ."' AND \"MemberID\" != '$post->AuthorID'"
0 ignored issues
show
Documentation introduced by
The property ThreadID does not exist on object<Post>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property AuthorID does not exist on object<Post>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
313
        );
314
315
        if ($list) {
316
            foreach ($list as $obj) {
317
                $SQL_id = Convert::raw2sql((int)$obj->MemberID);
318
319
                // Get the members details
320
                $member = DataObject::get_one("Member", "\"Member\".\"ID\" = '$SQL_id'");
321
                $adminEmail = Config::inst()->get('Email', 'admin_email');
322
323
                if ($member) {
324
                    $email = new Email();
325
                    $email->setFrom($adminEmail);
326
                    $email->setTo($member->Email);
327
                    $email->setSubject(_t('Post.NEWREPLY', 'New reply for {title}', array('title' => $post->Title)));
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<Post>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
array('title' => $post->Title) is of type array<string,?,{"title":"?"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
328
                    $email->setTemplate('ForumMember_TopicNotification');
329
                    $email->populateTemplate($member);
330
                    $email->populateTemplate($post);
331
                    $email->populateTemplate(array(
332
                        'UnsubscribeLink' => Director::absoluteBaseURL() . $post->Thread()->Forum()->Link() . '/unsubscribe/' . $post->ID
0 ignored issues
show
Documentation Bug introduced by
The method Thread does not exist on object<Post>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
333
                    ));
334
                    $email->send();
335
                }
336
            }
337
        }
338
    }
339
}
340