HasParameters   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 4
lcom 2
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setParametersAttribute() 0 8 2
A param() 0 4 1
A fluentParameters() 0 6 1
1
<?php
2
3
namespace Yajra\CMS\Entities\Traits;
4
5
trait HasParameters
6
{
7
    /**
8
     * Parameters attribute setter.
9
     *
10
     * @param array|string $parameters
11
     */
12
    public function setParametersAttribute($parameters)
13
    {
14
        if (is_array($parameters)) {
15
            $this->attributes['parameters'] = json_encode($parameters);
0 ignored issues
show
Bug introduced by
The property attributes does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
16
        } else {
17
            $this->attributes['parameters'] = $parameters;
18
        }
19
    }
20
21
    /**
22
     * Get a value in fluent parameters.
23
     *
24
     * @param string $key
25
     * @param string $default
26
     * @return mixed
27
     */
28
    public function param($key, $default = '')
29
    {
30
        return $this->fluentParameters()->get($key, $default);
31
    }
32
33
    /**
34
     * Fluent version of the entity json encoded parameters.
35
     *
36
     * @return \Illuminate\Support\Fluent
37
     */
38
    public function fluentParameters()
39
    {
40
        $parameters = $this->parameters ?? '{}';
0 ignored issues
show
Bug introduced by
The property parameters does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
41
42
        return new FluentParameters(json_decode($parameters, true));
43
    }
44
}
45