Completed
Push — master ( bbd63b...04134d )
by Alexander
02:30
created

XmlEqualityService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A compare() 0 19 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: horat1us
5
 * Date: 5/11/17
6
 * Time: 6:18 PM
7
 */
8
9
namespace Horat1us\Services;
10
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
    {
40 4
        $this->first = $first;
41 4
        $this->second = $second;
42 4
    }
43
44 4
    public function compare(): bool
45
    {
46
        if (
47 4
            !$this->first instanceof XmlConvertibleInterface
48 4
            || !$this->second instanceof XmlConvertibleInterface
49
        ) {
50 1
            return false;
51
        }
52
53 3
        $document = new \DOMDocument();
54 3
        $document->appendChild($this->first->toXml($document));
55 3
        $current = $document->saveXML();
56
57 3
        $document = new \DOMDocument();
58 3
        $document->appendChild($this->second->toXml($document));
59 3
        $compared = $document->saveXML();
60
61 3
        return $current === $compared;
62
    }
63
}