Completed
Push — master ( e0db1d...82088e )
by Paweł
11:28
created

PackageTopic   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 41
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A onSubscribe() 0 4 1
A onUnSubscribe() 0 4 1
A onPublish() 0 3 1
A onPush() 0 4 1
A getName() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Core Bundle.
7
 *
8
 * Copyright 2018 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2018 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\CoreBundle\WebSocket\Topic;
18
19
use Gos\Bundle\WebSocketBundle\Router\WampRequest;
20
use Gos\Bundle\WebSocketBundle\Topic\PushableTopicInterface;
21
use Gos\Bundle\WebSocketBundle\Topic\TopicInterface;
22
use Ratchet\ConnectionInterface;
23
use Ratchet\Wamp\Topic;
24
25
final class PackageTopic extends AbstractSecuredTopic implements TopicInterface, PushableTopicInterface
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function onSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request)
31
    {
32
        $topic->broadcast(['msg' => sprintf('%d connected to %s', $connection->resourceId, $topic->getId())]);
0 ignored issues
show
Bug introduced by
Accessing resourceId on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function onUnSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request)
39
    {
40
        $topic->broadcast(['msg' => sprintf('%d connected to %s', $connection->resourceId, $topic->getId())]);
0 ignored issues
show
Bug introduced by
Accessing resourceId on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function onPublish(ConnectionInterface $connection, Topic $topic, WampRequest $request, $event, array $exclude, array $eligible)
47
    {
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function onPush(Topic $topic, WampRequest $request, $data, $provider)
54
    {
55
        $topic->broadcast($data);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function getName()
62
    {
63
        return 'swp.package';
64
    }
65
}
66