Passed
Pull Request — master (#115)
by MusikAnimal
03:31
created

ArticleInfoRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 31.11 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 14
loc 45
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getBotData() 0 17 1
A getLogEvents() 14 14 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
 * This file contains only the ArticleInfoRepository class.
4
 */
5
6
namespace Xtools;
7
8
/**
9
 * ArticleInfoRepository is responsible for retrieving data about a single
10
 * article on a given wiki.
11
 */
12
class ArticleInfoRepository extends Repository
13
{
14
    /**
15
     * Get the number of edits made to the page by bots or former bots.
16
     * @param  Page $page
17
     * @return PDOStatement resolving with keys 'count', 'username' and 'current'.
18
     */
19
    public function getBotData(Page $page)
20
    {
21
        $project = $page->getProject();
22
        $userGroupsTable = $project->getTableName('user_groups');
23
        $userFromerGroupsTable = $project->getTableName('user_former_groups');
24
        $sql = "SELECT COUNT(rev_user_text) AS count, rev_user_text AS username, ug_group AS current
25
                FROM " . $project->getTableName('revision') . "
26
                LEFT JOIN $userGroupsTable ON rev_user = ug_user
27
                LEFT JOIN $userFromerGroupsTable ON rev_user = ufg_user
28
                WHERE rev_page = :pageId AND (ug_group = 'bot' OR ufg_group = 'bot')
29
                GROUP BY rev_user_text";
30
        $pageId = $page->getId();
31
        $resultQuery = $this->getProjectsConnection()->prepare($sql);
32
        $resultQuery->bindParam('pageId', $pageId);
33
        $resultQuery->execute();
34
        return $resultQuery;
35
    }
36
37
    /**
38
     * Get prior deletions, page moves, and protections to the page.
39
     * @param  Page page
40
     * @return string[] each entry with keys 'log_action', 'log_type' and 'timestamp'.
41
     */
42 View Code Duplication
    public function getLogEvents(Page $page)
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...
43
    {
44
        $loggingTable = $page->getProject()->getTableName('logging', 'logindex');
45
        $sql = "SELECT log_action, log_type, log_timestamp AS 'timestamp'
46
                FROM $loggingTable
47
                WHERE log_namespace = '" . $page->getNamespace() . "'
48
                AND log_title = :title AND log_timestamp > 1
49
                AND log_type IN ('delete', 'move', 'protect', 'stable')";
50
        $title = str_replace(' ', '_', $page->getTitle());
51
        $resultQuery = $this->getProjectsConnection()->prepare($sql);
52
        $resultQuery->bindParam(':title', $title);
53
        $resultQuery->execute();
54
        return $resultQuery->fetchAll();
55
    }
56
}
57