Completed
Push — master ( 887cf7...2ea773 )
by Emily
02:13
created

HashProducer::getHash()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
crap 12
1
<?php
2
/**
3
 * This file is part of the Composite Utils package.
4
 *
5
 * (c) Emily Shepherd <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the
8
 * LICENSE.md file that was distributed with this source code.
9
 *
10
 * @package spaark/composite-utils
11
 * @author Emily Shepherd <[email protected]>
12
 * @license MIT
13
 */
14
15
namespace Spaark\CompositeUtils\Service;
16
17
/**
18
 */
19
class HashProducer implements HashProducerInterface
20
{
21
    /**
22
     * Returns a good scalar value to use for a native PHP array
23
     *
24
     * @param KeyType $value The key to convert to a scalar
25
     * @return string Scalar value
26
     */
27
    public function getHash($value) : string
28
    {
29
        switch (gettype($value))
30
        {
31
            case 'object':
32
                return spl_object_hash($value);
33
            case 'array':
34
                return md5(serialize($value));
35
            default:
36
                return (string)$value;
37
        }
38
    }
39
}
40