Completed
Pull Request — master (#17)
by Oliver
09:46
created

ApnsClient::push()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 21
Code Lines 12

Duplication

Lines 21
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 21
loc 21
rs 9.3142
cc 2
eloc 12
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the MobileNotifBundle 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\MobileNotifBundle\Client;
11
12
use LinkValue\MobileNotif\Client\ApnsClient as BaseApnsClient;
13
use LinkValue\MobileNotif\Model\Message;
14
use LinkValue\MobileNotifBundle\Profiler\ClientProfilableTrait;
15
use LinkValue\MobileNotifBundle\Profiler\NullClientProfiler;
16
17
/**
18
 * Apple Push Notification Service client implementation.
19
 *
20
 * @package MobileNotifBundle
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