HasAttributes   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 31
ccs 6
cts 6
cp 1
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isJsonCastable() 0 3 1
A fromJson() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\Aranguent\Eloquent\Concerns;
6
7
trait HasAttributes
8
{
9
    /**
10
     * Determine whether a value is JSON castable for inbound manipulation.
11
     *
12
     * @param  string  $key
13
     * @return bool
14
     */
15 44
    protected function isJsonCastable($key)
16
    {
17 44
        return $this->hasCast($key, ['encrypted:array', 'encrypted:collection', 'encrypted:json', 'encrypted:object']);
0 ignored issues
show
Bug introduced by
It seems like hasCast() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
        return $this->/** @scrutinizer ignore-call */ hasCast($key, ['encrypted:array', 'encrypted:collection', 'encrypted:json', 'encrypted:object']);
Loading history...
18
    }
19
20
    /**
21
     * Decode the given JSON back into an array or object.
22
     *
23
     * @param  string  $value
24
     * @param  bool  $asObject
25
     * @return mixed
26
     *
27
     * @SuppressWarnings("PHPMD.BooleanArgumentFlag")
28
     */
29 5
    public function fromJson($value, $asObject = false)
30
    {
31
        // As data is stored as json in ArangoDB we don't have to decode it here.
32 5
        if ($asObject) {
33 1
            return (object) $value;
34
        }
35
36
        // Recursively cast objects within the value to arrays
37 4
        return mapObjectToArray($value);
38
    }
39
}
40