StreamWrapperRegistrar::protocol()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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