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

HashProducer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 21
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getHash() 0 12 3
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