GcmClient::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 6
loc 6
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
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\GcmClient as BaseGcmClient;
13
use LinkValue\MobileNotif\Model\Message;
14
use LinkValue\MobileNotifBundle\Profiler\ClientProfilableTrait;
15
use LinkValue\MobileNotifBundle\Profiler\NullClientProfiler;
16
17
/**
18
 * Google Cloud Messaging implementation.
19
 *
20
 * @package MobileNotifBundle
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