Completed
Push — master ( 1035b8...a1620e )
by Albert
03:30
created

MimeType   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A test() 0 12 2
1
<?php
2
3
namespace Albert221\Validation\Rule;
4
5
use InvalidArgumentException;
6
use Psr\Http\Message\UploadedFileInterface;
7
8
class MimeType implements RuleInterface
9
{
10
    use RuleTrait;
11
12
    protected $mimeType;
13
14 3
    public function __construct($mimeType)
15
    {
16 3
        $this->message = 'This field must be of specified MIME type.';
17
18 3
        $this->mimeType = $mimeType;
19 3
    }
20
21 3
    public function test($value)
22
    {
23 3
        if (! $value instanceof UploadedFileInterface) {
24 1
            throw new InvalidArgumentException(sprintf(
25 1
                'MimeType rule excepts field of type %s, %s given.',
26 1
                UploadedFileInterface::class,
27 1
                gettype($value)
28 1
            ));
29
        }
30
31 2
        return $this->mimeType == $value->getClientMediaType();
32
    }
33
}