Completed
Pull Request — 2.x (#118)
by jake
02:25
created

UploadedFileOrNull   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 26
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 12 3
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 *
8
 */
9
namespace Aura\Filter\Rule\Sanitize;
10
11
use Psr\Http\Message\UploadedFileInterface;
12
13
/**
14
 *
15
 * Sets value to null if not an uploaded file
16
 *
17
 * @package Aura.Filter
18
 *
19
 */
20
class UploadedFileOrNull
21
{
22
    /**
23
     *
24
     * Forces the value to null if not an uploaded file.
25
     *
26
     * @param object $subject The subject to be filtered.
27
     *
28
     * @param string $field The subject field name.
29
     *
30
     * @return bool True if the value was sanitized, false if not.
31
     *
32
     */
33 3
    public function __invoke($subject, $field)
34
    {
35 3
        $value = $subject->$field;
36
37
        if (! $value instanceof UploadedFileInterface
38 3
            || $value->getError() !==  UPLOAD_ERR_OK
39 3
        ) {
40 2
            $subject->$field = null;
41 2
        }
42
43 3
        return true;
44
    }
45
}
46