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

TToString::readSourceToString()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 18
rs 9.6111
ccs 9
cts 9
cp 1
cc 5
nc 4
nop 2
crap 5
1
<?php
2
3
namespace kalanis\kw_mime\Check\Traits;
4
5
6
use kalanis\kw_mime\MimeException;
7
8
9
/**
10
 * Trait TToString
11
 * @package kalanis\kw_mime\Check\Traits
12
 */
13
trait TToString
14
{
15
    use TCheckCalls;
16
17
    /**
18
     * @param string $sourcePath
19
     * @param string|resource|bool|null $sourceData
20
     * @throws MimeException
21
     * @return string
22
     */
23 6
    protected function readSourceToString(string $sourcePath, $sourceData): string
24
    {
25 6
        if ((false === $sourceData) || (null === $sourceData)) {
26 2
            throw new MimeException($this->getMiLang()->miCannotLoadFile($sourcePath));
27
28 4
        } elseif (is_resource($sourceData)) {
29 1
            rewind($sourceData);
30
31 1
            $data = stream_get_contents($sourceData, -1, 0);
32 1
            if (false === $data) {
33
                // @codeCoverageIgnoreStart
34
                throw new MimeException($this->getMiLang()->miCannotGetFilePart($sourcePath));
35
            }
36
            // @codeCoverageIgnoreEnd
37
38 1
            return $data;
39
        } else {
40 3
            return strval($sourceData);
41
        }
42
    }
43
}
44