SystemSetting   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getValueAttribute() 0 4 1
A setValueAttribute() 0 8 3
1
<?php
2
3
/*
4
 * This file is part of ibrand/setting.
5
 *
6
 * (c) iBrand <https://www.ibrand.cc>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace iBrand\Component\Setting\Models;
13
14
use Illuminate\Database\Eloquent\Model;
15
16
/**
17
 * Class SystemSetting
18
 * @package iBrand\Component\Setting\Models
19
 */
20
class SystemSetting extends Model
21
{
22
23
    /**
24
     * @var array
25
     */
26
    protected $guarded = ['id'];
27
28
    /**
29
     * SystemSetting constructor.
30
     * @param array $attributes
31
     */
32 7
    public function __construct(array $attributes = [])
33
    {
34 7
        parent::__construct($attributes);
35
36 7
        $this->setTable(config('ibrand.setting.table_name'));
37 7
    }
38
39
    /**
40
     * @param $value
41
     * @return mixed|string
42
     */
43 6
    public function getValueAttribute($value)
44
    {
45 6
        return json_decode($value, true);
46
    }
47
48
    /**
49
     * @param $value
50
     * @return string
51
     */
52 6
    public function setValueAttribute($value)
53
    {
54 6
        if ($value or 0 == $value) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
55 6
            $this->attributes['value'] = json_encode($value);
56
        }
57
58 6
        return '';
59
    }
60
}
61