Completed
Push — master ( cce6a6...8438be )
by Ivan
03:16
created

File::getPhpFileArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
ccs 15
cts 15
cp 1
rs 9.0857
cc 2
eloc 17
nc 2
nop 0
crap 2
1
<?php
2
3
namespace SP\Crawler\Element;
4
5
use Guzzlehttp\Psr7;
6
7
/**
8
 * @author    Ivan Kerin <[email protected]>
9
 * @copyright 2015, Clippings Ltd.
10
 * @license   http://spdx.org/licenses/BSD-3-Clause
11
 */
12
class File extends Input
13
{
14 2
    public function getPhpFileArray()
15
    {
16 2
        if ($this->getValue()) {
17 1
            $tmpFile = tempnam(sys_get_temp_dir(), 'crawler-uploaded-file');
18 1
            copy($this->getValue(), $tmpFile);
19
20
            return [
21 1
                'tmp_name' => $tmpFile,
22 1
                'size' => filesize($this->getValue()),
23 1
                'error' => UPLOAD_ERR_OK,
24 1
                'name' => $this->getValue(),
25 1
                'type' => Psr7\mimetype_from_filename($this->getValue())
26 1
            ];
27
        } else {
28
            return [
29 1
                'tmp_name' => '',
30 1
                'size' => '0',
31 1
                'error' => UPLOAD_ERR_NO_FILE,
32 1
                'name' => '',
33
                'type' => ''
34 1
            ];
35
        }
36
    }
37
}
38