Completed
Push — master ( d66148...249642 )
by Bocharsky
02:35
created

ContentHashNamingStrategy::provideName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
crap 2
1
<?php
2
3
namespace FileNamingResolver\NamingStrategy;
4
5
use FileNamingResolver\FileInfo;
6
7
/**
8
 * @author Victor Bocharsky <[email protected]>
9
 */
10
class ContentHashNamingStrategy extends AbstractHashNamingStrategy
11
{
12
    /**
13
     * {@inheritdoc}
14
     *
15
     * @throws \InvalidArgumentException If source file does not exist
16
     */
17 2
    public function provideName(FileInfo $srcFileInfo)
18
    {
19 2
        if (!$srcFileInfo->isFile()) {
20 1
            throw new \InvalidArgumentException(sprintf(
21 1
                'The source file does not exist on "%s" specified path.',
22 1
                $srcFileInfo->toString()
23 1
            ));
24
        }
25 1
        $hash = hash_file($this->algorithm, $srcFileInfo->toString());
26
27 1
        $dstFileInfo = $this->provideNameByHash($srcFileInfo, $hash);
28
29 1
        return $dstFileInfo;
30
    }
31
}
32