Completed
Pull Request — master (#20)
by Kevin
03:55
created

ApnsClient   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 5
dl 43
loc 43
ccs 0
cts 15
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A push() 21 21 2

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 JarvisBundle package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace LinkValue\JarvisBundle\Client;
11
12
use LinkValue\MobileNotif\Client\ApnsClient as BaseApnsClient;
13
use LinkValue\MobileNotif\Model\Message;
14
use LinkValue\JarvisBundle\Profiler\ClientProfilableTrait;
15
use LinkValue\JarvisBundle\Profiler\NullClientProfiler;
16
17
/**
18
 * Apple Push Notification Service client implementation.
19
 *
20
 * @package JarvisBundle
21
 * @author  Jamal Youssefi <[email protected]>
22
 * @author  Valentin Coulon <[email protected]>
23
 */
24 View Code Duplication
class ApnsClient extends BaseApnsClient
0 ignored issues
show
Duplication introduced by
This class 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...
25
{
26
    use ClientProfilableTrait;
27
28
    /**
29
     * Constructor.
30
     */
31
    public function __construct()
32
    {
33
        parent::__construct();
34
35
        $this->clientProfiler = new NullClientProfiler();
36
    }
37
38
    /**
39
     * Push a notification to a mobile client.
40
     *
41
     * @param Message $message
42
     *
43
     * @throws \Exception if an Exception is thrown while pushing $message.
44
     */
45
    public function push(Message $message)
46
    {
47
        $profilingEvent = $this->clientProfiler->startProfiling(sprintf('ApnsClient::push(%s)', $message->getPayloadAsJson()));
48
49
        try {
50
            parent::push($message);
51
52
            $this->clientProfiler->stopProfiling($profilingEvent, array(
53
                'error' => false,
54
                'error_message' => null,
55
            ));
56
57
        } catch (\Exception $e) {
58
            $this->clientProfiler->stopProfiling($profilingEvent, array(
59
                'error' => true,
60
                'error_message' => $e->getMessage(),
61
            ));
62
63
            throw $e;
64
        }
65
    }
66
}
67