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

TrillianPersonality   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A write() 0 2 1
A name() 0 3 1
A validate() 0 7 3
A read() 0 2 1
A connect() 0 2 1
1
<?php
2
3
/**
4
 * @author  Russell MIchell 2018 <[email protected]>
5
 * @package silverstripe-verifiable
6
 */
7
8
namespace PhpTek\Verifiable\Backend;
9
10
use PhpTek\Verifiable\Backend\BackendProvider;
0 ignored issues
show
Bug introduced by
The type PhpTek\Verifiable\Backend\BackendProvider 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\Verifiable;
12
use PhpTek\Verifiable\Exception\VerifiableValidationException;
13
14
/**
15
 * Trillian relies on something called a "Personality" to supply it with the exact
16
 * type and format of data, that the overall application is expecting it to store.
17
 * As such Trillian itself will perform no data validation or normalisation, favouring
18
 * instead to farm out this responsibility to personalities.
19
 */
20
class TrillianPersonality implements BackendProvider
21
{
22
    /**
23
     *
24
     * {@inheritdoc}
25
     */
26
    public function name() : string
27
    {
28
        return 'trillian';
29
    }
30
31
    /**
32
     *
33
     * {@inheritdoc}
34
     */
35
    public function connect() : bool
36
    {
37
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
38
39
    /**
40
     *
41
     * {@inheritdoc}
42
     */
43
    public function read(string $hash) : array
44
    {
45
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return array. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
46
47
    /**
48
     *
49
     * {@inheritdoc}
50
     */
51
    public function write(string $hash) : string
52
    {
53
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
54
55
    /**
56
     * @param  string $data                  The data to be verified
57
     * @throws VerifiableValidationException In the event invalid data is detected
58
     *                                       Sure-fire way to prevent a malformed
59
     *                                       write to the backend.
60
     * @return void
61
     * @todo   Implement a dedicated hash-specific handler
62
     */
63
    public function validate(string $data)
64
    {
65
        $func = Verifiable::config()->get('hash_func');
66
67
        if ($func == 'sha1') {
68
            if (strlen($data) !== 40) {
69
                throw new VerifiableValidationException(sprintf('Invalid %s hash: Length', $func));
70
            }
71
        }
72
    }
73
74
}
75