Passed
Push — master ( 1785b4...1ac661 )
by Marcio
03:05
created

ValidateDot   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 7
c 1
b 0
f 1
dl 0
loc 78
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetExists() 0 3 1
A exists() 0 3 1
A setReference() 0 3 1
A count() 0 3 1
A all() 0 3 1
A setArray() 0 3 1
1
<?php
2
3
/**
4
 * Dot - PHP dot notation access to arrays
5
 *
6
 * @author  Riku Särkinen <[email protected]>
7
 * @link    https://github.com/adbario/php-dot-notation
8
 * @license https://github.com/adbario/php-dot-notation/blob/2.x/LICENSE.md (MIT License)
9
 */
10
11
namespace Ballybran\Core\Collections\Collection;
12
13
use Countable;
14
use ArrayIterator;
15
16
/**
17
 * Dot
18
 *
19
 * This class provides a dot notation access and helper functions for
20
 * working with arrays of data. Inspired by Laravel Collection.
21
 */
22
class ValidateDot implements Countable
23
{
24
   
25
    /**
26
     * Replace all items with a given array as a reference
27
     *
28
     * @param array $items
29
     */
30
    public function setReference(array &$items)
31
    {
32
        $this->elements = &$items;
0 ignored issues
show
Bug Best Practice introduced by
The property elements does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
33
    }
34
35
	/**
36
     * Return all the stored items
37
     *
38
     * @return array
39
     */
40
    public function all()
41
    {
42
        return $this->elements;
43
    }
44
45
46
    /**
47
     * Checks if the given key exists in the provided array.
48
     *
49
     * @param  array $array Array to validate
50
     * @param  int|string $key The key to look for
51
     *
52
     * @return bool
53
     */
54
    private function exists($array, $key)
0 ignored issues
show
Unused Code introduced by
The method exists() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
55
    {
56
        return array_key_exists($key, $array);
57
    }
58
59
   
60
      /*
61
     * --------------------------------------------------------------
62
     * ArrayAccess interface
63
     * --------------------------------------------------------------
64
     */
65
    /**
66
     * Check if a given key exists
67
     *
68
     * @param  int|string $key
69
     * @return bool
70
     */
71
    public function offsetExists($key)
72
    {
73
        return $this->has($key);
0 ignored issues
show
introduced by
The method has() does not exist on Ballybran\Core\Collections\Collection\ValidateDot. Maybe you want to declare this class abstract? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
        return $this->/** @scrutinizer ignore-call */ has($key);
Loading history...
74
    }
75
76
    /**
77
     * Replace all items with a given array
78
     *
79
     * @param mixed $items
80
     */
81
    public function setArray($items)
82
    {
83
        $this->elements = $this->getArrayItems($items);
0 ignored issues
show
Bug Best Practice introduced by
The property elements does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
introduced by
The method getArrayItems() does not exist on Ballybran\Core\Collections\Collection\ValidateDot. Maybe you want to declare this class abstract? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
        /** @scrutinizer ignore-call */ 
84
        $this->elements = $this->getArrayItems($items);
Loading history...
84
    }
85
86
    /*
87
     * --------------------------------------------------------------
88
     * Countable interface
89
     * --------------------------------------------------------------
90
     */
91
    /**
92
     * Return the number of items in a given key
93
     *
94
     * @param  int|string|null $key
95
     * @return int
96
     */
97
    public function count($key = null)
98
    {
99
        return count($this->get($key));
0 ignored issues
show
introduced by
The method get() does not exist on Ballybran\Core\Collections\Collection\ValidateDot. Maybe you want to declare this class abstract? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

99
        return count($this->/** @scrutinizer ignore-call */ get($key));
Loading history...
100
    }
101
102
103
}