Completed
Push — master ( ea43a1...cefa14 )
by Daniel
05:36
created

AbstractDevice::getArgument()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4286
cc 2
eloc 4
nc 2
nop 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\Devices;
9
10
use GravityMedia\Ghostscript\Process\Arguments as ProcessArguments;
11
use Symfony\Component\Process\Process;
12
use Symfony\Component\Process\ProcessBuilder;
13
14
/**
15
 * The abstract device class
16
 *
17
 * @package GravityMedia\Ghostscript\Devices
18
 */
19
abstract class AbstractDevice
20
{
21
    /**
22
     * The process builder object
23
     *
24
     * @var Process
25
     */
26
    private $builder;
27
28
    /**
29
     * The arguments object
30
     *
31
     * @var ProcessArguments
32
     */
33
    private $arguments;
34
35
    /**
36
     * Create abstract device object
37
     *
38
     * @param ProcessBuilder   $builder
39
     * @param ProcessArguments $arguments
40
     */
41
    public function __construct(ProcessBuilder $builder, ProcessArguments $arguments)
42
    {
43
        $this->builder = $builder;
0 ignored issues
show
Documentation Bug introduced by
It seems like $builder of type object<Symfony\Component\Process\ProcessBuilder> is incompatible with the declared type object<Symfony\Component\Process\Process> of property $builder.

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...
44
        $this->arguments = $arguments;
45
    }
46
47
    /**
48
     * Get argument value
49
     *
50
     * @param string $name
51
     *
52
     * @return null|string
53
     */
54
    protected function getArgumentValue($name)
55
    {
56
        $argument = $this->arguments->getArgument($name);
57
        if (null === $argument) {
58
            return null;
59
        }
60
61
        return $argument->getValue();
62
    }
63
64
    /**
65
     * Set argument
66
     *
67
     * @param string $argument
68
     *
69
     * @return $this
70
     */
71
    protected function setArgument($argument)
72
    {
73
        $this->arguments->setArgument($argument);
74
75
        return $this;
76
    }
77
78
    /**
79
     * Create process object
80
     *
81
     * @param string $inputFile
82
     *
83
     * @throws \RuntimeException
84
     *
85
     * @return Process
86
     */
87
    public function createProcess($inputFile)
88
    {
89
        if (!is_file($inputFile)) {
90
            throw new \RuntimeException('Input file does not exist');
91
        }
92
93
        $arguments = array_values($this->arguments->toArray());
94
        array_push($arguments, '-f', $inputFile);
95
96
        return $this->builder->setArguments($arguments)->getProcess();
0 ignored issues
show
Bug introduced by
The method setArguments() does not seem to exist on object<Symfony\Component\Process\Process>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
97
    }
98
}
99