CommonTestClass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 32
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fullPath() 0 3 1
A sortingPaths() 0 3 1
A streamToString() 0 4 1
A stringToStream() 0 6 1
1
<?php
2
3
use kalanis\kw_files\Node;
4
use PHPUnit\Framework\TestCase;
5
6
7
/**
8
 * Class CommonTestClass
9
 * The structure for mocking and configuration seems so complicated, but it's necessary to let it be totally idiot-proof
10
 */
11
class CommonTestClass extends TestCase
12
{
13
    public function sortingPaths(Node $a, Node $b): int
14
    {
15
        return $this->fullPath($a) <=> $this->fullPath($b);
16
    }
17
18
    protected function fullPath(Node $node): string
19
    {
20
        return implode(DIRECTORY_SEPARATOR, $node->getPath());
21
    }
22
23
    /**
24
     * @param resource $content
25
     * @return string
26
     */
27
    protected function streamToString($content): string
28
    {
29
        rewind($content);
30
        return strval(stream_get_contents($content, -1, 0));
31
    }
32
33
    /**
34
     * @param string $content
35
     * @return resource
36
     */
37
    protected function stringToStream(string $content)
38
    {
39
        $handle = fopen('php://memory', 'rb+');
40
        fwrite($handle, $content);
41
        rewind($handle);
42
        return $handle;
43
    }
44
}
45