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

GcmClient::push()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 21
Code Lines 12

Duplication

Lines 21
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6
Metric Value
dl 21
loc 21
ccs 0
cts 11
cp 0
rs 9.3142
cc 2
eloc 12
nc 3
nop 1
crap 6
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\GcmClient as BaseGcmClient;
13
use LinkValue\MobileNotif\Model\Message;
14
use LinkValue\JarvisBundle\Profiler\ClientProfilableTrait;
15
use LinkValue\JarvisBundle\Profiler\NullClientProfiler;
16
17
/**
18
 * Google Cloud Messaging implementation.
19
 *
20
 * @package JarvisBundle
21
 * @author  Jamal Youssefi <[email protected]>
22
 * @author  Valentin Coulon <[email protected]>
23
 */
24 View Code Duplication
class GcmClient extends BaseGcmClient
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('GcmClient::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