Completed
Push — master ( 3c84ea...366ddd )
by Lars
02:25
created

KintVariableData::_isSequential()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
eloc 2
nc 1
nop 1
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 2
  protected static function _detectEncoding(&$value)
59
  {
60 2
    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 2
  protected static function _isSequential(array &$array)
73
  {
74 2
    return array_keys($array) === range(0, count($array) - 1);
75
  }
76
77
  /**
78
   * Get part of string
79
   *
80
   * @param string $string   <p>
81
   *                         The string being checked.
82
   *                         </p>
83
   * @param int    $start    <p>
84
   *                         The first position used in str.
85
   *                         </p>
86
   * @param int    $end      [optional] <p>
87
   *                         The maximum length of the returned string.
88
   *                         </p>
89
   * @param string $encoding [optional] &mbstring.encoding.parameter;
90
   *
91
   * @return string
92
   */
93
  protected static function _substr($string, $start, $end = null, $encoding = null)
94
  {
95
    if (!$encoding) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $encoding of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
96
      $encoding = self::_detectEncoding($string);
97
    }
98
99
    return mb_substr($string, $start, $end, $encoding);
100
  }
101
}
102