Completed
Push — master ( cf7247...7c3177 )
by Lars
04:07
created

KintVariableData   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 44.44%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 86
rs 10
ccs 4
cts 9
cp 0.4444

3 Methods

Rating   Name   Duplication   Size   Complexity  
A _detectEncoding() 0 4 1
A _isSequential() 0 4 1
A _substr() 0 10 3
1
<?php
2
3
namespace kint\inc;
4
5
use voku\helper\UTF8;
6
7
/**
8
 * Class KintVariableData
9
 */
10
class KintVariableData
11
{
12
  /**
13
   * @var string
14
   */
15
  public $type;
16
17
  /**
18
   * @var string
19
   */
20
  public $access;
21
22
  /**
23
   * @var string
24
   */
25
  public $name;
26
27
  /**
28
   * @var string
29
   */
30
  public $operator;
31
32
  /**
33
   * @var int
34
   */
35
  public $size;
36
37
  /**
38
   * @var kintVariableData[] array of kintVariableData objects or strings; displayed collapsed, each element from
39
   * the array is a separate possible representation of the dumped var
40
   */
41
  public $extendedValue;
42
43
  /**
44
   * @var string inline value
45
   */
46
  public $value;
47
48
  /**
49
   * @var kintVariableData[] array of alternative representations for same variable, don't use in custom parsers
50
   */
51
  public $_alternatives;
52
53
  /**
54
   * @param string $value
55
   *
56
   * @return string
57
   */
58 1
  protected static function _detectEncoding(&$value)
59
  {
60 1
    return UTF8::str_detect_encoding($value);
61
  }
62
63
  /**
64
   * returns whether the array:
65
   *  1) is numeric and
66
   *  2) in sequence starting from zero
67
   *
68
   * @param array $array
69
   *
70
   * @return bool
71
   */
72 1
  protected static function _isSequential(array &$array)
73
  {
74 1
    return array_keys($array) === range(0, count($array) - 1);
75
  }
76
77
  /**
78
   * @param      $string
79
   * @param      $start
80
   * @param      $end
81
   * @param null $encoding
82
   *
83
   * @return string
84
   */
85
  protected static function _substr($string, $start, $end, $encoding = null)
86
  {
87
    if (function_exists('mb_substr')) {
88
      $encoding or $encoding = self::_detectEncoding($string);
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...
89
90
      return mb_substr($string, $start, $end, $encoding);
91
    } else {
92
      return substr($string, $start, $end);
93
    }
94
  }
95
}
96