Broadcast   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 35.59 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 73.91%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 5
dl 21
loc 59
ccs 17
cts 23
cp 0.7391
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 9 9 1
A send() 9 9 1
A isValidOptions() 3 15 5
A getAllowedOptionsKeys() 0 7 1

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
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Api;
6
7
use Kerox\Messenger\Exception\InvalidOptionException;
8
use Kerox\Messenger\Helper\ValidatorTrait;
9
use Kerox\Messenger\Request\BroadcastRequest;
10
use Kerox\Messenger\Response\BroadcastResponse;
11
use Kerox\Messenger\SendInterface;
12
13
/**
14
 * @deprecated Since version 3.2.0 and will be removed in version 4.0.0.
15
 */
16
class Broadcast extends AbstractApi implements SendInterface
17
{
18
    use ValidatorTrait;
19
20
    /**
21
     * @param string|\Kerox\Messenger\Model\Message $message
22
     *
23
     * @throws \Exception
24
     */
25 1 View Code Duplication
    public function create($message): BroadcastResponse
0 ignored issues
show
Duplication introduced by
This method 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...
26
    {
27 1
        $message = $this->isValidMessage($message);
28
29 1
        $request = new BroadcastRequest($this->pageToken, $message);
0 ignored issues
show
Deprecated Code introduced by
The class Kerox\Messenger\Request\BroadcastRequest has been deprecated with message: Since version 3.2.0 and will be removed in version 4.0.0.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
30 1
        $response = $this->client->post('me/message_creatives', $request->build());
31
32 1
        return new BroadcastResponse($response);
0 ignored issues
show
Deprecated Code introduced by
The class Kerox\Messenger\Response\BroadcastResponse has been deprecated with message: Since version 3.2.0 and will be removed in version 4.0.0.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
33
    }
34
35
    /**
36
     * @throws \Kerox\Messenger\Exception\MessengerException
37
     */
38 1 View Code Duplication
    public function send(string $messageCreativeId, array $options = []): BroadcastResponse
0 ignored issues
show
Duplication introduced by
This method 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...
39
    {
40 1
        $this->isValidOptions($options);
41
42 1
        $request = new BroadcastRequest($this->pageToken, null, $messageCreativeId, $options);
0 ignored issues
show
Deprecated Code introduced by
The class Kerox\Messenger\Request\BroadcastRequest has been deprecated with message: Since version 3.2.0 and will be removed in version 4.0.0.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
43 1
        $response = $this->client->post('me/broadcast_messages', $request->build());
44
45 1
        return new BroadcastResponse($response);
0 ignored issues
show
Deprecated Code introduced by
The class Kerox\Messenger\Response\BroadcastResponse has been deprecated with message: Since version 3.2.0 and will be removed in version 4.0.0.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
46
    }
47
48
    /**
49
     * @throws \Kerox\Messenger\Exception\MessengerException
50
     */
51 1
    private function isValidOptions(array $options): void
52
    {
53 1
        $allowedOptionsKeys = $this->getAllowedOptionsKeys();
54 1
        foreach ($options as $key => $value) {
55 View Code Duplication
            if (!\in_array($key, $allowedOptionsKeys, true)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
56
                throw new InvalidOptionException(sprintf('Only "%s" are allowed keys for options.', implode(', ', $allowedOptionsKeys)));
57
            }
58
59
            if ($key === self::OPTION_NOTIFICATION_TYPE) {
60
                $this->isValidNotificationType($value);
61
            } elseif ($key === self::OPTION_TAG) {
62
                $this->isValidTag($value);
63
            }
64
        }
65 1
    }
66
67 1
    private function getAllowedOptionsKeys(): array
68
    {
69
        return [
70 1
            self::OPTION_NOTIFICATION_TYPE,
71 1
            self::OPTION_TAG,
72
        ];
73
    }
74
}
75