Encrypted   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 2
A set() 0 8 2
1
<?php
2
3
4
namespace RichardStyles\EloquentEncryption\Casts;
5
6
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
7
use RichardStyles\EloquentEncryption\EloquentEncryptionFacade;
8
9
class Encrypted implements CastsAttributes
10
{
11
    /**
12
     * Cast the given value and decrypt
13
     *
14
     * @param  \Illuminate\Database\Eloquent\Model  $model
15
     * @param  string  $key
16
     * @param  mixed  $value
17
     * @param  array  $attributes
18
     * @return array
19
     */
20
    public function get($model, $key, $value, $attributes)
21
    {
22
        if(is_null($value)){
23
            return null;
24
        }
25
26
        return EloquentEncryptionFacade::decryptString($value);
27
    }
28
29
    /**
30
     * Prepare the given value for storage.
31
     *
32
     * @param  \Illuminate\Database\Eloquent\Model  $model
33
     * @param  string  $key
34
     * @param  array  $value
35
     * @param  array  $attributes
36
     * @return string
37
     */
38
    public function set($model, $key, $value, $attributes)
39
    {
40
        if(is_null($value)){
41
            return null;
42
        }
43
44
        return EloquentEncryptionFacade::encryptString($value);
0 ignored issues
show
Documentation introduced by
$value is of type array, but the function expects a string.

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...
45
    }
46
}
47