LaravelFallbackInterface   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fallbackGet() 0 4 1
A fallbackHas() 0 9 3
1
<?php namespace jlourenco\support\Interfaces;
2
3
/**
4
 * Class LaravelFallbackInterface
5
 * @package Philf\Setting\interfaces
6
 */
7
class LaravelFallbackInterface implements FallbackInterface
8
{
9
10
    /**
11
     * @param $key
12
     * @return mixed
13
     */
14
    public function fallbackGet($key, $default = null)
15
    {
16
        return \App::make('config')->get($key, $default);
17
    }
18
19
    /**
20
     * @param $key
21
     * @return bool
22
     */
23
    public function fallbackHas($key)
24
    {
25
        $settingExists = \App::make('config')->has($key);
26
        $setting = \App::make('config')->get($key);
27
        if (is_array($setting) and count($setting) == 0) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and 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...
28
            return false;
29
        }
30
        return $settingExists;
31
    }
32
33
}