Passed
Push — master ( 7f61ea...38db0f )
by Russell
13:01
created

ChainpointProof   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getHashIdNode() 0 5 1
A match() 0 5 2
1
<?php
2
3
/**
4
 * @author  Russell Michell 2018 <[email protected]>
5
 * @package silverstripe-verifiable
6
 */
7
8
namespace PhpTek\Verifiable\Verify;
9
10
use PhpTek\JSONText\JSONText;
0 ignored issues
show
Bug introduced by
The type PhpTek\JSONText\JSONText was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
/**
13
 * Encapsulates a single chainpoint proof. The proof is usually derived from the
14
 * "Proof" field on a {@link DataExtension}.
15
 *
16
 * Makes use of the {@link JSONText} package and wraps simple queries around
17
 * its raw JSONQuery calls.
18
 */
19
class ChainpointProof extends JSONText
20
{
21
22
    /**
23
     * Returns the generated value of the proof's "hash_id_node" key.
24
     *
25
     * @return string
26
     */
27
    protected function getHashIdNode() : string
28
    {
29
        $this->setReturnType('json');
30
31
        return $this->query('->>', 'hash_id_node');
32
    }
33
34
    /**
35
     * Does the passed $hash match in the stored proof?
36
     *
37
     * @return boolean
38
     */
39
    public function match(string $hash) : bool
40
    {
41
        $hashFromProof = json_decode($this->getHashIdNode(), true) ?: '';
42
43
        return $hash === array_values($hashFromProof)[0];
0 ignored issues
show
Bug introduced by
It seems like $hashFromProof can also be of type string; however, parameter $input of array_values() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

43
        return $hash === array_values(/** @scrutinizer ignore-type */ $hashFromProof)[0];
Loading history...
44
    }
45
46
}
47