Overview   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 31.58 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 0
cbo 3
dl 18
loc 57
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A returnLimitUsers() 0 7 1
B returnLimitPosts() 0 23 4
A returnAllTagsFromPost() 9 9 1
A returnPopularTags() 9 9 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\Overview;
10
11
use \Anax\DI\InjectionAwareInterface;
12
use \Anax\Di\InjectionAwareTrait;
13
use \Radchasay\User\User;
14
use \Radchasay\Comment\Post;
15
16
class Overview implements InjectionAwareInterface
17
{
18
    use InjectionAwareTrait;
19
20
    public function returnLimitUsers($db, $order, $number)
21
    {
22
        $user = new User();
23
        $user->setDb($db);
24
        $res = $user->findAllLimitOrderBy($order, $number);
25
        return $res;
26
    }
27
28
    public function returnLimitPosts($db)
29
    {
30
        $post = new Post();
31
        $post->setDb($db);
32
        $sql = "Call VPost(null, null, 'desc', null, null)";
33
        $res = $post->findAllSql($sql);
34
        $post->getNext();
35
        $id = [];
36
        $newRes = [];
37
        $limitPost = 0;
38
        foreach ($res as $r) {
39
            if ($limitPost == 5) {
40
                return $newRes;
41
            } else {
42
                if (!in_array($r->postid, $id)) {
43
                    array_push($id, $r->postid);
44
                    array_push($newRes, $r);
45
                    $limitPost++;
46
                }
47
            }
48
        }
49
        return $newRes;
50
    }
51
52 View Code Duplication
    public function returnAllTagsFromPost($db, $id)
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...
53
    {
54
        $post = new Post();
55
        $post->setDb($db);
56
        $sql = "Call VCategory(?)";
57
        $res = $post->findAllSql($sql, $id);
58
        $post->getNext();
59
        return $res;
60
    }
61
62
63 View Code Duplication
    public function returnPopularTags($db)
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...
64
    {
65
        $post = new Post();
66
        $post->setDb($db);
67
        $sql = "Call PopularTags()";
68
        $res = $post->findAllSql($sql);
69
        $post->getNext();
70
        return $res;
71
    }
72
}
73