Completed
Push — master ( 7206f2...88ad46 )
by Jared
03:56
created

TimberComment   B

Complexity

Total Complexity 51

Size/Duplication

Total Lines 361
Duplicated Lines 2.22 %

Coupling/Cohesion

Components 4
Dependencies 2
Metric Value
wmc 51
lcom 4
cbo 2
dl 8
loc 361
rs 8.3206

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __toString() 0 3 1
A init() 0 11 2
A author() 0 13 4
B avatar() 0 22 5
A content() 0 3 1
A approved() 0 3 1
A date() 0 5 2
A time() 0 5 2
A meta() 0 3 1
A is_child() 0 3 1
B get_meta_fields() 0 15 5
A get_meta_field() 8 8 2
A reply_link() 0 19 4
A avatar_email() 0 10 2
A avatar_host() 0 12 3
C avatar_default() 0 27 12
A avatar_out() 0 8 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like TimberComment often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use TimberComment, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * The TimberComment class is used to view the output of comments. 99% of the time this will be in the context of the comments on a post. However you can also fetch a comment directly using its comment ID.
5
 * @example
6
 * ```php
7
 * $comment = new TimberComment($comment_id);
8
 * $context['comment_of_the_day'] = $comment;
9
 * Timber::render('index.twig', $context);
10
 * ```
11
 *
12
 * ```twig
13
 * <p class="comment">{{comment_of_the_day.content}}</p>
14
 * <p class="comment-attribution">- {{comment.author.name}}</p>
15
 * ```
16
 *
17
 * ```html
18
 * <p class="comment">But, O Sarah! If the dead can come back to this earth and flit unseen around those they loved, I shall always be near you; in the garish day and in the darkest night -- amidst your happiest scenes and gloomiest hours - always, always; and if there be a soft breeze upon your cheek, it shall be my breath; or the cool air fans your throbbing temple, it shall be my spirit passing by.</p>
19
 * <p class="comment-attribution">- Sullivan Ballou</p>
20
 * ```
21
 */
22
class TimberComment extends TimberCore implements TimberCoreInterface {
23
24
	public $PostClass = 'TimberPost';
25
	public $object_type = 'comment';
26
27
	public static $representation = 'comment';
28
29
	public $ID;
30
	public $id;
31
	public $comment_author_email;
32
	public $comment_content;
33
	public $comment_date;
34
	public $comment_ID;
35
	public $user_id;
36
	public $comment_author;
37
38
	public $children = array();
39
40
	/**
41
	 * @param int $cid
42
	 */
43
	function __construct($cid) {
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...
44
		$this->init($cid);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
45
	}
46
47
	function __toString(){
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...
48
		return $this->content();
49
	}
50
51
	/**
52
	 * @internal
53
	 * @param integer $cid
54
	 */
55
	function init($cid) {
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...
56
		$comment_data = $cid;
57
		if (is_integer($cid)) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
58
			$comment_data = get_comment($cid);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
59
		}
60
		$this->import($comment_data);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
61
		$this->ID = $this->comment_ID;
62
		$this->id = $this->comment_ID;
63
		$comment_meta_data = $this->get_meta_fields($this->ID);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
64
		$this->import($comment_meta_data);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
65
	}
66
67
	/**
68
	 * @api
69
	 * @example
70
	 * ```twig
71
	 * <h3>Comments by...</h3>
72
	 * <ol>
73
	 * {% for comment in post.comments %}
74
	 * 	<li>{{comment.author.name}}, who is a {{comment.author.role}}</li>
75
	 * {% endfor %}
76
	 * </ol>
77
	 * ```
78
	 * ```html
79
	 * <h3>Comments by...</h3>
80
	 * <ol>
81
	 * 	<li>Jared Novack, who is a contributor</li>
82
	 * 	<li>Katie Ricci, who is a subscriber</li>
83
	 * 	<li>Rebecca Pearl, who is a author</li>
84
	 * </ol>
85
	 * ```
86
	 * @return TimberUser
87
	 */
88
	public function author() {
89
		if ($this->user_id) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
90
			return new TimberUser($this->user_id);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
91
		} else {
92
			$author = new TimberUser(0);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
93
			if (isset($this->comment_author) && $this->comment_author) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
94
				$author->name = $this->comment_author;
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<TimberUser>. 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...
95
			} else {
96
				$author->name = 'Anonymous';
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<TimberUser>. 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...
97
			}
98
		}
99
		return $author;
100
	}
101
102
	/**
103
	 * Fetches the Gravatar
104
	 * @api
105
	 * @example
106
	 * ```twig
107
	 * <img src="{{comment.avatar(36,template_uri~"/img/dude.jpg")}}" alt="Image of {{comment.author.name}}" />
108
	 * ```
109
	 * ```html
110
	 * <img src="http://gravatar.com/i/sfsfsdfasdfsfa.jpg" alt="Image of Katherine Rich" />
111
	 * ```
112
	 * @param int $size
113
	 * @param string $default
114
	 * @return bool|mixed|string
115
	 */
116
	public function avatar($size = 92, $default = '') {
117
		if (!get_option('show_avatars')) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
Expected 1 space before "!"; 0 found
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
118
			return false;
119
		}
120
		if (!is_numeric($size)) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
Expected 1 space before "!"; 0 found
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
121
			$size = '92';
122
		}
123
124
		$email = $this->avatar_email();
125
		$email_hash = '';
126
		if (!empty($email)) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
Expected 1 space before "!"; 0 found
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
127
			$email_hash = md5(strtolower(trim($email)));
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
128
		}
129
		$host = $this->avatar_host($email_hash);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
130
		$default = $this->avatar_default($default, $email, $size, $host);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
131
		if (!empty($email)) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
Expected 1 space before "!"; 0 found
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
132
			$avatar = $this->avatar_out($default, $host, $email_hash, $size);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
133
		} else {
134
			$avatar = $default;
135
		}
136
		return $avatar;
137
	}
138
139
	/**
140
	 * @api
141
	 * @return string
142
	 */
143
	public function content() {
144
		return apply_filters('get_comment_text ', $this->comment_content);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
145
	}
146
147
	/**
148
	 * @api
149
	 * @example
150
	 * ```twig
151
	 * {% if comment.approved %}
152
	 * 	Your comment is good
153
	 * {% else %}
154
	 * 	Do you kiss your mother with that mouth?
155
	 * {% endif %}
156
	 * ```
157
	 * @return boolean
158
	 */
159
	public function approved() {
160
		return $this->comment_approved;
0 ignored issues
show
Documentation introduced by
The property comment_approved does not exist on object<TimberComment>. 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...
161
	}
162
163
	/**
164
	 * @api
165
	 * @example
166
	 * ```twig
167
	 * {% for comment in post.comments %}
168
	 * <article class="comment">
169
	 *   <p class="date">Posted on {{ comment.date }}:</p>
170
	 *   <p class="comment">{{ comment.content }}</p>
171
	 * </article>
172
	 * {% endfor %}
173
	 * ```
174
	 * ```html
175
	 * <article class="comment">
176
	 *   <p class="date">Posted on September 28, 2015:</p>
177
	 *   <p class="comment">Happy Birthday!</p>
178
	 * </article>
179
	 * ```
180
	 * @return string
181
	 */
182
	public function date( $date_format = '' ) {
183
		$df = $date_format ? $date_format : get_option('date_format');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
184
		$the_date = (string)mysql2date($df, $this->comment_date);
0 ignored issues
show
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
185
		return apply_filters('get_comment_date ', $the_date, $df);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
186
	}
187
188
	/**
189
	 * @api
190
	 * @example
191
	 * ```twig
192
	 * {% for comment in post.comments %}
193
	 * <article class="comment">
194
	 *   <p class="date">Posted on {{ comment.date }} at {{comment.time}}:</p>
195
	 *   <p class="comment">{{ comment.content }}</p>
196
	 * </article>
197
	 * {% endfor %}
198
	 * ```
199
	 * ```html
200
	 * <article class="comment">
201
	 *   <p class="date">Posted on September 28, 2015 at 12:45 am:</p>
202
	 *   <p class="comment">Happy Birthday!</p>
203
	 * </article>
204
	 * ```
205
	 * @return string
206
	 */
207
	public function time( $time_format = '' ) {
208
		$tf = $time_format ? $time_format : get_option('time_format');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
209
		$the_time = (string)mysql2date($tf, $this->comment_date);
0 ignored issues
show
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
210
		return apply_filters('get_comment_time', $the_time, $tf);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
211
	}
212
213
	/**
214
	 * @param string $field_name
215
	 * @return mixed
216
	 */
217
	public function meta($field_name) {
218
		return $this->get_meta_field($field_name);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
219
	}
220
221
	/**
222
	 * @api
223
	 * @return bool
224
	 */
225
	public function is_child() {
226
		return $this->comment_parent > 0;
0 ignored issues
show
Documentation introduced by
The property comment_parent does not exist on object<TimberComment>. 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...
227
	}
228
229
	/**
230
	 * @internal
231
	 * @param int $comment_id
0 ignored issues
show
Documentation introduced by
Should the type for parameter $comment_id not be integer|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
232
	 * @return mixed
233
	 */
234
	protected function get_meta_fields($comment_id = null) {
235
		if ($comment_id === null) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
236
			$comment_id = $this->ID;
237
		}
238
		//Could not find a WP function to fetch all comment meta data, so I made one.
239
		apply_filters('timber_comment_get_meta_pre', array(), $comment_id);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
240
		$comment_metas = get_comment_meta($comment_id);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
241
		foreach ($comment_metas as &$cm) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
242
			if (is_array($cm) && count($cm) == 1) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
Found "== 1". Use Yoda Condition checks, you must
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
243
				$cm = $cm[0];
244
			}
245
		}
246
		$comment_metas = apply_filters('timber_comment_get_meta', $comment_metas, $comment_id);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
247
		return $comment_metas;
248
	}
249
250
	/**
251
	 * @internal
252
	 * @param string $field_name
253
	 * @return mixed
254
	 */
255 View Code Duplication
	protected function get_meta_field($field_name) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
256
		$value = apply_filters('timber_comment_get_meta_field_pre', null, $this->ID, $field_name, $this);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
257
		if ($value === null) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
258
			$value = get_comment_meta($this->ID, $field_name, true);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
259
		}
260
		$value = apply_filters('timber_comment_get_meta_field', $value, $this->ID, $field_name, $this);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
261
		return $value;
262
	}
263
264
	/**
265
	 * Enqueue the WP threaded comments javascript,
266
	 * and fetch the reply link for various comments.
267
	 * @api
268
	 * @param int $comment_id
0 ignored issues
show
Bug introduced by
There is no parameter named $comment_id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
269
	 * @param int $post_id
0 ignored issues
show
Bug introduced by
There is no parameter named $post_id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
270
	 * @return string
271
	 */
272
	public function reply_link( $reply_text = 'Reply' ) {
273
		if ( is_singular() && comments_open() && get_option('thread_comments') ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
274
			wp_enqueue_script( 'comment-reply' );
275
		}
276
277
		// Get the comments depth option from the admin panel
278
		$max_depth = get_option('thread_comments_depth');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
279
280
		// Default args
281
		$args = array(
282
			'add_below' => 'comment',
283
			'respond_id' => 'respond',
284
			'reply_text' => $reply_text,
285
			'depth' => 1,
286
			'max_depth' => $max_depth,
287
		);
288
289
		return get_comment_reply_link( $args, $this->ID, $this->post_id );
0 ignored issues
show
Documentation introduced by
The property post_id does not exist on object<TimberComment>. 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...
290
	}
291
292
	/* AVATAR Stuff
293
	======================= */
294
295
	/**
296
	 * @internal
297
	 * @return string
298
	 */
299
	protected function avatar_email() {
300
		$id = (int)$this->user_id;
0 ignored issues
show
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
301
		$user = get_userdata($id);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
302
		if ($user) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
303
			$email = $user->user_email;
304
		} else {
305
			$email = $this->comment_author_email;
306
		}
307
		return $email;
308
	}
309
310
	/**
311
	 * @internal
312
	 * @param string $email_hash
313
	 * @return string
314
	 */
315
	protected function avatar_host($email_hash) {
316
		if (is_ssl()) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
317
			$host = 'https://secure.gravatar.com';
318
		} else {
319
			if (!empty($email_hash)) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
Expected 1 space before "!"; 0 found
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
320
				$host = sprintf("http://%d.gravatar.com", (hexdec($email_hash[0]) % 2));
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style Comprehensibility introduced by
The string literal http://%d.gravatar.com does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
321
			} else {
322
				$host = 'http://0.gravatar.com';
323
			}
324
		}
325
		return $host;
326
	}
327
328
	/**
329
	 * @internal
330
	 * @todo  what if it's relative?
331
	 * @param string $default
332
	 * @param string $email
333
	 * @param string $size
334
	 * @param string $host
335
	 * @return string
336
	 */
337
	protected function avatar_default($default, $email, $size, $host) {
338
		if (substr($default, 0, 1) == '/') {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
339
			$default = home_url() . $default;
340
		}
341
342
		if (empty($default)) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
343
			$avatar_default = get_option('avatar_default');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
344
			if (empty($avatar_default)) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
345
				$default = 'mystery';
346
			} else {
347
				$default = $avatar_default;
348
			}
349
		}
350
		if ('mystery' == $default) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
351
			$default = $host . '/avatar/ad516503a11cd5ca435acc9bb6523536?s=' . $size;
352
			// ad516503a11cd5ca435acc9bb6523536 == md5('[email protected]')
353
		} else if ('blank' == $default) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
354
			$default = $email ? 'blank' : includes_url('images/blank.gif');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
355
		} else if (!empty($email) && 'gravatar_default' == $default) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
Expected 1 space before "!"; 0 found
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
356
			$default = '';
357
		} else if ('gravatar_default' == $default) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
358
			$default = $host . '/avatar/?s=' . $size;
359
		} else if (empty($email) && !strstr($default, 'http://')) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
360
			$default = $host . '/avatar/?d=' . $default . '&amp;s=' . $size;
361
		}
362
		return $default;
363
	}
364
365
	/**
366
	 * @internal
367
	 * @param string $default
368
	 * @param string $host
369
	 * @param string $email_hash
370
	 * @param string $size
371
	 * @return mixed
372
	 */
373
	protected function avatar_out($default, $host, $email_hash, $size) {
374
		$out = $host . '/avatar/' . $email_hash . '?s=' . $size . '&amp;d=' . urlencode($default);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
375
		$rating = get_option('avatar_rating');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
376
		if (!empty($rating)) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
Expected 1 space before "!"; 0 found
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
377
			$out .= '&amp;r=' . $rating;
378
		}
379
		return str_replace('&#038;', '&amp;', esc_url($out));
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
380
	}
381
382
}
383