Message   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 24.24 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 8
loc 33
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getBody() 0 4 1
A setBody() 0 7 2
A bodyPredicate() 8 8 2

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
 * Nucleus - XMPP Library for PHP
4
 *
5
 * Copyright (C) 2017, Some rights reserved.
6
 *
7
 * @author Kacper "Kadet" Donat <[email protected]>
8
 *
9
 * Contact with author:
10
 * Xmpp: [email protected]
11
 * E-mail: [email protected]
12
 *
13
 * From Kadet with love.
14
 */
15
16
namespace Kadet\Xmpp\Stanza;
17
18
19
use Kadet\Xmpp\Stanza\Message\Body;
20
use Kadet\Xmpp\Xml\XmlElement;
21
use function Kadet\Xmpp\Utils\filter\all;
22
use function Kadet\Xmpp\Utils\filter\element\{
23
    attribute, name
24
};
25
26
class Message extends Stanza
27
{
28
    /**
29
     * Message constructor.
30
     * @param array $options
31
     */
32 4
    public function __construct($options = [])
33
    {
34 4
        parent::__construct('message', $options);
35 4
    }
36
37 1
    public function getBody($language = null)
38
    {
39 1
        return $this->get($this->bodyPredicate($language))->innerXml ?? null;
40
    }
41
42 2
    public function setBody($content, $language = null)
43
    {
44 2
        $body = $this->get($this->bodyPredicate($language))
45 2
             ?: $this->append(new Body($language)); // todo: Body class
46
47 2
        $body->setContent($content);
48 2
    }
49
50 3 View Code Duplication
    private function bodyPredicate($language) {
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...
51 3
        $predicate = name('body');
52 3
        if($language !== null) {
53 1
            $predicate = all($predicate, attribute('lang', $language, XmlElement::XML));
54
        }
55
56 3
        return $predicate;
57
    }
58
}