Completed
Push — master ( 71cc85...b00a6a )
by Alexey
37:06
created

Options.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace SfCod\QueueBundle;
4
5
/**
6
 * Class WorkerOptions
7
 *
8
 * @package SfCod\QueueBundle
9
 */
10
class Options
11
{
12
    /**
13
     * The number of seconds before a released job will be available.
14
     *
15
     * @var int
16
     */
17
    public $delay;
18
19
    /**
20
     * The maximum amount of RAM the worker may consume.
21
     *
22
     * @var int
23
     */
24
    public $memory;
25
26
    /**
27
     * The maximum number of seconds a child worker may run.
28
     *
29
     * @var int
30
     */
31
    public $timeout;
32
33
    /**
34
     * The number of seconds to wait in between polling the queue.
35
     *
36
     * @var int
37
     */
38
    public $sleep;
39
40
    /**
41
     * The maximum amount of times a job may be attempted.
42
     *
43
     * @var int
44
     */
45
    public $maxTries;
46
47
    /**
48
     * Indicates if the worker should run in maintenance mode.
49
     *
50
     * @var bool
51
     */
52
    public $force;
53
54
    /**
55
     * WorkerOptions constructor.
56
     *
57
     * @param int $delay
58
     * @param int $memory
59
     * @param int $timeout
60
     * @param int $sleep
61
     * @param int $maxTries
62
     * @param bool $force
63
     */
64
    public function __construct(
65
        int $delay = 0,
66
        int $memory = 128,
67
        int $timeout = 60,
68
        int $sleep = 3,
69
        int $maxTries = 0,
70
        bool $force = false
71
    ) {
72
        $this->delay = $delay;
73
        $this->sleep = $sleep;
74
        $this->force = $force;
75
        $this->memory = $memory;
76
        $this->timeout = $timeout;
77
        $this->maxTries = $maxTries;
78
    }
79
80
    public function getBinaryArgs(): string
81
    {
82
        return getenv('BINARY_ARGS') ?? '';
83
    }
84
85
    public function getBinPath()
86
    {
87
        return getenv('BIN_PATH');
88
    }
89
90
    public function getScriptName(): string
91
    {
92
        return getenv('SCRIPT_NAME');
93
    }
94
95
    /**
96
     * Get the escaped PHP Binary from the configuration
97
     *
98
     * @return string
99
     */
100
    public function getPhpBinary(): string
101
    {
102
        $path = $this->binary;
0 ignored issues
show
The property binary does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
103
        if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
104
            $path = escapeshellarg($path);
105
        }
106
107
        $args = $this->binaryArgs;
0 ignored issues
show
The property binaryArgs does not seem to exist. Did you mean binary?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
108
        if (is_array($args)) {
109
            $args = implode(' ', $args);
110
        }
111
112
        return trim($path . ' ' . $args);
113
    }
114
}
115