@@ -26,182 +26,182 @@ |
||
26 | 26 | */ |
27 | 27 | class WindowsPipes extends AbstractPipes |
28 | 28 | { |
29 | - private $files = []; |
|
30 | - private $fileHandles = []; |
|
31 | - private $lockHandles = []; |
|
32 | - private $readBytes = [ |
|
33 | - Process::STDOUT => 0, |
|
34 | - Process::STDERR => 0, |
|
35 | - ]; |
|
36 | - private $haveReadSupport; |
|
37 | - |
|
38 | - public function __construct($input, bool $haveReadSupport) |
|
39 | - { |
|
40 | - $this->haveReadSupport = $haveReadSupport; |
|
41 | - |
|
42 | - if ($this->haveReadSupport) { |
|
43 | - // Fix for PHP bug #51800: reading from STDOUT pipe hangs forever on Windows if the output is too big. |
|
44 | - // Workaround for this problem is to use temporary files instead of pipes on Windows platform. |
|
45 | - // |
|
46 | - // @see https://bugs.php.net/51800 |
|
47 | - $pipes = [ |
|
48 | - Process::STDOUT => Process::OUT, |
|
49 | - Process::STDERR => Process::ERR, |
|
50 | - ]; |
|
51 | - $tmpDir = sys_get_temp_dir(); |
|
52 | - $lastError = 'unknown reason'; |
|
53 | - set_error_handler(function ($type, $msg) use (&$lastError) { $lastError = $msg; }); |
|
54 | - for ($i = 0;; ++$i) { |
|
55 | - foreach ($pipes as $pipe => $name) { |
|
56 | - $file = sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name); |
|
57 | - |
|
58 | - if (!$h = fopen($file.'.lock', 'w')) { |
|
59 | - if (file_exists($file.'.lock')) { |
|
60 | - continue 2; |
|
61 | - } |
|
62 | - restore_error_handler(); |
|
63 | - throw new RuntimeException('A temporary file could not be opened to write the process output: '.$lastError); |
|
64 | - } |
|
65 | - if (!flock($h, \LOCK_EX | \LOCK_NB)) { |
|
66 | - continue 2; |
|
67 | - } |
|
68 | - if (isset($this->lockHandles[$pipe])) { |
|
69 | - flock($this->lockHandles[$pipe], \LOCK_UN); |
|
70 | - fclose($this->lockHandles[$pipe]); |
|
71 | - } |
|
72 | - $this->lockHandles[$pipe] = $h; |
|
73 | - |
|
74 | - if (!($h = fopen($file, 'w')) || !fclose($h) || !$h = fopen($file, 'r')) { |
|
75 | - flock($this->lockHandles[$pipe], \LOCK_UN); |
|
76 | - fclose($this->lockHandles[$pipe]); |
|
77 | - unset($this->lockHandles[$pipe]); |
|
78 | - continue 2; |
|
79 | - } |
|
80 | - $this->fileHandles[$pipe] = $h; |
|
81 | - $this->files[$pipe] = $file; |
|
82 | - } |
|
83 | - break; |
|
84 | - } |
|
85 | - restore_error_handler(); |
|
86 | - } |
|
87 | - |
|
88 | - parent::__construct($input); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - public function __sleep() |
|
95 | - { |
|
96 | - throw new \BadMethodCallException('Cannot serialize '.__CLASS__); |
|
97 | - } |
|
98 | - |
|
99 | - public function __wakeup() |
|
100 | - { |
|
101 | - throw new \BadMethodCallException('Cannot unserialize '.__CLASS__); |
|
102 | - } |
|
103 | - |
|
104 | - public function __destruct() |
|
105 | - { |
|
106 | - $this->close(); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * {@inheritdoc} |
|
111 | - */ |
|
112 | - public function getDescriptors(): array |
|
113 | - { |
|
114 | - if (!$this->haveReadSupport) { |
|
115 | - $nullstream = fopen('NUL', 'c'); |
|
116 | - |
|
117 | - return [ |
|
118 | - ['pipe', 'r'], |
|
119 | - $nullstream, |
|
120 | - $nullstream, |
|
121 | - ]; |
|
122 | - } |
|
123 | - |
|
124 | - // We're not using pipe on Windows platform as it hangs (https://bugs.php.net/51800) |
|
125 | - // We're not using file handles as it can produce corrupted output https://bugs.php.net/65650 |
|
126 | - // So we redirect output within the commandline and pass the nul device to the process |
|
127 | - return [ |
|
128 | - ['pipe', 'r'], |
|
129 | - ['file', 'NUL', 'w'], |
|
130 | - ['file', 'NUL', 'w'], |
|
131 | - ]; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * {@inheritdoc} |
|
136 | - */ |
|
137 | - public function getFiles(): array |
|
138 | - { |
|
139 | - return $this->files; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * {@inheritdoc} |
|
144 | - */ |
|
145 | - public function readAndWrite(bool $blocking, bool $close = false): array |
|
146 | - { |
|
147 | - $this->unblock(); |
|
148 | - $w = $this->write(); |
|
149 | - $read = $r = $e = []; |
|
150 | - |
|
151 | - if ($blocking) { |
|
152 | - if ($w) { |
|
153 | - @stream_select($r, $w, $e, 0, Process::TIMEOUT_PRECISION * 1E6); |
|
154 | - } elseif ($this->fileHandles) { |
|
155 | - usleep(Process::TIMEOUT_PRECISION * 1E6); |
|
156 | - } |
|
157 | - } |
|
158 | - foreach ($this->fileHandles as $type => $fileHandle) { |
|
159 | - $data = stream_get_contents($fileHandle, -1, $this->readBytes[$type]); |
|
160 | - |
|
161 | - if (isset($data[0])) { |
|
162 | - $this->readBytes[$type] += \strlen($data); |
|
163 | - $read[$type] = $data; |
|
164 | - } |
|
165 | - if ($close) { |
|
166 | - ftruncate($fileHandle, 0); |
|
167 | - fclose($fileHandle); |
|
168 | - flock($this->lockHandles[$type], \LOCK_UN); |
|
169 | - fclose($this->lockHandles[$type]); |
|
170 | - unset($this->fileHandles[$type], $this->lockHandles[$type]); |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - return $read; |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * {@inheritdoc} |
|
179 | - */ |
|
180 | - public function haveReadSupport(): bool |
|
181 | - { |
|
182 | - return $this->haveReadSupport; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * {@inheritdoc} |
|
187 | - */ |
|
188 | - public function areOpen(): bool |
|
189 | - { |
|
190 | - return $this->pipes && $this->fileHandles; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * {@inheritdoc} |
|
195 | - */ |
|
196 | - public function close() |
|
197 | - { |
|
198 | - parent::close(); |
|
199 | - foreach ($this->fileHandles as $type => $handle) { |
|
200 | - ftruncate($handle, 0); |
|
201 | - fclose($handle); |
|
202 | - flock($this->lockHandles[$type], \LOCK_UN); |
|
203 | - fclose($this->lockHandles[$type]); |
|
204 | - } |
|
205 | - $this->fileHandles = $this->lockHandles = []; |
|
206 | - } |
|
29 | + private $files = []; |
|
30 | + private $fileHandles = []; |
|
31 | + private $lockHandles = []; |
|
32 | + private $readBytes = [ |
|
33 | + Process::STDOUT => 0, |
|
34 | + Process::STDERR => 0, |
|
35 | + ]; |
|
36 | + private $haveReadSupport; |
|
37 | + |
|
38 | + public function __construct($input, bool $haveReadSupport) |
|
39 | + { |
|
40 | + $this->haveReadSupport = $haveReadSupport; |
|
41 | + |
|
42 | + if ($this->haveReadSupport) { |
|
43 | + // Fix for PHP bug #51800: reading from STDOUT pipe hangs forever on Windows if the output is too big. |
|
44 | + // Workaround for this problem is to use temporary files instead of pipes on Windows platform. |
|
45 | + // |
|
46 | + // @see https://bugs.php.net/51800 |
|
47 | + $pipes = [ |
|
48 | + Process::STDOUT => Process::OUT, |
|
49 | + Process::STDERR => Process::ERR, |
|
50 | + ]; |
|
51 | + $tmpDir = sys_get_temp_dir(); |
|
52 | + $lastError = 'unknown reason'; |
|
53 | + set_error_handler(function ($type, $msg) use (&$lastError) { $lastError = $msg; }); |
|
54 | + for ($i = 0;; ++$i) { |
|
55 | + foreach ($pipes as $pipe => $name) { |
|
56 | + $file = sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name); |
|
57 | + |
|
58 | + if (!$h = fopen($file.'.lock', 'w')) { |
|
59 | + if (file_exists($file.'.lock')) { |
|
60 | + continue 2; |
|
61 | + } |
|
62 | + restore_error_handler(); |
|
63 | + throw new RuntimeException('A temporary file could not be opened to write the process output: '.$lastError); |
|
64 | + } |
|
65 | + if (!flock($h, \LOCK_EX | \LOCK_NB)) { |
|
66 | + continue 2; |
|
67 | + } |
|
68 | + if (isset($this->lockHandles[$pipe])) { |
|
69 | + flock($this->lockHandles[$pipe], \LOCK_UN); |
|
70 | + fclose($this->lockHandles[$pipe]); |
|
71 | + } |
|
72 | + $this->lockHandles[$pipe] = $h; |
|
73 | + |
|
74 | + if (!($h = fopen($file, 'w')) || !fclose($h) || !$h = fopen($file, 'r')) { |
|
75 | + flock($this->lockHandles[$pipe], \LOCK_UN); |
|
76 | + fclose($this->lockHandles[$pipe]); |
|
77 | + unset($this->lockHandles[$pipe]); |
|
78 | + continue 2; |
|
79 | + } |
|
80 | + $this->fileHandles[$pipe] = $h; |
|
81 | + $this->files[$pipe] = $file; |
|
82 | + } |
|
83 | + break; |
|
84 | + } |
|
85 | + restore_error_handler(); |
|
86 | + } |
|
87 | + |
|
88 | + parent::__construct($input); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + public function __sleep() |
|
95 | + { |
|
96 | + throw new \BadMethodCallException('Cannot serialize '.__CLASS__); |
|
97 | + } |
|
98 | + |
|
99 | + public function __wakeup() |
|
100 | + { |
|
101 | + throw new \BadMethodCallException('Cannot unserialize '.__CLASS__); |
|
102 | + } |
|
103 | + |
|
104 | + public function __destruct() |
|
105 | + { |
|
106 | + $this->close(); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * {@inheritdoc} |
|
111 | + */ |
|
112 | + public function getDescriptors(): array |
|
113 | + { |
|
114 | + if (!$this->haveReadSupport) { |
|
115 | + $nullstream = fopen('NUL', 'c'); |
|
116 | + |
|
117 | + return [ |
|
118 | + ['pipe', 'r'], |
|
119 | + $nullstream, |
|
120 | + $nullstream, |
|
121 | + ]; |
|
122 | + } |
|
123 | + |
|
124 | + // We're not using pipe on Windows platform as it hangs (https://bugs.php.net/51800) |
|
125 | + // We're not using file handles as it can produce corrupted output https://bugs.php.net/65650 |
|
126 | + // So we redirect output within the commandline and pass the nul device to the process |
|
127 | + return [ |
|
128 | + ['pipe', 'r'], |
|
129 | + ['file', 'NUL', 'w'], |
|
130 | + ['file', 'NUL', 'w'], |
|
131 | + ]; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * {@inheritdoc} |
|
136 | + */ |
|
137 | + public function getFiles(): array |
|
138 | + { |
|
139 | + return $this->files; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * {@inheritdoc} |
|
144 | + */ |
|
145 | + public function readAndWrite(bool $blocking, bool $close = false): array |
|
146 | + { |
|
147 | + $this->unblock(); |
|
148 | + $w = $this->write(); |
|
149 | + $read = $r = $e = []; |
|
150 | + |
|
151 | + if ($blocking) { |
|
152 | + if ($w) { |
|
153 | + @stream_select($r, $w, $e, 0, Process::TIMEOUT_PRECISION * 1E6); |
|
154 | + } elseif ($this->fileHandles) { |
|
155 | + usleep(Process::TIMEOUT_PRECISION * 1E6); |
|
156 | + } |
|
157 | + } |
|
158 | + foreach ($this->fileHandles as $type => $fileHandle) { |
|
159 | + $data = stream_get_contents($fileHandle, -1, $this->readBytes[$type]); |
|
160 | + |
|
161 | + if (isset($data[0])) { |
|
162 | + $this->readBytes[$type] += \strlen($data); |
|
163 | + $read[$type] = $data; |
|
164 | + } |
|
165 | + if ($close) { |
|
166 | + ftruncate($fileHandle, 0); |
|
167 | + fclose($fileHandle); |
|
168 | + flock($this->lockHandles[$type], \LOCK_UN); |
|
169 | + fclose($this->lockHandles[$type]); |
|
170 | + unset($this->fileHandles[$type], $this->lockHandles[$type]); |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + return $read; |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * {@inheritdoc} |
|
179 | + */ |
|
180 | + public function haveReadSupport(): bool |
|
181 | + { |
|
182 | + return $this->haveReadSupport; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * {@inheritdoc} |
|
187 | + */ |
|
188 | + public function areOpen(): bool |
|
189 | + { |
|
190 | + return $this->pipes && $this->fileHandles; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * {@inheritdoc} |
|
195 | + */ |
|
196 | + public function close() |
|
197 | + { |
|
198 | + parent::close(); |
|
199 | + foreach ($this->fileHandles as $type => $handle) { |
|
200 | + ftruncate($handle, 0); |
|
201 | + fclose($handle); |
|
202 | + flock($this->lockHandles[$type], \LOCK_UN); |
|
203 | + fclose($this->lockHandles[$type]); |
|
204 | + } |
|
205 | + $this->fileHandles = $this->lockHandles = []; |
|
206 | + } |
|
207 | 207 | } |
@@ -26,20 +26,20 @@ discard block |
||
26 | 26 | */ |
27 | 27 | class WindowsPipes extends AbstractPipes |
28 | 28 | { |
29 | - private $files = []; |
|
30 | - private $fileHandles = []; |
|
31 | - private $lockHandles = []; |
|
29 | + private $files = [ ]; |
|
30 | + private $fileHandles = [ ]; |
|
31 | + private $lockHandles = [ ]; |
|
32 | 32 | private $readBytes = [ |
33 | 33 | Process::STDOUT => 0, |
34 | 34 | Process::STDERR => 0, |
35 | 35 | ]; |
36 | 36 | private $haveReadSupport; |
37 | 37 | |
38 | - public function __construct($input, bool $haveReadSupport) |
|
38 | + public function __construct( $input, bool $haveReadSupport ) |
|
39 | 39 | { |
40 | 40 | $this->haveReadSupport = $haveReadSupport; |
41 | 41 | |
42 | - if ($this->haveReadSupport) { |
|
42 | + if ( $this->haveReadSupport ) { |
|
43 | 43 | // Fix for PHP bug #51800: reading from STDOUT pipe hangs forever on Windows if the output is too big. |
44 | 44 | // Workaround for this problem is to use temporary files instead of pipes on Windows platform. |
45 | 45 | // |
@@ -50,42 +50,42 @@ discard block |
||
50 | 50 | ]; |
51 | 51 | $tmpDir = sys_get_temp_dir(); |
52 | 52 | $lastError = 'unknown reason'; |
53 | - set_error_handler(function ($type, $msg) use (&$lastError) { $lastError = $msg; }); |
|
54 | - for ($i = 0;; ++$i) { |
|
55 | - foreach ($pipes as $pipe => $name) { |
|
56 | - $file = sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name); |
|
53 | + set_error_handler( function( $type, $msg ) use ( &$lastError ) { $lastError = $msg; }); |
|
54 | + for ( $i = 0; ; ++$i ) { |
|
55 | + foreach ( $pipes as $pipe => $name ) { |
|
56 | + $file = sprintf( '%s\\sf_proc_%02X.%s', $tmpDir, $i, $name ); |
|
57 | 57 | |
58 | - if (!$h = fopen($file.'.lock', 'w')) { |
|
59 | - if (file_exists($file.'.lock')) { |
|
58 | + if ( ! $h = fopen( $file . '.lock', 'w' ) ) { |
|
59 | + if ( file_exists( $file . '.lock' ) ) { |
|
60 | 60 | continue 2; |
61 | 61 | } |
62 | 62 | restore_error_handler(); |
63 | - throw new RuntimeException('A temporary file could not be opened to write the process output: '.$lastError); |
|
63 | + throw new RuntimeException( 'A temporary file could not be opened to write the process output: ' . $lastError ); |
|
64 | 64 | } |
65 | - if (!flock($h, \LOCK_EX | \LOCK_NB)) { |
|
65 | + if ( ! flock( $h, \LOCK_EX | \LOCK_NB ) ) { |
|
66 | 66 | continue 2; |
67 | 67 | } |
68 | - if (isset($this->lockHandles[$pipe])) { |
|
69 | - flock($this->lockHandles[$pipe], \LOCK_UN); |
|
70 | - fclose($this->lockHandles[$pipe]); |
|
68 | + if ( isset( $this->lockHandles[ $pipe ] ) ) { |
|
69 | + flock( $this->lockHandles[ $pipe ], \LOCK_UN ); |
|
70 | + fclose( $this->lockHandles[ $pipe ] ); |
|
71 | 71 | } |
72 | - $this->lockHandles[$pipe] = $h; |
|
72 | + $this->lockHandles[ $pipe ] = $h; |
|
73 | 73 | |
74 | - if (!($h = fopen($file, 'w')) || !fclose($h) || !$h = fopen($file, 'r')) { |
|
75 | - flock($this->lockHandles[$pipe], \LOCK_UN); |
|
76 | - fclose($this->lockHandles[$pipe]); |
|
77 | - unset($this->lockHandles[$pipe]); |
|
74 | + if ( ! ( $h = fopen( $file, 'w' ) ) || ! fclose( $h ) || ! $h = fopen( $file, 'r' ) ) { |
|
75 | + flock( $this->lockHandles[ $pipe ], \LOCK_UN ); |
|
76 | + fclose( $this->lockHandles[ $pipe ] ); |
|
77 | + unset( $this->lockHandles[ $pipe ] ); |
|
78 | 78 | continue 2; |
79 | 79 | } |
80 | - $this->fileHandles[$pipe] = $h; |
|
81 | - $this->files[$pipe] = $file; |
|
80 | + $this->fileHandles[ $pipe ] = $h; |
|
81 | + $this->files[ $pipe ] = $file; |
|
82 | 82 | } |
83 | 83 | break; |
84 | 84 | } |
85 | 85 | restore_error_handler(); |
86 | 86 | } |
87 | 87 | |
88 | - parent::__construct($input); |
|
88 | + parent::__construct( $input ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function __sleep() |
95 | 95 | { |
96 | - throw new \BadMethodCallException('Cannot serialize '.__CLASS__); |
|
96 | + throw new \BadMethodCallException( 'Cannot serialize ' . __CLASS__ ); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | public function __wakeup() |
100 | 100 | { |
101 | - throw new \BadMethodCallException('Cannot unserialize '.__CLASS__); |
|
101 | + throw new \BadMethodCallException( 'Cannot unserialize ' . __CLASS__ ); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | public function __destruct() |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function getDescriptors(): array |
113 | 113 | { |
114 | - if (!$this->haveReadSupport) { |
|
115 | - $nullstream = fopen('NUL', 'c'); |
|
114 | + if ( ! $this->haveReadSupport ) { |
|
115 | + $nullstream = fopen( 'NUL', 'c' ); |
|
116 | 116 | |
117 | 117 | return [ |
118 | - ['pipe', 'r'], |
|
118 | + [ 'pipe', 'r' ], |
|
119 | 119 | $nullstream, |
120 | 120 | $nullstream, |
121 | 121 | ]; |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | // We're not using file handles as it can produce corrupted output https://bugs.php.net/65650 |
126 | 126 | // So we redirect output within the commandline and pass the nul device to the process |
127 | 127 | return [ |
128 | - ['pipe', 'r'], |
|
129 | - ['file', 'NUL', 'w'], |
|
130 | - ['file', 'NUL', 'w'], |
|
128 | + [ 'pipe', 'r' ], |
|
129 | + [ 'file', 'NUL', 'w' ], |
|
130 | + [ 'file', 'NUL', 'w' ], |
|
131 | 131 | ]; |
132 | 132 | } |
133 | 133 | |
@@ -142,32 +142,32 @@ discard block |
||
142 | 142 | /** |
143 | 143 | * {@inheritdoc} |
144 | 144 | */ |
145 | - public function readAndWrite(bool $blocking, bool $close = false): array |
|
145 | + public function readAndWrite( bool $blocking, bool $close = false ): array |
|
146 | 146 | { |
147 | 147 | $this->unblock(); |
148 | 148 | $w = $this->write(); |
149 | - $read = $r = $e = []; |
|
149 | + $read = $r = $e = [ ]; |
|
150 | 150 | |
151 | - if ($blocking) { |
|
152 | - if ($w) { |
|
153 | - @stream_select($r, $w, $e, 0, Process::TIMEOUT_PRECISION * 1E6); |
|
154 | - } elseif ($this->fileHandles) { |
|
155 | - usleep(Process::TIMEOUT_PRECISION * 1E6); |
|
151 | + if ( $blocking ) { |
|
152 | + if ( $w ) { |
|
153 | + @stream_select( $r, $w, $e, 0, Process::TIMEOUT_PRECISION * 1E6 ); |
|
154 | + } elseif ( $this->fileHandles ) { |
|
155 | + usleep( Process::TIMEOUT_PRECISION * 1E6 ); |
|
156 | 156 | } |
157 | 157 | } |
158 | - foreach ($this->fileHandles as $type => $fileHandle) { |
|
159 | - $data = stream_get_contents($fileHandle, -1, $this->readBytes[$type]); |
|
158 | + foreach ( $this->fileHandles as $type => $fileHandle ) { |
|
159 | + $data = stream_get_contents( $fileHandle, -1, $this->readBytes[ $type ] ); |
|
160 | 160 | |
161 | - if (isset($data[0])) { |
|
162 | - $this->readBytes[$type] += \strlen($data); |
|
163 | - $read[$type] = $data; |
|
161 | + if ( isset( $data[ 0 ] ) ) { |
|
162 | + $this->readBytes[ $type ] += \strlen( $data ); |
|
163 | + $read[ $type ] = $data; |
|
164 | 164 | } |
165 | - if ($close) { |
|
166 | - ftruncate($fileHandle, 0); |
|
167 | - fclose($fileHandle); |
|
168 | - flock($this->lockHandles[$type], \LOCK_UN); |
|
169 | - fclose($this->lockHandles[$type]); |
|
170 | - unset($this->fileHandles[$type], $this->lockHandles[$type]); |
|
165 | + if ( $close ) { |
|
166 | + ftruncate( $fileHandle, 0 ); |
|
167 | + fclose( $fileHandle ); |
|
168 | + flock( $this->lockHandles[ $type ], \LOCK_UN ); |
|
169 | + fclose( $this->lockHandles[ $type ] ); |
|
170 | + unset( $this->fileHandles[ $type ], $this->lockHandles[ $type ] ); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
@@ -196,12 +196,12 @@ discard block |
||
196 | 196 | public function close() |
197 | 197 | { |
198 | 198 | parent::close(); |
199 | - foreach ($this->fileHandles as $type => $handle) { |
|
200 | - ftruncate($handle, 0); |
|
201 | - fclose($handle); |
|
202 | - flock($this->lockHandles[$type], \LOCK_UN); |
|
203 | - fclose($this->lockHandles[$type]); |
|
199 | + foreach ( $this->fileHandles as $type => $handle ) { |
|
200 | + ftruncate( $handle, 0 ); |
|
201 | + fclose( $handle ); |
|
202 | + flock( $this->lockHandles[ $type ], \LOCK_UN ); |
|
203 | + fclose( $this->lockHandles[ $type ] ); |
|
204 | 204 | } |
205 | - $this->fileHandles = $this->lockHandles = []; |
|
205 | + $this->fileHandles = $this->lockHandles = [ ]; |
|
206 | 206 | } |
207 | 207 | } |
@@ -24,8 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @internal |
26 | 26 | */ |
27 | -class WindowsPipes extends AbstractPipes |
|
28 | -{ |
|
27 | +class WindowsPipes extends AbstractPipes { |
|
29 | 28 | private $files = []; |
30 | 29 | private $fileHandles = []; |
31 | 30 | private $lockHandles = []; |
@@ -35,8 +34,7 @@ discard block |
||
35 | 34 | ]; |
36 | 35 | private $haveReadSupport; |
37 | 36 | |
38 | - public function __construct($input, bool $haveReadSupport) |
|
39 | - { |
|
37 | + public function __construct($input, bool $haveReadSupport) { |
|
40 | 38 | $this->haveReadSupport = $haveReadSupport; |
41 | 39 | |
42 | 40 | if ($this->haveReadSupport) { |
@@ -91,18 +89,15 @@ discard block |
||
91 | 89 | /** |
92 | 90 | * @return array |
93 | 91 | */ |
94 | - public function __sleep() |
|
95 | - { |
|
92 | + public function __sleep() { |
|
96 | 93 | throw new \BadMethodCallException('Cannot serialize '.__CLASS__); |
97 | 94 | } |
98 | 95 | |
99 | - public function __wakeup() |
|
100 | - { |
|
96 | + public function __wakeup() { |
|
101 | 97 | throw new \BadMethodCallException('Cannot unserialize '.__CLASS__); |
102 | 98 | } |
103 | 99 | |
104 | - public function __destruct() |
|
105 | - { |
|
100 | + public function __destruct() { |
|
106 | 101 | $this->close(); |
107 | 102 | } |
108 | 103 | |
@@ -193,8 +188,7 @@ discard block |
||
193 | 188 | /** |
194 | 189 | * {@inheritdoc} |
195 | 190 | */ |
196 | - public function close() |
|
197 | - { |
|
191 | + public function close() { |
|
198 | 192 | parent::close(); |
199 | 193 | foreach ($this->fileHandles as $type => $handle) { |
200 | 194 | ftruncate($handle, 0); |
@@ -20,75 +20,75 @@ |
||
20 | 20 | */ |
21 | 21 | class InputStream implements \IteratorAggregate |
22 | 22 | { |
23 | - /** @var callable|null */ |
|
24 | - private $onEmpty = null; |
|
25 | - private $input = []; |
|
26 | - private $open = true; |
|
23 | + /** @var callable|null */ |
|
24 | + private $onEmpty = null; |
|
25 | + private $input = []; |
|
26 | + private $open = true; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Sets a callback that is called when the write buffer becomes empty. |
|
30 | - */ |
|
31 | - public function onEmpty(callable $onEmpty = null) |
|
32 | - { |
|
33 | - $this->onEmpty = $onEmpty; |
|
34 | - } |
|
28 | + /** |
|
29 | + * Sets a callback that is called when the write buffer becomes empty. |
|
30 | + */ |
|
31 | + public function onEmpty(callable $onEmpty = null) |
|
32 | + { |
|
33 | + $this->onEmpty = $onEmpty; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Appends an input to the write buffer. |
|
38 | - * |
|
39 | - * @param resource|string|int|float|bool|\Traversable|null $input The input to append as scalar, |
|
40 | - * stream resource or \Traversable |
|
41 | - */ |
|
42 | - public function write($input) |
|
43 | - { |
|
44 | - if (null === $input) { |
|
45 | - return; |
|
46 | - } |
|
47 | - if ($this->isClosed()) { |
|
48 | - throw new RuntimeException(sprintf('"%s" is closed.', static::class)); |
|
49 | - } |
|
50 | - $this->input[] = ProcessUtils::validateInput(__METHOD__, $input); |
|
51 | - } |
|
36 | + /** |
|
37 | + * Appends an input to the write buffer. |
|
38 | + * |
|
39 | + * @param resource|string|int|float|bool|\Traversable|null $input The input to append as scalar, |
|
40 | + * stream resource or \Traversable |
|
41 | + */ |
|
42 | + public function write($input) |
|
43 | + { |
|
44 | + if (null === $input) { |
|
45 | + return; |
|
46 | + } |
|
47 | + if ($this->isClosed()) { |
|
48 | + throw new RuntimeException(sprintf('"%s" is closed.', static::class)); |
|
49 | + } |
|
50 | + $this->input[] = ProcessUtils::validateInput(__METHOD__, $input); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Closes the write buffer. |
|
55 | - */ |
|
56 | - public function close() |
|
57 | - { |
|
58 | - $this->open = false; |
|
59 | - } |
|
53 | + /** |
|
54 | + * Closes the write buffer. |
|
55 | + */ |
|
56 | + public function close() |
|
57 | + { |
|
58 | + $this->open = false; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Tells whether the write buffer is closed or not. |
|
63 | - */ |
|
64 | - public function isClosed() |
|
65 | - { |
|
66 | - return !$this->open; |
|
67 | - } |
|
61 | + /** |
|
62 | + * Tells whether the write buffer is closed or not. |
|
63 | + */ |
|
64 | + public function isClosed() |
|
65 | + { |
|
66 | + return !$this->open; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @return \Traversable |
|
71 | - */ |
|
72 | - #[\ReturnTypeWillChange] |
|
73 | - public function getIterator() |
|
74 | - { |
|
75 | - $this->open = true; |
|
69 | + /** |
|
70 | + * @return \Traversable |
|
71 | + */ |
|
72 | + #[\ReturnTypeWillChange] |
|
73 | + public function getIterator() |
|
74 | + { |
|
75 | + $this->open = true; |
|
76 | 76 | |
77 | - while ($this->open || $this->input) { |
|
78 | - if (!$this->input) { |
|
79 | - yield ''; |
|
80 | - continue; |
|
81 | - } |
|
82 | - $current = array_shift($this->input); |
|
77 | + while ($this->open || $this->input) { |
|
78 | + if (!$this->input) { |
|
79 | + yield ''; |
|
80 | + continue; |
|
81 | + } |
|
82 | + $current = array_shift($this->input); |
|
83 | 83 | |
84 | - if ($current instanceof \Iterator) { |
|
85 | - yield from $current; |
|
86 | - } else { |
|
87 | - yield $current; |
|
88 | - } |
|
89 | - if (!$this->input && $this->open && null !== $onEmpty = $this->onEmpty) { |
|
90 | - $this->write($onEmpty($this)); |
|
91 | - } |
|
92 | - } |
|
93 | - } |
|
84 | + if ($current instanceof \Iterator) { |
|
85 | + yield from $current; |
|
86 | + } else { |
|
87 | + yield $current; |
|
88 | + } |
|
89 | + if (!$this->input && $this->open && null !== $onEmpty = $this->onEmpty) { |
|
90 | + $this->write($onEmpty($this)); |
|
91 | + } |
|
92 | + } |
|
93 | + } |
|
94 | 94 | } |
@@ -22,13 +22,13 @@ discard block |
||
22 | 22 | { |
23 | 23 | /** @var callable|null */ |
24 | 24 | private $onEmpty = null; |
25 | - private $input = []; |
|
25 | + private $input = [ ]; |
|
26 | 26 | private $open = true; |
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Sets a callback that is called when the write buffer becomes empty. |
30 | 30 | */ |
31 | - public function onEmpty(callable $onEmpty = null) |
|
31 | + public function onEmpty( callable $onEmpty = null ) |
|
32 | 32 | { |
33 | 33 | $this->onEmpty = $onEmpty; |
34 | 34 | } |
@@ -39,15 +39,15 @@ discard block |
||
39 | 39 | * @param resource|string|int|float|bool|\Traversable|null $input The input to append as scalar, |
40 | 40 | * stream resource or \Traversable |
41 | 41 | */ |
42 | - public function write($input) |
|
42 | + public function write( $input ) |
|
43 | 43 | { |
44 | - if (null === $input) { |
|
44 | + if ( null === $input ) { |
|
45 | 45 | return; |
46 | 46 | } |
47 | - if ($this->isClosed()) { |
|
48 | - throw new RuntimeException(sprintf('"%s" is closed.', static::class)); |
|
47 | + if ( $this->isClosed() ) { |
|
48 | + throw new RuntimeException( sprintf( '"%s" is closed.', static::class ) ); |
|
49 | 49 | } |
50 | - $this->input[] = ProcessUtils::validateInput(__METHOD__, $input); |
|
50 | + $this->input[ ] = ProcessUtils::validateInput( __METHOD__, $input ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function isClosed() |
65 | 65 | { |
66 | - return !$this->open; |
|
66 | + return ! $this->open; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -74,20 +74,20 @@ discard block |
||
74 | 74 | { |
75 | 75 | $this->open = true; |
76 | 76 | |
77 | - while ($this->open || $this->input) { |
|
78 | - if (!$this->input) { |
|
77 | + while ( $this->open || $this->input ) { |
|
78 | + if ( ! $this->input ) { |
|
79 | 79 | yield ''; |
80 | 80 | continue; |
81 | 81 | } |
82 | - $current = array_shift($this->input); |
|
82 | + $current = array_shift( $this->input ); |
|
83 | 83 | |
84 | - if ($current instanceof \Iterator) { |
|
84 | + if ( $current instanceof \Iterator ) { |
|
85 | 85 | yield from $current; |
86 | 86 | } else { |
87 | 87 | yield $current; |
88 | 88 | } |
89 | - if (!$this->input && $this->open && null !== $onEmpty = $this->onEmpty) { |
|
90 | - $this->write($onEmpty($this)); |
|
89 | + if ( ! $this->input && $this->open && null !== $onEmpty = $this->onEmpty ) { |
|
90 | + $this->write( $onEmpty( $this ) ); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | } |
@@ -18,8 +18,7 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @author Nicolas Grekas <[email protected]> |
20 | 20 | */ |
21 | -class InputStream implements \IteratorAggregate |
|
22 | -{ |
|
21 | +class InputStream implements \IteratorAggregate { |
|
23 | 22 | /** @var callable|null */ |
24 | 23 | private $onEmpty = null; |
25 | 24 | private $input = []; |
@@ -28,8 +27,7 @@ discard block |
||
28 | 27 | /** |
29 | 28 | * Sets a callback that is called when the write buffer becomes empty. |
30 | 29 | */ |
31 | - public function onEmpty(callable $onEmpty = null) |
|
32 | - { |
|
30 | + public function onEmpty(callable $onEmpty = null) { |
|
33 | 31 | $this->onEmpty = $onEmpty; |
34 | 32 | } |
35 | 33 | |
@@ -39,8 +37,7 @@ discard block |
||
39 | 37 | * @param resource|string|int|float|bool|\Traversable|null $input The input to append as scalar, |
40 | 38 | * stream resource or \Traversable |
41 | 39 | */ |
42 | - public function write($input) |
|
43 | - { |
|
40 | + public function write($input) { |
|
44 | 41 | if (null === $input) { |
45 | 42 | return; |
46 | 43 | } |
@@ -53,16 +50,14 @@ discard block |
||
53 | 50 | /** |
54 | 51 | * Closes the write buffer. |
55 | 52 | */ |
56 | - public function close() |
|
57 | - { |
|
53 | + public function close() { |
|
58 | 54 | $this->open = false; |
59 | 55 | } |
60 | 56 | |
61 | 57 | /** |
62 | 58 | * Tells whether the write buffer is closed or not. |
63 | 59 | */ |
64 | - public function isClosed() |
|
65 | - { |
|
60 | + public function isClosed() { |
|
66 | 61 | return !$this->open; |
67 | 62 | } |
68 | 63 | |
@@ -70,8 +65,7 @@ discard block |
||
70 | 65 | * @return \Traversable |
71 | 66 | */ |
72 | 67 | #[\ReturnTypeWillChange] |
73 | - public function getIterator() |
|
74 | - { |
|
68 | + public function getIterator() { |
|
75 | 69 | $this->open = true; |
76 | 70 | |
77 | 71 | while ($this->open || $this->input) { |
@@ -12,31 +12,31 @@ |
||
12 | 12 | use Symfony\Polyfill\Php80 as p; |
13 | 13 | |
14 | 14 | if (\PHP_VERSION_ID >= 80000) { |
15 | - return; |
|
15 | + return; |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | if (!defined('FILTER_VALIDATE_BOOL') && defined('FILTER_VALIDATE_BOOLEAN')) { |
19 | - define('FILTER_VALIDATE_BOOL', \FILTER_VALIDATE_BOOLEAN); |
|
19 | + define('FILTER_VALIDATE_BOOL', \FILTER_VALIDATE_BOOLEAN); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | if (!function_exists('fdiv')) { |
23 | - function fdiv(float $num1, float $num2): float { return p\Php80::fdiv($num1, $num2); } |
|
23 | + function fdiv(float $num1, float $num2): float { return p\Php80::fdiv($num1, $num2); } |
|
24 | 24 | } |
25 | 25 | if (!function_exists('preg_last_error_msg')) { |
26 | - function preg_last_error_msg(): string { return p\Php80::preg_last_error_msg(); } |
|
26 | + function preg_last_error_msg(): string { return p\Php80::preg_last_error_msg(); } |
|
27 | 27 | } |
28 | 28 | if (!function_exists('str_contains')) { |
29 | - function str_contains(?string $haystack, ?string $needle): bool { return p\Php80::str_contains($haystack ?? '', $needle ?? ''); } |
|
29 | + function str_contains(?string $haystack, ?string $needle): bool { return p\Php80::str_contains($haystack ?? '', $needle ?? ''); } |
|
30 | 30 | } |
31 | 31 | if (!function_exists('str_starts_with')) { |
32 | - function str_starts_with(?string $haystack, ?string $needle): bool { return p\Php80::str_starts_with($haystack ?? '', $needle ?? ''); } |
|
32 | + function str_starts_with(?string $haystack, ?string $needle): bool { return p\Php80::str_starts_with($haystack ?? '', $needle ?? ''); } |
|
33 | 33 | } |
34 | 34 | if (!function_exists('str_ends_with')) { |
35 | - function str_ends_with(?string $haystack, ?string $needle): bool { return p\Php80::str_ends_with($haystack ?? '', $needle ?? ''); } |
|
35 | + function str_ends_with(?string $haystack, ?string $needle): bool { return p\Php80::str_ends_with($haystack ?? '', $needle ?? ''); } |
|
36 | 36 | } |
37 | 37 | if (!function_exists('get_debug_type')) { |
38 | - function get_debug_type($value): string { return p\Php80::get_debug_type($value); } |
|
38 | + function get_debug_type($value): string { return p\Php80::get_debug_type($value); } |
|
39 | 39 | } |
40 | 40 | if (!function_exists('get_resource_id')) { |
41 | - function get_resource_id($resource): int { return p\Php80::get_resource_id($resource); } |
|
41 | + function get_resource_id($resource): int { return p\Php80::get_resource_id($resource); } |
|
42 | 42 | } |
@@ -11,32 +11,32 @@ |
||
11 | 11 | |
12 | 12 | use Symfony\Polyfill\Php80 as p; |
13 | 13 | |
14 | -if (\PHP_VERSION_ID >= 80000) { |
|
14 | +if ( \PHP_VERSION_ID >= 80000 ) { |
|
15 | 15 | return; |
16 | 16 | } |
17 | 17 | |
18 | -if (!defined('FILTER_VALIDATE_BOOL') && defined('FILTER_VALIDATE_BOOLEAN')) { |
|
19 | - define('FILTER_VALIDATE_BOOL', \FILTER_VALIDATE_BOOLEAN); |
|
18 | +if ( ! defined( 'FILTER_VALIDATE_BOOL' ) && defined( 'FILTER_VALIDATE_BOOLEAN' ) ) { |
|
19 | + define( 'FILTER_VALIDATE_BOOL', \FILTER_VALIDATE_BOOLEAN ); |
|
20 | 20 | } |
21 | 21 | |
22 | -if (!function_exists('fdiv')) { |
|
23 | - function fdiv(float $num1, float $num2): float { return p\Php80::fdiv($num1, $num2); } |
|
22 | +if ( ! function_exists( 'fdiv' ) ) { |
|
23 | + function fdiv( float $num1, float $num2 ): float { return p\Php80::fdiv( $num1, $num2 ); } |
|
24 | 24 | } |
25 | -if (!function_exists('preg_last_error_msg')) { |
|
25 | +if ( ! function_exists( 'preg_last_error_msg' ) ) { |
|
26 | 26 | function preg_last_error_msg(): string { return p\Php80::preg_last_error_msg(); } |
27 | 27 | } |
28 | -if (!function_exists('str_contains')) { |
|
29 | - function str_contains(?string $haystack, ?string $needle): bool { return p\Php80::str_contains($haystack ?? '', $needle ?? ''); } |
|
28 | +if ( ! function_exists( 'str_contains' ) ) { |
|
29 | + function str_contains( ?string $haystack, ?string $needle ): bool { return p\Php80::str_contains( $haystack ?? '', $needle ?? '' ); } |
|
30 | 30 | } |
31 | -if (!function_exists('str_starts_with')) { |
|
32 | - function str_starts_with(?string $haystack, ?string $needle): bool { return p\Php80::str_starts_with($haystack ?? '', $needle ?? ''); } |
|
31 | +if ( ! function_exists( 'str_starts_with' ) ) { |
|
32 | + function str_starts_with( ?string $haystack, ?string $needle ): bool { return p\Php80::str_starts_with( $haystack ?? '', $needle ?? '' ); } |
|
33 | 33 | } |
34 | -if (!function_exists('str_ends_with')) { |
|
35 | - function str_ends_with(?string $haystack, ?string $needle): bool { return p\Php80::str_ends_with($haystack ?? '', $needle ?? ''); } |
|
34 | +if ( ! function_exists( 'str_ends_with' ) ) { |
|
35 | + function str_ends_with( ?string $haystack, ?string $needle ): bool { return p\Php80::str_ends_with( $haystack ?? '', $needle ?? '' ); } |
|
36 | 36 | } |
37 | -if (!function_exists('get_debug_type')) { |
|
38 | - function get_debug_type($value): string { return p\Php80::get_debug_type($value); } |
|
37 | +if ( ! function_exists( 'get_debug_type' ) ) { |
|
38 | + function get_debug_type( $value ): string { return p\Php80::get_debug_type( $value ); } |
|
39 | 39 | } |
40 | -if (!function_exists('get_resource_id')) { |
|
41 | - function get_resource_id($resource): int { return p\Php80::get_resource_id($resource); } |
|
40 | +if ( ! function_exists( 'get_resource_id' ) ) { |
|
41 | + function get_resource_id( $resource ): int { return p\Php80::get_resource_id( $resource ); } |
|
42 | 42 | } |
@@ -20,86 +20,86 @@ |
||
20 | 20 | */ |
21 | 21 | final class Php80 |
22 | 22 | { |
23 | - public static function fdiv(float $dividend, float $divisor): float |
|
24 | - { |
|
25 | - return @($dividend / $divisor); |
|
26 | - } |
|
23 | + public static function fdiv(float $dividend, float $divisor): float |
|
24 | + { |
|
25 | + return @($dividend / $divisor); |
|
26 | + } |
|
27 | 27 | |
28 | - public static function get_debug_type($value): string |
|
29 | - { |
|
30 | - switch (true) { |
|
31 | - case null === $value: return 'null'; |
|
32 | - case \is_bool($value): return 'bool'; |
|
33 | - case \is_string($value): return 'string'; |
|
34 | - case \is_array($value): return 'array'; |
|
35 | - case \is_int($value): return 'int'; |
|
36 | - case \is_float($value): return 'float'; |
|
37 | - case \is_object($value): break; |
|
38 | - case $value instanceof \__PHP_Incomplete_Class: return '__PHP_Incomplete_Class'; |
|
39 | - default: |
|
40 | - if (null === $type = @get_resource_type($value)) { |
|
41 | - return 'unknown'; |
|
42 | - } |
|
28 | + public static function get_debug_type($value): string |
|
29 | + { |
|
30 | + switch (true) { |
|
31 | + case null === $value: return 'null'; |
|
32 | + case \is_bool($value): return 'bool'; |
|
33 | + case \is_string($value): return 'string'; |
|
34 | + case \is_array($value): return 'array'; |
|
35 | + case \is_int($value): return 'int'; |
|
36 | + case \is_float($value): return 'float'; |
|
37 | + case \is_object($value): break; |
|
38 | + case $value instanceof \__PHP_Incomplete_Class: return '__PHP_Incomplete_Class'; |
|
39 | + default: |
|
40 | + if (null === $type = @get_resource_type($value)) { |
|
41 | + return 'unknown'; |
|
42 | + } |
|
43 | 43 | |
44 | - if ('Unknown' === $type) { |
|
45 | - $type = 'closed'; |
|
46 | - } |
|
44 | + if ('Unknown' === $type) { |
|
45 | + $type = 'closed'; |
|
46 | + } |
|
47 | 47 | |
48 | - return "resource ($type)"; |
|
49 | - } |
|
48 | + return "resource ($type)"; |
|
49 | + } |
|
50 | 50 | |
51 | - $class = \get_class($value); |
|
51 | + $class = \get_class($value); |
|
52 | 52 | |
53 | - if (false === strpos($class, '@')) { |
|
54 | - return $class; |
|
55 | - } |
|
53 | + if (false === strpos($class, '@')) { |
|
54 | + return $class; |
|
55 | + } |
|
56 | 56 | |
57 | - return (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous'; |
|
58 | - } |
|
57 | + return (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous'; |
|
58 | + } |
|
59 | 59 | |
60 | - public static function get_resource_id($res): int |
|
61 | - { |
|
62 | - if (!\is_resource($res) && null === @get_resource_type($res)) { |
|
63 | - throw new \TypeError(sprintf('Argument 1 passed to get_resource_id() must be of the type resource, %s given', get_debug_type($res))); |
|
64 | - } |
|
60 | + public static function get_resource_id($res): int |
|
61 | + { |
|
62 | + if (!\is_resource($res) && null === @get_resource_type($res)) { |
|
63 | + throw new \TypeError(sprintf('Argument 1 passed to get_resource_id() must be of the type resource, %s given', get_debug_type($res))); |
|
64 | + } |
|
65 | 65 | |
66 | - return (int) $res; |
|
67 | - } |
|
66 | + return (int) $res; |
|
67 | + } |
|
68 | 68 | |
69 | - public static function preg_last_error_msg(): string |
|
70 | - { |
|
71 | - switch (preg_last_error()) { |
|
72 | - case \PREG_INTERNAL_ERROR: |
|
73 | - return 'Internal error'; |
|
74 | - case \PREG_BAD_UTF8_ERROR: |
|
75 | - return 'Malformed UTF-8 characters, possibly incorrectly encoded'; |
|
76 | - case \PREG_BAD_UTF8_OFFSET_ERROR: |
|
77 | - return 'The offset did not correspond to the beginning of a valid UTF-8 code point'; |
|
78 | - case \PREG_BACKTRACK_LIMIT_ERROR: |
|
79 | - return 'Backtrack limit exhausted'; |
|
80 | - case \PREG_RECURSION_LIMIT_ERROR: |
|
81 | - return 'Recursion limit exhausted'; |
|
82 | - case \PREG_JIT_STACKLIMIT_ERROR: |
|
83 | - return 'JIT stack limit exhausted'; |
|
84 | - case \PREG_NO_ERROR: |
|
85 | - return 'No error'; |
|
86 | - default: |
|
87 | - return 'Unknown error'; |
|
88 | - } |
|
89 | - } |
|
69 | + public static function preg_last_error_msg(): string |
|
70 | + { |
|
71 | + switch (preg_last_error()) { |
|
72 | + case \PREG_INTERNAL_ERROR: |
|
73 | + return 'Internal error'; |
|
74 | + case \PREG_BAD_UTF8_ERROR: |
|
75 | + return 'Malformed UTF-8 characters, possibly incorrectly encoded'; |
|
76 | + case \PREG_BAD_UTF8_OFFSET_ERROR: |
|
77 | + return 'The offset did not correspond to the beginning of a valid UTF-8 code point'; |
|
78 | + case \PREG_BACKTRACK_LIMIT_ERROR: |
|
79 | + return 'Backtrack limit exhausted'; |
|
80 | + case \PREG_RECURSION_LIMIT_ERROR: |
|
81 | + return 'Recursion limit exhausted'; |
|
82 | + case \PREG_JIT_STACKLIMIT_ERROR: |
|
83 | + return 'JIT stack limit exhausted'; |
|
84 | + case \PREG_NO_ERROR: |
|
85 | + return 'No error'; |
|
86 | + default: |
|
87 | + return 'Unknown error'; |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - public static function str_contains(string $haystack, string $needle): bool |
|
92 | - { |
|
93 | - return '' === $needle || false !== strpos($haystack, $needle); |
|
94 | - } |
|
91 | + public static function str_contains(string $haystack, string $needle): bool |
|
92 | + { |
|
93 | + return '' === $needle || false !== strpos($haystack, $needle); |
|
94 | + } |
|
95 | 95 | |
96 | - public static function str_starts_with(string $haystack, string $needle): bool |
|
97 | - { |
|
98 | - return 0 === strncmp($haystack, $needle, \strlen($needle)); |
|
99 | - } |
|
96 | + public static function str_starts_with(string $haystack, string $needle): bool |
|
97 | + { |
|
98 | + return 0 === strncmp($haystack, $needle, \strlen($needle)); |
|
99 | + } |
|
100 | 100 | |
101 | - public static function str_ends_with(string $haystack, string $needle): bool |
|
102 | - { |
|
103 | - return '' === $needle || ('' !== $haystack && 0 === substr_compare($haystack, $needle, -\strlen($needle))); |
|
104 | - } |
|
101 | + public static function str_ends_with(string $haystack, string $needle): bool |
|
102 | + { |
|
103 | + return '' === $needle || ('' !== $haystack && 0 === substr_compare($haystack, $needle, -\strlen($needle))); |
|
104 | + } |
|
105 | 105 | } |
@@ -20,55 +20,55 @@ discard block |
||
20 | 20 | */ |
21 | 21 | final class Php80 |
22 | 22 | { |
23 | - public static function fdiv(float $dividend, float $divisor): float |
|
23 | + public static function fdiv( float $dividend, float $divisor ): float |
|
24 | 24 | { |
25 | - return @($dividend / $divisor); |
|
25 | + return @( $dividend / $divisor ); |
|
26 | 26 | } |
27 | 27 | |
28 | - public static function get_debug_type($value): string |
|
28 | + public static function get_debug_type( $value ): string |
|
29 | 29 | { |
30 | - switch (true) { |
|
30 | + switch ( true ) { |
|
31 | 31 | case null === $value: return 'null'; |
32 | - case \is_bool($value): return 'bool'; |
|
33 | - case \is_string($value): return 'string'; |
|
34 | - case \is_array($value): return 'array'; |
|
35 | - case \is_int($value): return 'int'; |
|
36 | - case \is_float($value): return 'float'; |
|
37 | - case \is_object($value): break; |
|
32 | + case \is_bool( $value ): return 'bool'; |
|
33 | + case \is_string( $value ): return 'string'; |
|
34 | + case \is_array( $value ): return 'array'; |
|
35 | + case \is_int( $value ): return 'int'; |
|
36 | + case \is_float( $value ): return 'float'; |
|
37 | + case \is_object( $value ): break; |
|
38 | 38 | case $value instanceof \__PHP_Incomplete_Class: return '__PHP_Incomplete_Class'; |
39 | 39 | default: |
40 | - if (null === $type = @get_resource_type($value)) { |
|
40 | + if ( null === $type = @get_resource_type( $value ) ) { |
|
41 | 41 | return 'unknown'; |
42 | 42 | } |
43 | 43 | |
44 | - if ('Unknown' === $type) { |
|
44 | + if ( 'Unknown' === $type ) { |
|
45 | 45 | $type = 'closed'; |
46 | 46 | } |
47 | 47 | |
48 | 48 | return "resource ($type)"; |
49 | 49 | } |
50 | 50 | |
51 | - $class = \get_class($value); |
|
51 | + $class = \get_class( $value ); |
|
52 | 52 | |
53 | - if (false === strpos($class, '@')) { |
|
53 | + if ( false === strpos( $class, '@' ) ) { |
|
54 | 54 | return $class; |
55 | 55 | } |
56 | 56 | |
57 | - return (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous'; |
|
57 | + return ( get_parent_class( $class ) ?: key( class_implements( $class ) ) ?: 'class' ) . '@anonymous'; |
|
58 | 58 | } |
59 | 59 | |
60 | - public static function get_resource_id($res): int |
|
60 | + public static function get_resource_id( $res ): int |
|
61 | 61 | { |
62 | - if (!\is_resource($res) && null === @get_resource_type($res)) { |
|
63 | - throw new \TypeError(sprintf('Argument 1 passed to get_resource_id() must be of the type resource, %s given', get_debug_type($res))); |
|
62 | + if ( ! \is_resource( $res ) && null === @get_resource_type( $res ) ) { |
|
63 | + throw new \TypeError( sprintf( 'Argument 1 passed to get_resource_id() must be of the type resource, %s given', get_debug_type( $res ) ) ); |
|
64 | 64 | } |
65 | 65 | |
66 | - return (int) $res; |
|
66 | + return (int)$res; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | public static function preg_last_error_msg(): string |
70 | 70 | { |
71 | - switch (preg_last_error()) { |
|
71 | + switch ( preg_last_error() ) { |
|
72 | 72 | case \PREG_INTERNAL_ERROR: |
73 | 73 | return 'Internal error'; |
74 | 74 | case \PREG_BAD_UTF8_ERROR: |
@@ -88,18 +88,18 @@ discard block |
||
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
91 | - public static function str_contains(string $haystack, string $needle): bool |
|
91 | + public static function str_contains( string $haystack, string $needle ): bool |
|
92 | 92 | { |
93 | - return '' === $needle || false !== strpos($haystack, $needle); |
|
93 | + return '' === $needle || false !== strpos( $haystack, $needle ); |
|
94 | 94 | } |
95 | 95 | |
96 | - public static function str_starts_with(string $haystack, string $needle): bool |
|
96 | + public static function str_starts_with( string $haystack, string $needle ): bool |
|
97 | 97 | { |
98 | - return 0 === strncmp($haystack, $needle, \strlen($needle)); |
|
98 | + return 0 === strncmp( $haystack, $needle, \strlen( $needle ) ); |
|
99 | 99 | } |
100 | 100 | |
101 | - public static function str_ends_with(string $haystack, string $needle): bool |
|
101 | + public static function str_ends_with( string $haystack, string $needle ): bool |
|
102 | 102 | { |
103 | - return '' === $needle || ('' !== $haystack && 0 === substr_compare($haystack, $needle, -\strlen($needle))); |
|
103 | + return '' === $needle || ( '' !== $haystack && 0 === substr_compare( $haystack, $needle, -\strlen( $needle ) ) ); |
|
104 | 104 | } |
105 | 105 | } |
@@ -18,8 +18,7 @@ |
||
18 | 18 | * |
19 | 19 | * @internal |
20 | 20 | */ |
21 | -final class Php80 |
|
22 | -{ |
|
21 | +final class Php80 { |
|
23 | 22 | public static function fdiv(float $dividend, float $divisor): float |
24 | 23 | { |
25 | 24 | return @($dividend / $divisor); |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (\PHP_VERSION_ID < 80000) { |
4 | - interface Stringable |
|
5 | - { |
|
6 | - /** |
|
7 | - * @return string |
|
8 | - */ |
|
9 | - public function __toString(); |
|
10 | - } |
|
4 | + interface Stringable |
|
5 | + { |
|
6 | + /** |
|
7 | + * @return string |
|
8 | + */ |
|
9 | + public function __toString(); |
|
10 | + } |
|
11 | 11 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (\PHP_VERSION_ID < 80000) { |
|
3 | +if ( \PHP_VERSION_ID < 80000 ) { |
|
4 | 4 | interface Stringable |
5 | 5 | { |
6 | 6 | /** |
@@ -1,8 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (\PHP_VERSION_ID < 80000) { |
4 | - interface Stringable |
|
5 | - { |
|
4 | + interface Stringable { |
|
6 | 5 | /** |
7 | 6 | * @return string |
8 | 7 | */ |
@@ -1,5 +1,4 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class ValueError extends Error |
|
4 | -{ |
|
3 | +class ValueError extends Error { |
|
5 | 4 | } |
@@ -1,5 +1,4 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class UnhandledMatchError extends Error |
|
4 | -{ |
|
3 | +class UnhandledMatchError extends Error { |
|
5 | 4 | } |
@@ -3,20 +3,20 @@ |
||
3 | 3 | #[Attribute(Attribute::TARGET_CLASS)] |
4 | 4 | final class Attribute |
5 | 5 | { |
6 | - public const TARGET_CLASS = 1; |
|
7 | - public const TARGET_FUNCTION = 2; |
|
8 | - public const TARGET_METHOD = 4; |
|
9 | - public const TARGET_PROPERTY = 8; |
|
10 | - public const TARGET_CLASS_CONSTANT = 16; |
|
11 | - public const TARGET_PARAMETER = 32; |
|
12 | - public const TARGET_ALL = 63; |
|
13 | - public const IS_REPEATABLE = 64; |
|
6 | + public const TARGET_CLASS = 1; |
|
7 | + public const TARGET_FUNCTION = 2; |
|
8 | + public const TARGET_METHOD = 4; |
|
9 | + public const TARGET_PROPERTY = 8; |
|
10 | + public const TARGET_CLASS_CONSTANT = 16; |
|
11 | + public const TARGET_PARAMETER = 32; |
|
12 | + public const TARGET_ALL = 63; |
|
13 | + public const IS_REPEATABLE = 64; |
|
14 | 14 | |
15 | - /** @var int */ |
|
16 | - public $flags; |
|
15 | + /** @var int */ |
|
16 | + public $flags; |
|
17 | 17 | |
18 | - public function __construct(int $flags = self::TARGET_ALL) |
|
19 | - { |
|
20 | - $this->flags = $flags; |
|
21 | - } |
|
18 | + public function __construct(int $flags = self::TARGET_ALL) |
|
19 | + { |
|
20 | + $this->flags = $flags; |
|
21 | + } |
|
22 | 22 | } |
@@ -15,7 +15,7 @@ |
||
15 | 15 | /** @var int */ |
16 | 16 | public $flags; |
17 | 17 | |
18 | - public function __construct(int $flags = self::TARGET_ALL) |
|
18 | + public function __construct( int $flags = self::TARGET_ALL ) |
|
19 | 19 | { |
20 | 20 | $this->flags = $flags; |
21 | 21 | } |
@@ -1,8 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | #[Attribute(Attribute::TARGET_CLASS)] |
4 | -final class Attribute |
|
5 | -{ |
|
4 | +final class Attribute { |
|
6 | 5 | public const TARGET_CLASS = 1; |
7 | 6 | public const TARGET_FUNCTION = 2; |
8 | 7 | public const TARGET_METHOD = 4; |
@@ -15,8 +14,7 @@ discard block |
||
15 | 14 | /** @var int */ |
16 | 15 | public $flags; |
17 | 16 | |
18 | - public function __construct(int $flags = self::TARGET_ALL) |
|
19 | - { |
|
17 | + public function __construct(int $flags = self::TARGET_ALL) { |
|
20 | 18 | $this->flags = $flags; |
21 | 19 | } |
22 | 20 | } |
@@ -12,20 +12,20 @@ |
||
12 | 12 | use Symfony\Polyfill\Php73 as p; |
13 | 13 | |
14 | 14 | if (\PHP_VERSION_ID >= 70300) { |
15 | - return; |
|
15 | + return; |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | if (!function_exists('is_countable')) { |
19 | - function is_countable($value) { return is_array($value) || $value instanceof Countable || $value instanceof ResourceBundle || $value instanceof SimpleXmlElement; } |
|
19 | + function is_countable($value) { return is_array($value) || $value instanceof Countable || $value instanceof ResourceBundle || $value instanceof SimpleXmlElement; } |
|
20 | 20 | } |
21 | 21 | if (!function_exists('hrtime')) { |
22 | - require_once __DIR__.'/Php73.php'; |
|
23 | - p\Php73::$startAt = (int) microtime(true); |
|
24 | - function hrtime($as_number = false) { return p\Php73::hrtime($as_number); } |
|
22 | + require_once __DIR__.'/Php73.php'; |
|
23 | + p\Php73::$startAt = (int) microtime(true); |
|
24 | + function hrtime($as_number = false) { return p\Php73::hrtime($as_number); } |
|
25 | 25 | } |
26 | 26 | if (!function_exists('array_key_first')) { |
27 | - function array_key_first(array $array) { foreach ($array as $key => $value) { return $key; } } |
|
27 | + function array_key_first(array $array) { foreach ($array as $key => $value) { return $key; } } |
|
28 | 28 | } |
29 | 29 | if (!function_exists('array_key_last')) { |
30 | - function array_key_last(array $array) { return key(array_slice($array, -1, 1, true)); } |
|
30 | + function array_key_last(array $array) { return key(array_slice($array, -1, 1, true)); } |
|
31 | 31 | } |
@@ -11,21 +11,21 @@ |
||
11 | 11 | |
12 | 12 | use Symfony\Polyfill\Php73 as p; |
13 | 13 | |
14 | -if (\PHP_VERSION_ID >= 70300) { |
|
14 | +if ( \PHP_VERSION_ID >= 70300 ) { |
|
15 | 15 | return; |
16 | 16 | } |
17 | 17 | |
18 | -if (!function_exists('is_countable')) { |
|
19 | - function is_countable($value) { return is_array($value) || $value instanceof Countable || $value instanceof ResourceBundle || $value instanceof SimpleXmlElement; } |
|
18 | +if ( ! function_exists( 'is_countable' ) ) { |
|
19 | + function is_countable( $value ) { return is_array( $value ) || $value instanceof Countable || $value instanceof ResourceBundle || $value instanceof SimpleXmlElement; } |
|
20 | 20 | } |
21 | -if (!function_exists('hrtime')) { |
|
22 | - require_once __DIR__.'/Php73.php'; |
|
23 | - p\Php73::$startAt = (int) microtime(true); |
|
24 | - function hrtime($as_number = false) { return p\Php73::hrtime($as_number); } |
|
21 | +if ( ! function_exists( 'hrtime' ) ) { |
|
22 | + require_once __DIR__ . '/Php73.php'; |
|
23 | + p\Php73::$startAt = (int)microtime( true ); |
|
24 | + function hrtime( $as_number = false ) { return p\Php73::hrtime( $as_number ); } |
|
25 | 25 | } |
26 | -if (!function_exists('array_key_first')) { |
|
27 | - function array_key_first(array $array) { foreach ($array as $key => $value) { return $key; } } |
|
26 | +if ( ! function_exists( 'array_key_first' ) ) { |
|
27 | + function array_key_first( array $array ) { foreach ( $array as $key => $value ) { return $key; } } |
|
28 | 28 | } |
29 | -if (!function_exists('array_key_last')) { |
|
30 | - function array_key_last(array $array) { return key(array_slice($array, -1, 1, true)); } |
|
29 | +if ( ! function_exists( 'array_key_last' ) ) { |
|
30 | + function array_key_last( array $array ) { return key( array_slice( $array, -1, 1, true ) ); } |
|
31 | 31 | } |