Passed
Push — master ( 1a6375...8f4058 )
by Petr
08:21 queued 05:12
created

TCheckCalls::checkMimeClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
ccs 2
cts 2
cp 1
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace kalanis\kw_mime\Check\Traits;
4
5
6
use kalanis\kw_mime\MimeException;
7
8
9
/**
10
 * Trait TCheckCalls
11
 * @package kalanis\kw_mime\Check\Traits
12
 * Check some parts of the system - some things might not be available on selected instance
13
 */
14
trait TCheckCalls
15
{
16
    use TLang;
17
18
    /**
19
     * @throws MimeException
20
     */
21 4
    public function checkMimeClass(): void
22
    {
23 4
        if (!$this->isMimeClass()) {
24
            // @codeCoverageIgnoreStart
25
            throw new MimeException($this->getMiLang()->miNoClass());
26
        }
27
        // @codeCoverageIgnoreEnd
28
    }
29
30 4
    public function isMimeClass(): bool
31
    {
32 4
        return class_exists('\finfo');
33
    }
34
35
    /**
36
     * @throws MimeException
37
     */
38 6
    public function checkMimeMethod(): void
39
    {
40 6
        if (!$this->isMimeMethod()) {
41
            // @codeCoverageIgnoreStart
42
            throw new MimeException($this->getMiLang()->miNoMethod());
43
        }
44
        // @codeCoverageIgnoreEnd
45
    }
46
47 11
    public function isMimeMethod(): bool
48
    {
49 11
        return method_exists('\finfo', 'buffer');
50
    }
51
52
    /**
53
     * @throws MimeException
54
     */
55 13
    public function checkMimeFunction(): void
56
    {
57 13
        if (!$this->isMimeFunction()) {
58
            // @codeCoverageIgnoreStart
59
            throw new MimeException($this->getMiLang()->miNoFunction());
60
        }
61
        // @codeCoverageIgnoreEnd
62
    }
63
64 25
    protected function isMimeFunction(): bool
65
    {
66 25
        return function_exists('mime_content_type');
67
    }
68
}
69