Completed
Push — master ( 058da3...8d02ae )
by Carlos
05:22 queued 02:18
created

Stats   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 83
Duplicated Lines 45.78 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 38
loc 83
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A deviceSummary() 10 10 1
A batchDeviceSummary() 9 9 1
A pageSummary() 10 10 1
A batchPageSummary() 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
/*
4
 * This file is part of the overtrue/wechat.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
/**
13
 * Stats.php.
14
 *
15
 * @author    allen05ren <[email protected]>
16
 * @copyright 2016 overtrue <[email protected]>
17
 *
18
 * @see       https://github.com/overtrue
19
 * @see       http://overtrue.me
20
 */
21
22
namespace EasyWeChat\ShakeAround;
23
24
use EasyWeChat\Core\AbstractAPI;
25
26
/**
27
 * Class Stats.
28
 */
29
class Stats extends AbstractAPI
30
{
31
    const API_DEVICE = 'https://api.weixin.qq.com/shakearound/statistics/device';
32
    const API_DEVICE_LIST = 'https://api.weixin.qq.com/shakearound/statistics/devicelist';
33
    const API_PAGE = 'https://api.weixin.qq.com/shakearound/statistics/page';
34
    const API_PAGE_LIST = 'https://api.weixin.qq.com/shakearound/statistics/pagelist';
35
36
    /**
37
     * Fetch statistics data by deviceId.
38
     *
39
     * @param array $deviceIdentifier
40
     * @param int   $beginDate        (Unix timestamp)
41
     * @param int   $endDate          (Unix timestamp)
42
     *
43
     * @return \EasyWeChat\Support\Collection
44
     */
45 1 View Code Duplication
    public function deviceSummary(array $deviceIdentifier, $beginDate, $endDate)
46
    {
47
        $params = [
48 1
            'device_identifier' => $deviceIdentifier,
49 1
            'begin_date' => $beginDate,
50 1
            'end_date' => $endDate,
51 1
        ];
52
53 1
        return $this->parseJSON('json', [self::API_DEVICE, $params]);
54
    }
55
56
    /**
57
     * Fetch all devices statistics data by date.
58
     *
59
     * @param int $timestamp
60
     * @param int $pageIndex
61
     *
62
     * @return \EasyWeChat\Support\Collection
63
     */
64 1 View Code Duplication
    public function batchDeviceSummary($timestamp, $pageIndex)
65
    {
66
        $params = [
67 1
            'date' => $timestamp,
68 1
            'page_index' => $pageIndex,
69 1
        ];
70
71 1
        return $this->parseJSON('json', [self::API_DEVICE_LIST, $params]);
72
    }
73
74
    /**
75
     * Fetch statistics data by pageId.
76
     *
77
     * @param int $pageId
78
     * @param int $beginDate (Unix timestamp)
79
     * @param int $endDate   (Unix timestamp)
80
     *
81
     * @return \EasyWeChat\Support\Collection
82
     */
83 1 View Code Duplication
    public function pageSummary($pageId, $beginDate, $endDate)
84
    {
85
        $params = [
86 1
            'page_id' => $pageId,
87 1
            'begin_date' => $beginDate,
88 1
            'end_date' => $endDate,
89 1
        ];
90
91 1
        return $this->parseJSON('json', [self::API_PAGE, $params]);
92
    }
93
94
    /**
95
     * Fetch all pages statistics data by date.
96
     *
97
     * @param int $timestamp
98
     * @param int $pageIndex
99
     *
100
     * @return \EasyWeChat\Support\Collection
101
     */
102 1 View Code Duplication
    public function batchPageSummary($timestamp, $pageIndex)
103
    {
104
        $params = [
105 1
            'date' => $timestamp,
106 1
            'page_index' => $pageIndex,
107 1
        ];
108
109 1
        return $this->parseJSON('json', [self::API_PAGE_LIST, $params]);
110
    }
111
}
112