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

Field   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 22
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 10 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