SwiftMessageTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 68.97 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 20
loc 29
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getSwiftMessage() 20 20 4

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
namespace WShafer\PSR11MonoLog\Handler;
4
5
use WShafer\PSR11MonoLog\Exception\MissingConfigException;
6
use WShafer\PSR11MonoLog\Exception\MissingServiceException;
7
use WShafer\PSR11MonoLog\ServiceTrait;
8
9
trait SwiftMessageTrait
10
{
11
    use ServiceTrait;
12
13
    /**
14
     * @param $options
15
     * @return callable|\Swift_Message
16
     */
17 6 View Code Duplication
    public function getSwiftMessage($options)
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...
18
    {
19 6
        if (empty($options['message'])) {
20 1
            throw new MissingConfigException(
21 1
                'No message service name or callback provided'
22
            );
23
        }
24
25 5
        if (is_callable($options['message'])) {
26 1
            return $options['message'];
27
        }
28
29 4
        if (!$this->getContainer()->has($options['message'])) {
30 1
            throw new MissingServiceException(
31 1
                'No Message service found'
32
            );
33
        }
34
35 3
        return $this->getContainer()->get($options['message']);
36
    }
37
}
38