Passed
Push — master ( af7542...44a008 )
by Petr
02:16
created

TToString   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 30
ccs 13
cts 14
cp 0.9286
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A toString() 0 21 6
1
<?php
2
3
namespace kalanis\kw_menu\Traits;
4
5
6
use kalanis\kw_menu\MenuException;
7
8
9
/**
10
 * Trait TToString
11
 * @package kalanis\kw_menu\Traits
12
 * Transform resource to string
13
 */
14
trait TToString
15
{
16
    use TLang;
17
18
    /**
19
     * @param mixed $content
20
     * @throws MenuException
21
     * @return string
22
     */
23 11
    protected function toString($content): string
24
    {
25 11
        if (is_null($content)) {
26 1
            throw new MenuException($this->getMnLang()->mnProblematicData());
27 10
        } elseif (is_bool($content)) {
28 2
            throw new MenuException($this->getMnLang()->mnProblematicData());
29 8
        } elseif (is_resource($content)) {
30 1
            rewind($content);
31 1
            $data = stream_get_contents($content, -1, 0);
32 1
            if (false === $data) {
33
                // @codeCoverageIgnoreStart
34
                // must die something with stream reading
35
                throw new MenuException($this->getMnLang()->mnCannotOpen());
36
            }
37
            // @codeCoverageIgnoreEnd
38 1
            return strval($data);
39
        } else {
40
            try {
41 7
                return strval($content);
42 1
            } catch (\Error $ex) {
43 1
                throw new MenuException($ex->getMessage(), $ex->getCode(), $ex);
44
            }
45
        }
46
    }
47
}
48