Passed
Push — master ( 75af5b...7c734b )
by Nicklas
02:14
created

Post::getAllPosts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
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
    public $accepted; # default "no"
25
26
    public $type; # question/answer
27
    public $text;
28
29
    public $created;
30
31
    public $di;
32
33
34
    /**
35
     * Set ups the question
36
     * @param object $question
0 ignored issues
show
Bug introduced by
There is no parameter named $question. 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...
37
     * @param array $param
0 ignored issues
show
Bug introduced by
There is no parameter named $param. 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...
38
     *
39
     * @return object
40
     */
41 8
    public function setupPost($post)
42
    {
43
44 8
        $user = new User($this->db);
45 8
        $comment = new Comment($this->db);
46 8
        $vote = new Vote($this->db);
47
48 8
        $post->img      = $user->getGravatar($post->user);
49 8
        $post->comments = $comment->getComments("parentId = ?", [$post->id]);
50 8
        $post->vote     = $vote->getVote("parentId = ? AND parentType = ?", [$post->id, "post"]);
51 8
        $post->markdown = $this->getMD($post->text);
52
53 8
        return $post;
54
    }
55
56
    /**
57
     * Returns post with markdown and gravatar
58
     * @param string $sql
59
     * @param array $param
0 ignored issues
show
Documentation introduced by
There is no parameter named $param. Did you maybe mean $params?

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 method finale(...).

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

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

Loading history...
60
     *
61
     * @return array
62
     */
63 9
    public function getAllPosts($sql, $params)
64
    {
65 9
        $posts = $this->findAllWhere("$sql", $params);
66
67
        // array_reverse so latest order question gets returned
68 9
        return array_map(array($this, 'setupPost'), $posts);
69
    }
70
71
    /**
72
     * return question/answer, three attributes are set, comments connected to them is an array.
73
     *
74
     * @return object
75
    */
76 8
    public function getPost($sql, $params)
77
    {
78 8
        $post = $this->findWhere("$sql", $params);
79 8
        return $post->setupPost($post);
0 ignored issues
show
Bug introduced by
The method setupPost cannot be called on $post (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
80
    }
81
}
82