Passed
Push — master ( 9c4857...eecc1f )
by Russell
02:55
created

VerifiableExtension::__construct()   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\Verify;
9
10
use SilverStripe\Core\DataExtension;
0 ignored issues
show
Bug introduced by
The type SilverStripe\Core\DataExtension 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
 * Attach to any {@link DataObject} subclass, including {@link SiteTree} subclasses,
14
 * and all applicable database writes will be passed through here.
15
 */
16
class VerifiableExtension extends DataExtension
17
{
18
    /**
19
     * @var array
20
     * @config
21
     */
22
    private static $verifiable_fields = [];
0 ignored issues
show
introduced by
The private property $verifiable_fields is not used, and could be removed.
Loading history...
23
24
    /**
25
     * @var  Verifiable
26
     * @todo Should prob be nailed-in, in config as a dependency.
27
     */
28
    protected $verifiable;
29
30
    /**
31
     * @return void
32
     */
33
    public function __construct()
34
    {
35
        $this->verifiable = Verifiable::create()->setModel($this->getOwner());
36
    }
37
38
    /**
39
     * After each write, hash the desired fields and submit to the current backend.
40
     *
41
     * @return void
42
     */
43
    public function onAfterWrite()
44
    {
45
        $this->verifiable->write();
46
    }
47
48
    /**
49
     * Return the data in the backend referenced by $hash. If no data
50
     * is found, returns an empty array.
51
     *
52
     * @param  string $hash
53
     * @return mixed boolean | array
54
     */
55
    public function read(string $hash) : array
56
    {
57
        return $this->verifiable->read($hash);
58
    }
59
60
}
61
62