Issues (13)

src/Services/XmlEqualityService.php (2 issues)

Severity
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
$this->first is always a sub-type of Horat1us\XmlConvertibleInterface.
Loading history...
50 4
            || !$this->second instanceof XmlConvertibleInterface
0 ignored issues
show
$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