PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.6
Kubio AI Page Builder v2.8.6
2.9.0 2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / vendor / sebastian / comparator / src / ObjectComparator.php
kubio / vendor / sebastian / comparator / src Last commit date
exceptions 1 year ago ArrayComparator.php 1 year ago Comparator.php 1 year ago ComparisonFailure.php 1 year ago DOMNodeComparator.php 1 year ago DateTimeComparator.php 1 year ago DoubleComparator.php 1 year ago ExceptionComparator.php 1 year ago Factory.php 1 year ago MockObjectComparator.php 1 year ago NumericComparator.php 1 year ago ObjectComparator.php 1 year ago ResourceComparator.php 1 year ago ScalarComparator.php 1 year ago SplObjectStorageComparator.php 1 year ago TypeComparator.php 1 year ago
ObjectComparator.php
113 lines
1 <?php declare(strict_types=1);
2 /*
3 * This file is part of sebastian/comparator.
4 *
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10 namespace SebastianBergmann\Comparator;
11
12 use function get_class;
13 use function in_array;
14 use function is_object;
15 use function sprintf;
16 use function substr_replace;
17
18 /**
19 * Compares objects for equality.
20 */
21 class ObjectComparator extends ArrayComparator
22 {
23 /**
24 * Returns whether the comparator can compare two values.
25 *
26 * @param mixed $expected The first value to compare
27 * @param mixed $actual The second value to compare
28 *
29 * @return bool
30 */
31 public function accepts($expected, $actual)
32 {
33 return is_object($expected) && is_object($actual);
34 }
35
36 /**
37 * Asserts that two values are equal.
38 *
39 * @param mixed $expected First value to compare
40 * @param mixed $actual Second value to compare
41 * @param float $delta Allowed numerical distance between two values to consider them equal
42 * @param bool $canonicalize Arrays are sorted before comparison when set to true
43 * @param bool $ignoreCase Case is ignored when set to true
44 * @param array $processed List of already processed elements (used to prevent infinite recursion)
45 *
46 * @throws ComparisonFailure
47 */
48 public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false, array &$processed = [])/*: void*/
49 {
50 if (get_class($actual) !== get_class($expected)) {
51 throw new ComparisonFailure(
52 $expected,
53 $actual,
54 $this->exporter->export($expected),
55 $this->exporter->export($actual),
56 false,
57 sprintf(
58 '%s is not instance of expected class "%s".',
59 $this->exporter->export($actual),
60 get_class($expected)
61 )
62 );
63 }
64
65 // don't compare twice to allow for cyclic dependencies
66 if (in_array([$actual, $expected], $processed, true) ||
67 in_array([$expected, $actual], $processed, true)) {
68 return;
69 }
70
71 $processed[] = [$actual, $expected];
72
73 // don't compare objects if they are identical
74 // this helps to avoid the error "maximum function nesting level reached"
75 // CAUTION: this conditional clause is not tested
76 if ($actual !== $expected) {
77 try {
78 parent::assertEquals(
79 $this->toArray($expected),
80 $this->toArray($actual),
81 $delta,
82 $canonicalize,
83 $ignoreCase,
84 $processed
85 );
86 } catch (ComparisonFailure $e) {
87 throw new ComparisonFailure(
88 $expected,
89 $actual,
90 // replace "Array" with "MyClass object"
91 substr_replace($e->getExpectedAsString(), get_class($expected) . ' Object', 0, 5),
92 substr_replace($e->getActualAsString(), get_class($actual) . ' Object', 0, 5),
93 false,
94 'Failed asserting that two objects are equal.'
95 );
96 }
97 }
98 }
99
100 /**
101 * Converts an object to an array containing all of its private, protected
102 * and public properties.
103 *
104 * @param object $object
105 *
106 * @return array
107 */
108 protected function toArray($object)
109 {
110 return $this->exporter->toArray($object);
111 }
112 }
113