StreamWrapperRegistrar   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 26
ccs 6
cts 6
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A unregisterFor() 0 6 2
A registerFor() 0 6 2
A protocol() 0 3 1
1
<?php
2
3
namespace Mpyw\StreamInterfaceResource\Registry;
4
5
use Mpyw\StreamInterfaceResource\StreamWrapper\StreamWrapper;
6
7
abstract class StreamWrapperRegistrar
8
{
9 1
    public static function registerFor(StreamRegistrarInterface $registrar): void
10
    {
11 1
        $protocol = static::protocol($registrar);
12
13 1
        if (!\in_array($protocol, \stream_get_wrappers(), true)) {
14 1
            \stream_wrapper_register($protocol, StreamWrapper::class);
15
        }
16
    }
17
18
    /**
19
     * @codeCoverageIgnore
20
     */
21
    public static function unregisterFor(StreamRegistrarInterface $registrar): void
22
    {
23
        $protocol = static::protocol($registrar);
24
25
        if (\in_array($protocol, \stream_get_wrappers(), true)) {
26
            \stream_wrapper_unregister($protocol);
27
        }
28
    }
29
30 15
    public static function protocol(StreamRegistrarInterface $registrar): string
31
    {
32 15
        return \sha1(\spl_object_hash($registrar));
33
    }
34
}
35