Completed
Push — master ( e6cd79...15515b )
by Mike
02:12
created

GETFile::getFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace SugarAPI\SDK\Request;
4
5
6
class GETFile extends GET {
7
8
    /**
9
     * File to dump response
10
     * @var resource
11
     */
12
    protected $filePath;
13
14
    /**
15
     * File Handle used by Curl
16
     * @var
17
     */
18
    protected $fileHandle;
19
20
    /**
21
     * @inheritdoc
22
     */
23
    protected static $_DEFAULT_HEADERS = array();
24
25
    /**
26
     * Set Temp File for File Response
27
     * @inheritdoc
28
     */
29
    public function send(){
30
        //$this->initFile();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
31
        return parent::send();
32
    }
33
34
    public function setFile($filePath){
35
        if ($this->status == self::STATUS_INIT) {
36
            $this->filePath = fopen($filePath, 'w+');
37
        }
38
        return $this;
39
    }
40
41
    protected function initFile(){
42
        if ($this->status == self::STATUS_INIT) {
43
            if ($this->filePath == NULL) {
44
                $this->filePath = tempnam(sys_get_temp_dir(), 'SugarAP_SDK_Response_');
0 ignored issues
show
Documentation Bug introduced by
It seems like tempnam(sys_get_temp_dir...SugarAP_SDK_Response_') of type string is incompatible with the declared type resource of property $filePath.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
45
            }
46
        }
47
        $this->fileHandle = fopen($this->filePath,'w+');
48
    }
49
50
    protected function closeFile(){
51
        if ($this->status !== self::STATUS_INIT) {
52
            fclose($this->fileHandle);
53
        }
54
    }
55
56
    public function getFile(){
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
57
        return $this->filePath;
58
    }
59
60
    public function close(){
61
        $this->closeFile();
62
        return parent::close();
63
    }
64
65
}