Completed
Push — master ( 7266dd...4ae319 )
by Russell
04:39
created

ChainpointFullProofTask::writeFull()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
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\Cron;
9
10
use SilverStripe\CronTask\Interfaces\CronTask;
0 ignored issues
show
Bug introduced by
The type SilverStripe\CronTask\Interfaces\CronTask 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
use PhpTek\Verifiable\ORM\FieldType\ChainpointProof;
12
use SilverStripe\ORM\DataObject;
13
use SilverStripe\Core\Extensible;
14
use PhpTek\Verifiable\Verify\VerifiableExtension;
15
use SilverStripe\ORM\DataList;
16
17
/**
18
 * Assumes of course that the CronTask cron is running on the server. See README.
19
 */
20
class ChainpointFullProofTask implements CronTask
21
{
22
    use Extensible;
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function getSchedule()
28
    {
29
        return '0 1 * * *'; // 01:00 every day
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     * @throws Exception
35
     */
36
    public function process()
37
    {
38
        if (!$backend = $this->verifiableService->getBackend() === 'chainpoint') {
39
            throw new Exception(sprintf('Cannot use %s backend with %s!', $backend, __CLASS__));
0 ignored issues
show
Bug introduced by
$backend of type false is incompatible with the type string expected by parameter $args of sprintf(). ( Ignorable by Annotation )

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

39
            throw new Exception(sprintf('Cannot use %s backend with %s!', /** @scrutinizer ignore-type */ $backend, __CLASS__));
Loading history...
Bug introduced by
The type PhpTek\Verifiable\Cron\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
40
        }
41
42
        $fullProofs = $this->verifiableService->read($this->getPartials());
43
        $this->writeFull($fullProofs);
44
    }
45
46
    /**
47
     * Fetch all partial proofs, ready to make them whole again. The returned
48
     *
49
     * @return array
50
     */
51
    protected function getPartials()
52
    {
53
        // Get decorated classes
54
        $verifiableClasses = array_filter(self::get_extensions(DataObject::class), function($v) {
0 ignored issues
show
Unused Code introduced by
The assignment to $verifiableClasses is dead and can be removed.
Loading history...
55
            return $v === VerifiableExtension::class;
56
        });
57
58
        // Now fetch the relevant records, filtering on incomplete proofs
59
        DataList::create($args);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $args seems to be never defined.
Loading history...
60
    }
61
62
    /**
63
     * Takes a large JSON string, converts it to a ChainpointProof object and
64
     * updates the necessary records.
65
     *
66
     * @param  string $fullProofs
67
     * @return void
68
     */
69
    protected function writeFull($proofs)
70
    {
71
        $jsonObject = ChainpointProof::create()->setValue($proofs);
0 ignored issues
show
Unused Code introduced by
The assignment to $jsonObject is dead and can be removed.
Loading history...
72
    }
73
74
}
75