Completed
Push — master ( c61969...df1bf5 )
by Marcus
02:35
created

Field::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 3
crap 2
1
<?php
2
3
namespace Mbright\Validation\Rule\Sanitize;
4
5
class Field
6
{
7
    /**
8
     * Modifies the field value to match that of another field.
9
     *
10
     * @param object $subject The subject to be filtered.
11
     * @param string $field The subject field name.
12
     * @param string $other_field The name of the other subject field.
13
     *
14
     * @return bool True if the value was sanitized, false if not.
15
     */
16 18
    public function __invoke($subject, $field, $other_field): bool
17
    {
18
        // the other field needs to exist and *not* be null
19 18
        if (! isset($subject->$other_field)) {
20 3
            return false;
21
        }
22 15
        $subject->$field = $subject->$other_field;
23
24 15
        return true;
25
    }
26
}
27