Passed
Pull Request — master (#3)
by Jasper
03:15
created

ModelEncrypter::getPreviousKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace Swis\Laravel\Encrypted;
4
5
use Illuminate\Contracts\Encryption\Encrypter;
6
7
/**
8
 * @deprecated only use this when migrating from this package to Laravel's built-in encrypted casting
9
 */
10
class ModelEncrypter implements Encrypter
11
{
12
    private ?Encrypter $encrypter;
13
14
    public function __construct()
15
    {
16
        $this->encrypter = app('encrypted-data.encrypter');
17
    }
18
19
    public function encrypt($value, $serialize = true)
20
    {
21
        return $this->encrypter->encrypt($value, $serialize);
0 ignored issues
show
Bug introduced by
The method encrypt() 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

21
        return $this->encrypter->/** @scrutinizer ignore-call */ encrypt($value, $serialize);

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...
22
    }
23
24
    public function decrypt($payload, $unserialize = true)
25
    {
26
        $decrypted = $this->encrypter->decrypt($payload, false);
27
28
        $unserialized = @unserialize($decrypted);
29
        if ($unserialized === false && $decrypted !== 'b:0;') {
30
            return $decrypted;
31
        }
32
33
        return $unserialized;
34
    }
35
36
    public function getKey()
37
    {
38
        return $this->encrypter->getKey();
39
    }
40
41
    public function getAllKeys()
42
    {
43
        return $this->encrypter->getAllKeys();
44
    }
45
46
    public function getPreviousKeys()
47
    {
48
        return $this->encrypter->getPreviousKeys();
49
    }
50
}
51