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

Overview::returnLimitPosts()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 0
cts 18
cp 0
rs 8.9197
c 0
b 0
f 0
cc 4
eloc 17
nc 4
nop 1
crap 20
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 = "SELECT * FROM VPost ORDER BY postid DESC";
33
        $res = $post->findAllSql($sql);
34
        $id = [];
35
        $newRes = [];
36
        $limitPost = 0;
37
        foreach ($res as $r) {
38
            if ($limitPost == 5) {
39
                return $newRes;
40
            } else {
41
                if (!in_array($r->postid, $id)) {
42
                    array_push($id, $r->postid);
43
                    array_push($newRes, $r);
44
                    $limitPost++;
45
                }
46
            }
47
        }
48
        return $newRes;
49
    }
50
51 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...
52
    {
53
        $post = new Post();
54
        $post->setDb($db);
55
        $sql = "SELECT Category FROM VCategory WHERE postid = ?";
56
        $res = $post->findAllSql($sql, $id);
57
        return $res;
58
    }
59
60
61 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...
62
    {
63
        $post = new Post();
64
        $post->setDb($db);
65
        $sql = "SELECT catid, count(catid) as count FROM Post2Cat GROUP BY catid order by count desc LIMIT 5";
66
        $res = $post->findAllSql($sql);
67
        return $res;
68
    }
69
}
70