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

ManageCommentReplies   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 47.22 %

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 17
loc 36
rs 10
ccs 11
cts 11
cp 1
wmc 2
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A replyComment() 9 9 1
A deleteCommentReply() 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 ManageCommentReplies.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 ManageCommentReplies
30
{
31
    /**
32
     * Reply to a comment.
33
     *
34
     * @param int    $commentId
35
     * @param string $content
36
     *
37
     * @return \EasyWeChat\Support\Collection
38
     */
39 1 View Code Duplication
    public function replyComment($commentId, $content)
40
    {
41 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...
42 1
            'user_comment_id' => $commentId,
43 1
            'content' => $content,
44 1
        ]);
45
46 1
        return $this->parseJSON('post', [self::API_REPLY_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...
47
    }
48
49
    /**
50
     * Delete a reply.
51
     *
52
     * @param int $commentId
53
     *
54
     * @return \EasyWeChat\Support\Collection
55
     */
56 1 View Code Duplication
    public function deleteCommentReply($commentId)
57
    {
58 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...
59 1
            'user_comment_id' => $commentId,
60 1
        ]);
61
62 1
        return $this->parseJSON('post', [self::API_DELETE_REPLY, $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...
63
    }
64
}
65