1 | <?php |
||
2 | |||
3 | namespace SwooleTW\Http\HotReload; |
||
4 | |||
5 | use Swoole\Process as SwooleProcess; |
||
6 | use Symfony\Component\Process\Process as AppProcess; |
||
7 | |||
8 | /** |
||
9 | * Class FSProcess |
||
10 | */ |
||
11 | class FSProcess |
||
12 | { |
||
13 | /** |
||
14 | * Observed files. |
||
15 | * |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $filter; |
||
19 | |||
20 | /** |
||
21 | * Watch recursively. |
||
22 | * |
||
23 | * @var bool |
||
24 | */ |
||
25 | protected $recursively; |
||
26 | |||
27 | /** |
||
28 | * Watch directory. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $directory; |
||
33 | |||
34 | /** |
||
35 | * When locked event cannot do anything. |
||
36 | * |
||
37 | * @var bool |
||
38 | */ |
||
39 | protected $locked; |
||
40 | |||
41 | /** |
||
42 | * FSProcess constructor. |
||
43 | * |
||
44 | * @param string $filter |
||
45 | * @param bool $recursively |
||
46 | * @param string $directory |
||
47 | */ |
||
48 | public function __construct(string $filter, bool $recursively, string $directory) |
||
49 | { |
||
50 | $this->filter = $filter; |
||
0 ignored issues
–
show
|
|||
51 | $this->recursively = $recursively; |
||
52 | $this->directory = $directory; |
||
53 | $this->locked = false; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Make swoole process. |
||
58 | * |
||
59 | * @param callable|null $callback |
||
60 | * |
||
61 | * @return \Swoole\Process |
||
62 | */ |
||
63 | public function make(?callable $callback = null) |
||
64 | { |
||
65 | $mcb = function ($type, $buffer) use ($callback) { |
||
66 | if (! $this->locked && AppProcess::OUT === $type && $event = FSEventParser::toEvent($buffer)) { |
||
67 | $this->locked = true; |
||
68 | ($callback) ? $callback($event) : null; |
||
69 | $this->locked = false; |
||
70 | unset($event); |
||
71 | } |
||
72 | }; |
||
73 | |||
74 | return new SwooleProcess(function () use ($mcb) { |
||
75 | (new AppProcess($this->configure()))->setTimeout(0)->run($mcb); |
||
76 | }, false, false); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Configure process. |
||
81 | * |
||
82 | * @return array |
||
83 | */ |
||
84 | protected function configure(): array |
||
85 | { |
||
86 | return [ |
||
87 | 'fswatch', |
||
88 | $this->recursively ? '-rtx' : '-tx', |
||
89 | '-e', |
||
90 | '.*', |
||
91 | '-i', |
||
92 | "\\{$this->filter}$", |
||
93 | $this->directory, |
||
94 | ]; |
||
95 | } |
||
96 | } |
||
97 |
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..