Passed
Push — master ( 2ce6bc...9c94e5 )
by Russell
11:27
created

BackendVerificationJob::getHash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @author  Russell Michell 2018 <[email protected]>
5
 * @package silverstripe-verifiable
6
 */
7
8
namespace PhpTek\Verifiable\Job;
9
10
use Symbiote\QueuedJobs\Services\AbstractQueuedJob;
11
12
/**
13
 * Simple job to periodically fetch a full chainpoint proof from the backend.
14
 * On success receive and save the returned, full chainpoint proof. Once a proof
15
 * is saved, this job is considered to be complete.
16
 *
17
 * @todo Using the Tierion REST API, we can submit "Blockscriptions" where a callback
18
 * URL is called by the network itself when a ChainPoint proof is ready. Is there
19
 * anything similar in the Chainpoint API?
20
 * @todo Ensure this job does not create a copy of itself, if the proof-save
21
 * is successful.
22
 */
23
class BackendVerificationJob extends AbstractQueuedJob
24
{
25
    /**
26
     * @return string
27
     */
28
    public function getTitle() : string
29
    {
30
        return 'Chainpoint Full Proof Fetch Job';
31
    }
32
33
    /**
34
     * @return string
35
     */
36
    public function getJobType()
37
    {
38
        return QueuedJob::IMMEDIATE;
0 ignored issues
show
Bug introduced by
The type PhpTek\Verifiable\Job\QueuedJob 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...
39
    }
40
41
    /**
42
     * Do the work to ping the remote backend.
43
     *
44
     * @return void
45
     * @todo Prevent a new job being created
46
     */
47
    public function process()
48
    {
49
        $proof = $this->getObject()->dbObject('Proof');
50
        $savedHash = $proof->getHashNodeId();
0 ignored issues
show
Bug introduced by
The method getHashNodeId() does not exist on SilverStripe\ORM\FieldType\DBField. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

50
        /** @scrutinizer ignore-call */ 
51
        $savedHash = $proof->getHashNodeId();
Loading history...
51
        $body = $this->verifiableService->read($savedHash);
0 ignored issues
show
Bug Best Practice introduced by
The property verifiableService does not exist on PhpTek\Verifiable\Job\BackendVerificationJob. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
The method read() does not exist on null. ( Ignorable by Annotation )

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

51
        /** @scrutinizer ignore-call */ 
52
        $body = $this->verifiableService->read($savedHash);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
53
        if ($proof->isComplete($body)) {
0 ignored issues
show
Bug introduced by
The method isComplete() does not exist on SilverStripe\ORM\FieldType\DBField. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

53
        if ($proof->/** @scrutinizer ignore-call */ isComplete($body)) {
Loading history...
54
            $this->getObject()->setField('Proof', $body)->write();
55
            $this->isComplete = true;
56
        }
57
    }
58
59
}
60