Completed
Pull Request — master (#2)
by thomas
72:23 queued 66:26
created

FullTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A random() 0 4 1
B testProcedure() 0 27 2
1
<?php
2
3
namespace Btccom\JustEncrypt\Test;
4
5
use BitWasp\Buffertools\Buffer;
6
use BitWasp\Buffertools\BufferInterface;
7
use Btccom\JustEncrypt\Encryption;
8
use Btccom\JustEncrypt\EncryptionMnemonic;
9
10
class FullTest extends AbstractTestCase
11
{
12
    /**
13
     * @param int $len
14
     * @return BufferInterface
15
     */
16
    public function random($len)
17
    {
18
        return new Buffer(random_bytes($len));
19
    }
20
21
    public function testProcedure()
22
    {
23
        $passphrase = new Buffer('FFUgnayLMUDLqpTY2bctzBvx5ckPhFt3n5VadNxyMp8XwpZ8SjVJRZpALTWaUvnE7Fru8j8GqgSzC8zdHeQxV6CM2jzL46ULQeRjPXAsVrbSSYnvW8Axrfgv');
24
        $primarySeed = $this->random(32);
25
        $secret = $this->random(32);
26
27
        $encryptedSecret = Encryption::encrypt($secret, $passphrase)->getBuffer();
28
        $this->assertTrue($secret->equals(Encryption::decrypt($encryptedSecret, $passphrase)));
0 ignored issues
show
Documentation introduced by
\Btccom\JustEncrypt\Encr...tedSecret, $passphrase) is of type object<BitWasp\Buffertools\BufferInterface>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
29
30
        $encryptedPrimarySeed = Encryption::encrypt($primarySeed, $secret)->getBuffer();
31
        $this->assertTrue($primarySeed->equals(Encryption::decrypt($encryptedPrimarySeed, $secret)));
0 ignored issues
show
Documentation introduced by
\Btccom\JustEncrypt\Encr...edPrimarySeed, $secret) is of type object<BitWasp\Buffertools\BufferInterface>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
32
33
        $recoverySecret = $this->random(32);
34
        $recoveryEncryptedSecret = Encryption::encrypt($secret, $recoverySecret)->getBuffer();
35
        $this->assertTrue($secret->equals(Encryption::decrypt($recoveryEncryptedSecret, $recoverySecret)));
0 ignored issues
show
Documentation introduced by
\Btccom\JustEncrypt\Encr...ecret, $recoverySecret) is of type object<BitWasp\Buffertools\BufferInterface>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
36
37
        $backupInfo = [
38
            'encryptedPrimarySeed' => EncryptionMnemonic::encode($encryptedPrimarySeed),
39
            'encryptedSecret' => EncryptionMnemonic::encode($encryptedSecret),
40
            'recoveryEncryptedSecret' => EncryptionMnemonic::encode($recoveryEncryptedSecret),
41
        ];
42
43
        foreach ($backupInfo as $key => $val) {
44
            $cmp = $$key;
45
            $this->assertTrue(EncryptionMnemonic::decode($val)->equals($cmp));
46
        }
47
    }
48
}
49