Completed
Pull Request — master (#716)
by mingyoung
03:01
created

ManageComments   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 90
Duplicated Lines 37.78 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 34
loc 90
rs 10
ccs 26
cts 26
cp 1
wmc 6
lcom 0
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A openComment() 0 4 1
A closeComment() 0 4 1
A comments() 10 10 1
A markElectComment() 8 8 1
A unmarkElectComment() 8 8 1
A deleteComment() 8 8 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
 * Trait ManageComments.php.
14
 *
15
 * Part of Overtrue\WeChat.
16
 *
17
 * For the full copyright and license information, please view the LICENSE
18
 * file that was distributed with this source code.
19
 *
20
 * @author    mingyoung <[email protected]>
21
 * @copyright 2017
22
 *
23
 * @see      https://github.com/overtrue
24
 * @see      http://overtrue.me
25
 */
26
27
namespace EasyWeChat\MediaPress;
28
29
trait ManageComments
30
{
31
    /**
32
     * Open article comment.
33
     *
34
     * @return \EasyWeChat\Support\Collection
35
     */
36 1
    public function openComment()
37
    {
38 1
        return $this->parseJSON('post', [self::API_OPEN_COMMENT, $this->mediaPress()]);
0 ignored issues
show
Bug introduced by
It seems like mediaPress() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Bug introduced by
It seems like parseJSON() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
39
    }
40
41
    /**
42
     * Close comment.
43
     *
44
     * @return \EasyWeChat\Support\Collection
45
     */
46 1
    public function closeComment()
47
    {
48 1
        return $this->parseJSON('post', [self::API_CLOSE_COMMENT, $this->mediaPress()]);
0 ignored issues
show
Bug introduced by
It seems like mediaPress() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Bug introduced by
It seems like parseJSON() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
49
    }
50
51
    /**
52
     * Get article comments.
53
     *
54
     * @param int $begin
55
     * @param int $count
56
     * @param int $type
57
     *
58
     * @return \EasyWeChat\Support\Collection
59
     */
60 1 View Code Duplication
    public function comments($begin, $count, $type = 0)
61
    {
62 1
        $params = array_merge($this->mediaPress(), [
0 ignored issues
show
Bug introduced by
It seems like mediaPress() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
63 1
            'begin' => $begin,
64 1
            'count' => $count,
65 1
            'type' => $type,
66 1
        ]);
67
68 1
        return $this->parseJSON('post', [self::API_LIST_COMMENT, $params]);
0 ignored issues
show
Bug introduced by
It seems like parseJSON() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
69
    }
70
71
    /**
72
     * Mark elect comment.
73
     *
74
     * @param int $commentId
75
     *
76
     * @return \EasyWeChat\Support\Collection
77
     */
78 1 View Code Duplication
    public function markElectComment($commentId)
79
    {
80 1
        $params = array_merge($this->mediaPress(), [
0 ignored issues
show
Bug introduced by
It seems like mediaPress() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
81 1
            'user_comment_id' => $commentId,
82 1
        ]);
83
84 1
        return $this->parseJSON('post', [self::API_MARK_ELECT, $params]);
0 ignored issues
show
Bug introduced by
It seems like parseJSON() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
85
    }
86
87
    /**
88
     * Unmark comment elect.
89
     *
90
     * @param int $commentId
91
     *
92
     * @return \EasyWeChat\Support\Collection
93
     */
94 1 View Code Duplication
    public function unmarkElectComment($commentId)
95
    {
96 1
        $params = array_merge($this->mediaPress(), [
0 ignored issues
show
Bug introduced by
It seems like mediaPress() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
97 1
            'user_comment_id' => $commentId,
98 1
        ]);
99
100 1
        return $this->parseJSON('post', [self::API_UNMARK_ELECT, $params]);
0 ignored issues
show
Bug introduced by
It seems like parseJSON() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
101
    }
102
103
    /**
104
     * Delete comment.
105
     *
106
     * @param int $commentId
107
     *
108
     * @return \EasyWeChat\Support\Collection
109
     */
110 1 View Code Duplication
    public function deleteComment($commentId)
111
    {
112 1
        $params = array_merge($this->mediaPress(), [
0 ignored issues
show
Bug introduced by
It seems like mediaPress() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
113 1
            'user_comment_id' => $commentId,
114 1
        ]);
115
116 1
        return $this->parseJSON('post', [self::API_DELETE_COMMENT, $params]);
0 ignored issues
show
Bug introduced by
It seems like parseJSON() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
117
    }
118
}
119