Test Failed
Push — master ( 7e1229...8260e2 )
by Nicklas
02:49
created

Comment::getComments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Nicklas\Comment\Modules;
4
5
/**
6
 * A database driven model.
7
 */
8
class Comment extends ActiveRecordModelExtender
9
{
10
11
        /**
12
     * @var string $tableName name of the database table.
13
     */
14
    protected $tableName = "ramverk1_comments";
15
16
    /**
17
     * Columns in the table.
18
     *
19
     * @var integer $id primary key auto incremented.
20
     */
21
    public $id;
22
    public $type; # question/answer/comment
23
    public $parentId; # All posts have different ids
24
25
    public $title;
26
    public $tags;
27
    public $text;
28
29
    public $created;
30
31
    public $di;
32
33
34
    /**
35
     * Constructor injects with DI container.
36
     *
37
     */
38
    public function __construct($di = null)
39
    {
40
        $this->di = $di;
41
    }
42
    /**
43
     * Returns post with markdown and gravatar
44
     * @param string $sql
45
     * @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...
46
     *
47 5
     * @return array
48
     */
49 5
    public function getComments($sql, $params)
50 5
    {
51
        $posts = $this->findAllWhere("$sql", $params);
52
53
        return array_map(function ($post) {
54
            $user = new User();
55
            $user->setDb($this->di->get("db"));
56
            $user->find("name", $post->user);
57
58 4
59
            $post->comments = $this->getPosts("parentId = ? AND type = ?", [$post->id, "comment"]);
0 ignored issues
show
Bug introduced by
The method getPosts() does not seem to exist on object<Nicklas\Comment\Modules\Comment>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60 4
            $post->tags = explode(',', $post->tags);
61
62 4
            $post->img = $this->gravatar($user->email);
63 4
            $post->markdown = $this->getMD($post->text);
64 4
65 4
            return $post;
66
        }, $posts);
67
    }
68
}
69