Passed
Push — master ( 76fde7...d6d75c )
by Magnus
01:55
created

Post   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 71
Duplicated Lines 19.72 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 9.38%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 14
loc 71
ccs 3
cts 32
cp 0.0938
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getInformation() 0 5 1
A getAllInformationWhere() 0 5 1
A checkId() 0 5 2
A getPostInfo() 0 7 1
A getTags() 0 6 1
A getAllPosts() 14 14 3
A getNext() 0 4 1

How to fix   Duplicated Code   

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:

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: root
5
 * Date: 2017-09-27
6
 * Time: 10:27
7
 */
8
9
namespace Radchasay\Comment;
10
11
use \Anax\Database\ActiveRecordModel;
12
13
class Post extends ActiveRecordModel
14
{
15
16
    /**
17
     * @var string $tableName name of the database table.
18
     */
19
    protected $tableName = "Posts";
20
21
    /**
22
     * Columns in the table.
23
     *
24
     * @var integer $id primary key auto incremented.
25
     */
26
    public $id;
27
    public $posttitle;
28
    public $postname;
29
    public $posttext;
30
31 1
    public function getInformation($name)
32
    {
33 1
        $res = $this->find("postname", $name);
34 1
        return $res;
35
    }
36
37
    public function getAllInformationWhere($name)
38
    {
39
        $res = $this->findAllWhere("postname = ?", $name);
40
        return $res;
41
    }
42
43
    public function checkId($id)
44
    {
45
        $row = $this->find("id", $id);
46
        return !$row ? false : true;
47
    }
48
49
    public function getPostInfo($params)
50
    {
51
        $this->getNext();
52
        $sql = "SELECT * FROM VPost WHERE postid = ?";
53
        $res = $this->findAllSql($sql, $params);
54
        return $res;
55
    }
56
57
    public function getTags($params)
58
    {
59
        $sql = "SELECT Category FROM VCategory WHERE postid = ?";
60
        $res = $this->findAllSql($sql, $params);
61
        return $res;
62
    }
63
64 View Code Duplication
    public function getAllPosts()
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...
65
    {
66
        $sql = "SELECT * FROM VPost";
67
        $res = $this->findAllSql($sql);
68
        $id = [];
69
        $newRes = [];
70
        foreach ($res as $r) {
71
            if (!in_array($r->postid, $id)) {
72
                array_push($id, $r->postid);
73
                array_push($newRes, $r);
74
            }
75
        }
76
        return $newRes;
77
    }
78
79
    public function getNext()
80
    {
81
        return $this->next();
82
    }
83
}
84