StandardHashingStrategy::hash()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.8666
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 4
1
<?php
2
3
/*
4
 * This file is part of Transfer.
5
 *
6
 * For the full copyright and license information, please view the LICENSE file located
7
 * in the root directory.
8
 */
9
10
namespace Transfer\Storage\Hashing;
11
12
/**
13
 * Standard hashing strategy.
14
 */
15
class StandardHashingStrategy implements HashingStrategyInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 11
    public function hash($object)
21
    {
22 11
        if (is_object($object)) {
23 1
            return spl_object_hash($object);
24 10
        } elseif (is_string($object)) {
25 9
            return md5($object);
26 3
        } elseif (is_array($object)) {
27 2
            return md5(serialize($object));
28
        }
29
30 1
        throw new \InvalidArgumentException(sprintf('Object of type "%s" can not be hashed.', gettype($object)));
31
    }
32
}
33