XmlEqualityService   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 16
c 2
b 0
f 0
dl 0
loc 46
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compare() 0 18 3
A __construct() 0 6 1
1
<?php
2
3
/**
4
 * Created by PhpStorm.
5
 * User: horat1us
6
 * Date: 5/11/17
7
 * Time: 6:18 PM
8
 */
9
10
namespace Horat1us\Services;
11
12
use Horat1us\XmlConvertibleInterface;
13
14
/**
15
 * Class XmlEqualityService
16
 * @package Horat1us\Services
17
 */
18
class XmlEqualityService
19
{
20
    /**
21
     * @var XmlConvertibleInterface
22
     */
23
    public $first;
24
25
    /**
26
     * @var XmlConvertibleInterface
27
     */
28
    public $second;
29
30
    /**
31
     * XmlEqualityService constructor.
32
     * @param XmlConvertibleInterface|null $first
33
     * @param XmlConvertibleInterface|null $second
34
     */
35 4
    public function __construct(
36
        ?XmlConvertibleInterface $first = null,
37
        ?XmlConvertibleInterface $second = null
38
    ) {
39
        $this->first = $first;
40 4
        $this->second = $second;
41 4
    }
42 4
43
    /**
44
     * @return bool
45
     */
46
    public function compare(): bool
47 4
    {
48
        if (
49
            !$this->first instanceof XmlConvertibleInterface
0 ignored issues
show
introduced by
$this->first is always a sub-type of Horat1us\XmlConvertibleInterface.
Loading history...
50 4
            || !$this->second instanceof XmlConvertibleInterface
0 ignored issues
show
introduced by
$this->second is always a sub-type of Horat1us\XmlConvertibleInterface.
Loading history...
51 4
        ) {
52
            return false;
53 1
        }
54
55
        $document = new \DOMDocument();
56 3
        $document->appendChild($this->first->toXml($document));
57 3
        $current = $document->saveXML();
58 3
59
        $document = new \DOMDocument();
60 3
        $document->appendChild($this->second->toXml($document));
61 3
        $compared = $document->saveXML();
62 3
63
        return $current === $compared;
64 3
    }
65
}
66