Passed
Push — master ( 0b0ee1...9503f0 )
by Petr
06:38 queued 03:11
created

StorageTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A MockArray::getKey() 0 3 1
1
<?php
2
3
use kalanis\kw_forms\Adapters\AAdapter;
4
use kalanis\kw_forms\Adapters\FilesAdapter;
5
use PHPUnit\Framework\TestCase;
6
7
8
class CommonTestClass extends TestCase
9
{
10
}
11
12
13
class MockArray implements ArrayAccess, Countable, Iterator
14
{
15
    protected $key = null;
16
    protected $vars = [];
17
18
    public function getKey(): string
19
    {
20
        return $this->key;
21
    }
22
23
    public function getValue()
24
    {
25
        return $this->current();
26
    }
27
28
    public function current()
29
    {
30
        return $this->valid() ? $this->offsetGet($this->key) : null ;
31
    }
32
33
    public function next()
34
    {
35
        next($this->vars);
36
        $this->key = key($this->vars);
37
    }
38
39
    public function key()
40
    {
41
        return $this->key;
42
    }
43
44
    public function valid()
45
    {
46
        return $this->offsetExists($this->key);
47
    }
48
49
    public function rewind()
50
    {
51
        reset($this->vars);
52
        $this->key = key($this->vars);
53
    }
54
55
    public function offsetExists($offset)
56
    {
57
        return isset($this->vars[$offset]);
58
    }
59
60
    public function offsetGet($offset)
61
    {
62
        return $this->vars[$offset];
63
    }
64
65
    public function offsetSet($offset, $value)
66
    {
67
        $this->vars[$offset] = $value;
68
    }
69
70
    public function offsetUnset($offset)
71
    {
72
        unset($this->vars[$offset]);
73
    }
74
75
    public function count()
76
    {
77
        return count($this->vars);
78
    }
79
}
80
81
82
class Adapter extends AAdapter
83
{
84
    protected $vars = [
85
        'foo' => 'aff',
86
        'bar' => 'poa',
87
        'baz' => 'cdd',
88
        'sgg' => 'arr',
89
        'sdsrs' => 'ggsd<$=#,\'',
90
        'dsrsd' => 'zfd?-.!>"',
91
        'dg-[]' => 'dc^&#~\\€`~°',
92
        'dg[]' => '<?php =!@#dc^&#~',
93
    ];
94
95
    public function loadEntries(string $inputType): void
96
    {
97
        $entry = new \kalanis\kw_input\Entries\Entry();
98
        $entry->setEntry(\kalanis\kw_input\Interfaces\IEntry::SOURCE_EXTERNAL, 'xggxgx', 'lkjhdf');
99
        $this->vars['xggxgx'] = $entry;
100
    }
101
102
    public function getSource(): string
103
    {
104
        return static::SOURCE_EXTERNAL;
105
    }
106
}
107
108
109
class Files extends FilesAdapter
110
{
111
    public function loadEntries(string $inputType): void
112
    {
113
        parent::loadEntries($inputType);
114
        $dataset = $this->fileDataset();
115
        $this->vars = $this->loadVars($dataset);
116
    }
117
118
    protected function fileDataset(): array
119
    {
120
        return [
121
            'files' => [ // simple upload
122
                'name' => 'facepalm.jpg',
123
                'type' => 'image/jpeg',
124
                'tmp_name' => '/tmp/php3zU3t5',
125
                'error' => UPLOAD_ERR_OK,
126
                'size' => 591387,
127
            ],
128
            'download' => [ // multiple upload
129
                'name' => [
130
                    'file1' => 'MyFile.txt',
131
                    'file2' => 'MyFile.jpg',
132
                ],
133
                'type' => [
134
                    'file1' => 'text/plain',
135
                    'file2' => 'image/jpeg',
136
                ],
137
                'tmp_name' => [
138
                    'file1' => '/tmp/php/phpgj46fg',
139
                    'file2' => '/tmp/php/php7s4ag4',
140
                ],
141
                'error' => [
142
                    'file1' => UPLOAD_ERR_CANT_WRITE,
143
                    'file2' => UPLOAD_ERR_PARTIAL,
144
                ],
145
                'size' => [
146
                    'file1' => 816,
147
                    'file2' => 3075,
148
                ],
149
            ],
150
            'numbered' => [ // multiple upload
151
                'name' => [
152
                    0 => 'MyFile.txt',
153
                    1 => 'MyFile.jpg',
154
                ],
155
                'type' => [
156
                    0 => 'text/plain',
157
                    1 => 'image/jpeg',
158
                ],
159
                'tmp_name' => [
160
                    0 => '/tmp/php/phpgj46fg',
161
                    1 => '/tmp/php/php7s4ag4',
162
                ],
163
                'error' => [
164
                    0 => UPLOAD_ERR_CANT_WRITE,
165
                    1 => UPLOAD_ERR_PARTIAL,
166
                ],
167
                'size' => [
168
                    0 => 816,
169
                    1 => 3075,
170
                ],
171
            ],
172
        ];
173
    }
174
175
}
176