Post   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 74
Duplicated Lines 20.27 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 8.57%

Importance

Changes 0
Metric Value
wmc 10
c 0
b 0
f 0
lcom 1
cbo 1
dl 15
loc 74
ccs 3
cts 35
cp 0.0857
rs 10

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 8 1
A getTags() 0 7 1
A getAllPosts() 15 15 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 = "Call VPost('true', ?, null, null, null)";
53
        $res = $this->findAllSql($sql, $params);
54
        $this->getNext();
55
        return $res;
56
    }
57
58
    public function getTags($params)
59
    {
60
        $sql = "Call VCategory(?)";
61
        $res = $this->findAllSql($sql, $params);
62
        $this->getNext();
63
        return $res;
64
    }
65
66 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...
67
    {
68
        $sql = "Call VPost(null, null, null, null, null)";
69
        $res = $this->findAllSql($sql);
70
        $this->getNext();
71
        $id = [];
72
        $newRes = [];
73
        foreach ($res as $r) {
74
            if (!in_array($r->postid, $id)) {
75
                array_push($id, $r->postid);
76
                array_push($newRes, $r);
77
            }
78
        }
79
        return $newRes;
80
    }
81
82
    public function getNext()
83
    {
84
        return $this->next();
85
    }
86
}
87