Completed
Push — master ( 9eb354...1c75bc )
by Bocharsky
02:10
created

CallbackNamingStrategy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 4
c 4
b 1
f 1
lcom 1
cbo 1
dl 0
loc 40
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getCallback() 0 4 1
A provideName() 0 13 2
1
<?php
2
3
namespace FileNamingResolver\NamingStrategy;
4
5
use FileNamingResolver\FileInfo;
6
7
/**
8
 * @author Victor Bocharsky <[email protected]>
9
 */
10
class CallbackNamingStrategy extends AbstractNamingStrategy
11
{
12
    /**
13
     * @var \Closure
14
     */
15
    protected $callback;
16
17
    /**
18
     * @param \Closure $callback
19
     */
20 4
    public function __construct(\Closure $callback)
21
    {
22 4
        $this->callback = $callback;
23 4
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 3
    public function provideName(FileInfo $srcFileInfo)
29
    {
30 3
        $func = $this->callback;
31
32 3
        $dstFileInfo = $func($srcFileInfo);
33 3
        if (!$dstFileInfo instanceof FileInfo) {
34 1
            throw new \RuntimeException(
35 1
                sprintf('Callback naming strategy should return an instance of FileNamingResolver\FileInfo class')
36 1
            );
37
        }
38
39 2
        return $dstFileInfo;
40
    }
41
42
    /**
43
     * @return \Closure
44
     */
45 1
    public function getCallback()
46
    {
47 1
        return $this->callback;
48
    }
49
}
50