FileBag   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 13
c 3
b 0
f 0
lcom 1
cbo 0
dl 0
loc 77
ccs 29
cts 29
cp 1
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 4 1
A key() 0 4 1
A next() 0 4 1
A rewind() 0 4 1
A valid() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 8 2
A offsetUnset() 0 4 1
A offsetSet() 0 14 4
1
<?php
2
3
namespace Fracture\Http;
4
5
class FileBag implements \Iterator, \ArrayAccess
6
{
7
8
    private $entries = [];
9
10
    private $current = 0;
11
12
13
    // implementing Iterator interface
14 1
    public function current()
15
    {
16 1
        return $this->entries[$this->current];
17
    }
18
19
20 1
    public function key()
21
    {
22 1
        return $this->current;
23
    }
24
25
26 1
    public function next()
27
    {
28 1
        $this->current += 1;
29 1
    }
30
31
32 2
    public function rewind()
33
    {
34 2
        $this->current = 0;
35 2
    }
36
37
38 2
    public function valid()
39
    {
40 2
        return isset($this->entries[$this->current]);
41
    }
42
43
44
    // implementing ArrayAccess interface
45 3
    public function offsetExists($offset)
46
    {
47 3
        return isset($this->entries[$offset]);
48
    }
49
50
51 3
    public function offsetSet($offset, $value)
52
    {
53
        // attempts to add invalid file in a filebag er ignored
54 3
        if (is_a($value, 'Fracture\Http\UploadedFile') === true &&
55 3
            $value->isValid() === false) {
56 1
            return;
57
        }
58
59 2
        if (is_null($offset) === true) {
60 1
            $this->entries[] = $value;
61
        } else {
62 1
            $this->entries[$offset] = $value;
63
        }
64 2
    }
65
66
67 2
    public function offsetGet($offset)
68
    {
69 2
        if (array_key_exists($offset, $this->entries)) {
70 1
            return $this->entries[$offset];
71
        }
72
73 1
        return null;
74
    }
75
76
77 2
    public function offsetUnset($offset)
78
    {
79 2
        unset($this->entries[$offset]);
80 2
    }
81
}
82