Input::setPostScriptCode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This file is part of the Ghostscript package.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Ghostscript;
9
10
use Symfony\Component\Process\ProcessUtils;
11
12
/**
13
 * The input class.
14
 *
15
 * @package GravityMedia\Ghostscript
16
 */
17
class Input
18
{
19
    /**
20
     * The process input.
21
     *
22
     * @var null|string|resource
23
     */
24
    private $processInput;
25
26
    /**
27
     * The PostScript code.
28
     *
29
     * @var null|string
30
     */
31
    private $postScriptCode;
32
33
    /**
34
     * The files.
35
     *
36
     * @var null|string[]
37
     */
38
    private $files;
39
40
    /**
41
     * Get process input.
42
     *
43
     * @return null|string|resource
44
     */
45 4
    public function getProcessInput()
46
    {
47 4
        return $this->processInput;
48
    }
49
50
    /**
51
     * Set process input.
52
     *
53
     * @param mixed $processInput
54
     *
55
     * @throws \InvalidArgumentException
56
     *
57
     * @return $this
58
     */
59 2
    public function setProcessInput($processInput)
60
    {
61 2
        $this->processInput = ProcessUtils::validateInput(__METHOD__, $processInput);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Symfony\Component\Proce...ETHOD__, $processInput) can also be of type object<Iterator>. However, the property $processInput is declared as type null|string|resource. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
62
63 2
        return $this;
64
    }
65
66
    /**
67
     * Get PostScript code.
68
     *
69
     * @return null|string
70
     */
71 4
    public function getPostScriptCode()
72
    {
73 4
        return $this->postScriptCode;
74
    }
75
76
    /**
77
     * Set PostScript code.
78
     *
79
     * @param null|string $postScriptCode
80
     *
81
     * @return $this
82
     */
83 2
    public function setPostScriptCode($postScriptCode)
84
    {
85 2
        $this->postScriptCode = $postScriptCode;
86
87 2
        return $this;
88
    }
89
90
    /**
91
     * Get files.
92
     *
93
     * @return string[]
94
     */
95 4
    public function getFiles()
96
    {
97 4
        if (null === $this->files) {
98 2
            return [];
99
        }
100
101 2
        return $this->files;
102
    }
103
104
    /**
105
     * Add file.
106
     *
107
     * @param string $file
108
     *
109
     * @return $this
110
     */
111 2
    public function addFile($file)
112
    {
113 2
        if (null === $this->files) {
114 2
            $this->files = [];
115 1
        }
116
117 2
        $this->files[] = $file;
118
119 2
        return $this;
120
    }
121
122
    /**
123
     * Set files.
124
     *
125
     * @param string[] $files
126
     *
127
     * @return $this
128
     */
129 2
    public function setFiles(array $files)
130
    {
131 2
        $this->files = $files;
132
133 2
        return $this;
134
    }
135
}
136