1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nicklas\Comment\Modules; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* A database driven model. |
7
|
|
|
*/ |
8
|
|
|
class Post extends ActiveRecordModelExtender |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @var string $tableName name of the database table. |
13
|
|
|
*/ |
14
|
|
|
protected $tableName = "ramverk1_posts"; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Columns in the table. |
18
|
|
|
* |
19
|
|
|
* @var integer $id primary key auto incremented. |
20
|
|
|
*/ |
21
|
|
|
public $id; |
22
|
|
|
public $user; |
23
|
|
|
public $questionId; # Connection to new Question() |
24
|
|
|
|
25
|
|
|
public $type; # question/answer |
26
|
|
|
public $text; |
27
|
|
|
|
28
|
|
|
public $created; |
29
|
|
|
|
30
|
|
|
public $di; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Returns post with markdown and gravatar |
36
|
|
|
* @param string $sql |
37
|
|
|
* @param array $param |
|
|
|
|
38
|
|
|
* |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
2 |
View Code Duplication |
public function getAllPosts($sql, $params) |
|
|
|
|
42
|
|
|
{ |
43
|
2 |
|
$posts = $this->findAllWhere("$sql", $params); |
44
|
|
|
|
45
|
2 |
|
return array_map(function ($post) { |
46
|
|
|
|
47
|
|
|
// Get e-mail for Post |
48
|
2 |
|
$user = new User($this->db); |
49
|
2 |
|
$post->img = $user->getGravatar($post->user); |
50
|
|
|
|
51
|
|
|
// Get comments for Post |
52
|
2 |
|
$comment = new Comment($this->db); |
53
|
2 |
|
$post->comments = $comment->getComments("parentId = ?", [$post->id]); |
54
|
|
|
|
55
|
|
|
// Get text |
56
|
2 |
|
$post->markdown = $this->getMD($post->text); |
57
|
|
|
|
58
|
2 |
|
return $post; |
59
|
2 |
|
}, $posts); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* return question/answer, three attributes are set, comments connected to them is an array. |
64
|
|
|
* |
65
|
|
|
* @return object |
66
|
|
|
*/ |
67
|
2 |
View Code Duplication |
public function getPost($sql, $params) |
|
|
|
|
68
|
|
|
{ |
69
|
2 |
|
$post = $this->findWhere("$sql", $params); |
70
|
|
|
|
71
|
|
|
// Get e-mail for question |
72
|
2 |
|
$user = new User($this->db); |
73
|
2 |
|
$post->img = $user->getGravatar($post->user); |
74
|
|
|
|
75
|
|
|
|
76
|
2 |
|
$comment = new Comment($this->db); |
77
|
|
|
// Start setting attributes |
78
|
2 |
|
$post->markdown = $this->getMD($post->text); |
79
|
2 |
|
$post->comments = $comment->getComments("parentId = ?", [$post->id]); |
80
|
|
|
|
81
|
2 |
|
return $post; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.