Completed
Push — master ( a027a8...56c2be )
by Tony Karavasilev (Тони
08:06
created

ObjectHashingTrait::hashObject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
/**
4
 * Trait implementation of object hashing for digestion algorithms.
5
 */
6
7
namespace CryptoManana\Core\Traits\MessageDigestion;
8
9
use \CryptoManana\Core\Interfaces\MessageDigestion\ObjectHashingInterface as ObjectHashingSpecification;
10
use \CryptoManana\Core\Abstractions\MessageDigestion\AbstractHashAlgorithm as AnyDerivedHashAlgorithm;
11
12
/**
13
 * Trait ObjectHashingTrait - Reusable implementation of `ObjectHashingInterface`.
14
 *
15
 * @see \CryptoManana\Core\Interfaces\MessageDigestion\ObjectHashingInterface The abstract specification.
16
 *
17
 * @package CryptoManana\Core\Traits\MessageDigestion
18
 *
19
 * @mixin ObjectHashingSpecification
20
 * @mixin AnyDerivedHashAlgorithm
21
 */
22
trait ObjectHashingTrait
23
{
24
    /**
25
     * Calculates a hash value for the serialized value of the given object.
26
     *
27
     * @param object|\stdClass $object The full path and name of the file for hashing.
28
     *
29
     * @return string The digest.
30
     * @throws \Exception Validation errors.
31
     */
32 88
    public function hashObject($object)
33
    {
34 88
        if (is_object($object)) {
35 44
            $object = serialize($object);
36
        } else {
37 44
            throw new \InvalidArgumentException('The data for hashing must be an object instance.');
38
        }
39
40 44
        return $this->hashData($object);
0 ignored issues
show
Bug introduced by
It seems like hashData() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
        return $this->/** @scrutinizer ignore-call */ hashData($object);
Loading history...
41
    }
42
}
43