Completed
Push — master ( 2f2681...17bcc4 )
by Richard
01:03
created

EncryptedFloat::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
1
<?php
2
3
4
namespace RichardStyles\EloquentEncryption\Casts;
5
6
7
class EncryptedFloat extends Encrypted
8
{
9
    /**
10
     * Cast the given value and decrypt
11
     *
12
     * @param \Illuminate\Database\Eloquent\Model $model
13
     * @param string $key
14
     * @param mixed $value
15
     * @param array $attributes
16
     * @return int
17
     */
18
    public function get($model, $key, $value, $attributes)
19
    {
20
        return $this->fromFloat(parent::get($model, $key, $value, $attributes));
21
    }
22
23
    /**
24
     * Prepare the given value for storage.
25
     *
26
     * @param \Illuminate\Database\Eloquent\Model $model
27
     * @param string $key
28
     * @param float $value
29
     * @param array $attributes
30
     * @return string
31
     */
32
    public function set($model, $key, $value, $attributes)
33
    {
34
        return parent::set($model, $key, $value, $attributes);
0 ignored issues
show
Documentation introduced by
$value is of type double, but the function expects a array.

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...
35
    }
36
37
    /**
38
     * Decode the given float.
39
     *
40
     * @param mixed $value
41
     * @return mixed
42
     */
43
    public function fromFloat($value)
44
    {
45
        switch ((string)$value) {
46
            case 'Infinity':
47
                return INF;
48
            case '-Infinity':
49
                return -INF;
50
            case 'NaN':
51
                return NAN;
52
            default:
53
                return (float)$value;
54
        }
55
    }
56
}
57