StreamWrapperRegistrar::unregisterFor()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
ccs 0
cts 0
cp 0
crap 6
rs 10
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