Completed
Push — master ( 8ffaa6...f544e7 )
by Nicklas
02:28
created

Post::getPost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 16
loc 16
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
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
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
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...
38
     *
39
     * @return array
40
     */
41 2 View Code Duplication
    public function getAllPosts($sql, $params)
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...
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)
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...
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