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

XmlEqualityService::compare()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 2
nop 0
crap 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
}