AbortableProcess   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 16 3
1
<?php
2
/**
3
 * AbortableProcess implements a workaround to make Symfony Process not kill itself when we
4
 * trap a Unix signal.
5
 *
6
 * Process is relying on error_get_last to learn if the stream reading was interrupted by a signal
7
 * (see UnixSignal's readAndWrite, the hasSystemCallBeenInterrupted call). Unfortunately this doesn't
8
 * work if we trapp the signal, which wipes out the error, which makes Process think it's some
9
 * other kind of error which makes it commit suicide for no good reason.
10
 *
11
 * Workaround is to avoid blocking stream_select as ->run nor ->wait do. Fortunately we can call
12
 * ->isRunning instead, which uses a non-blocking readPipes via updateStatus. This means our callback
13
 * will still get called if we loop over ->isRunning.
14
 */
15
class AbortableProcess extends \Symfony\Component\Process\Process {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
16
	public function run($callback = null) {
17
		$this->start($callback);
18
		while($this->isRunning()) {
19
			$this->checkTimeout();
20
			sleep(1);
21
		}
22
23
		if ($this->hasBeenSignaled()) {
24
			throw new RuntimeException(sprintf(
25
				'The process has been signaled with signal "%s".',
26
				$this->getTermSignal())
27
			);
28
		}
29
30
		return $this->getExitCode();
31
	}
32
}
33