-
Notifications
You must be signed in to change notification settings - Fork 15
/
AtomicDiffOp.php
62 lines (54 loc) · 1.36 KB
/
AtomicDiffOp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
declare( strict_types = 1 );
namespace Diff\DiffOp;
/**
* Base class for diff operations. A diff operation
* represents a change to a single element.
*
* @since 0.1
*
* @license BSD-3-Clause
* @author Jeroen De Dauw < [email protected] >
* @author Daniel Kinzler
*/
abstract class AtomicDiffOp implements DiffOp {
/**
* @see Countable::count
*
* @since 0.1
*
* @return int
*/
public function count(): int {
return 1;
}
/**
* @see DiffOp::isAtomic
*
* @since 0.1
*
* @return bool
*/
public function isAtomic(): bool {
return true;
}
/**
* Converts an object to an array using the given callback function.
* If the convert callback is null or the value is not an object, the value is returned
* unchanged. The Converter callback is intended for converting the value into an array,
* but may also just leave the value unchanged if it cannot handle it.
*
* @since 0.5
*
* @param mixed $value The value to convert
* @param callable|null $valueConverter The converter to use if $value is an object
*
* @return mixed The $value unchanged, or the return value of calling $valueConverter on $value.
*/
protected function objectToArray( $value, $valueConverter = null ) {
if ( $valueConverter !== null && is_object( $value ) ) {
$value = call_user_func( $valueConverter, $value );
}
return $value;
}
}