Passed
Pull Request — develop (#295)
by Peter
04:30
created

MessageBirdService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 12 2
1
<?php
2
3
/**
4
 * Copyright 2021 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
18
19
namespace Surfnet\StepupGateway\ApiBundle\Sms;
20
21
use Psr\Log\LoggerInterface;
22
use Surfnet\MessageBirdApiClient\Messaging\Message;
23
use Surfnet\MessageBirdApiClientBundle\Service\MessagingService;
24
use Surfnet\StepupGateway\ApiBundle\Dto\SmsMessage;
25
26
class MessageBirdService implements SmsAdapterInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class MessageBirdService
Loading history...
27
{
28
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
29
     * @var MessagingService
30
     */
31
    private $messagingService;
0 ignored issues
show
Coding Style introduced by
Private member variable "messagingService" must be prefixed with an underscore
Loading history...
32
33
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
34
     * @var LoggerInterface
35
     */
36
    private $logger;
0 ignored issues
show
Coding Style introduced by
Private member variable "logger" must be prefixed with an underscore
Loading history...
37
38
    public function __construct(MessagingService $messagingService, LoggerInterface $logger)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
39
    {
40
        $this->messagingService = $messagingService;
41
        $this->logger = $logger;
42
    }
43
44
    public function send(SmsMessage $message): SmsMessageResultInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function send()
Loading history...
45
    {
46
        $this->logger->notice('Using MessageBird to send an SMS');
47
48
        $message = new Message($message->originator, $message->recipient, $message->body);
49
        $result = $this->messagingService->send($message);
50
51
        if (!$result->isSuccess()) {
52
            $this->logger->warning('Sending OTP per SMS failed.');
53
        }
54
55
        return new MessageBirdMessageResult($result);
56
    }
57
}
58