| Conditions | 27 | 
| Paths | 1802 | 
| Total Lines | 83 | 
| Code Lines | 47 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php  | 
            ||
| 93 | public function readAndWrite($blocking, $close = false)  | 
            ||
| 94 |     { | 
            ||
| 95 | |||
| 96 |         if (1 === count($this->pipes) && [0] === array_keys($this->pipes)) { | 
            ||
| 97 | fclose($this->pipes[0]);  | 
            ||
| 98 | unset($this->pipes[0]);  | 
            ||
| 99 | }  | 
            ||
| 100 | |||
| 101 |         if (empty($this->pipes)) { | 
            ||
| 102 | return [];  | 
            ||
| 103 | }  | 
            ||
| 104 | |||
| 105 | $this->unblock();  | 
            ||
| 106 | |||
| 107 | $read = [];  | 
            ||
| 108 | |||
| 109 |         if (null !== $this->input) { | 
            ||
| 110 | $r = array_merge($this->pipes, ['input' => $this->input]);  | 
            ||
| 111 |         } else { | 
            ||
| 112 | $r = $this->pipes;  | 
            ||
| 113 | }  | 
            ||
| 114 | |||
| 115 | unset($r[0]);  | 
            ||
| 116 | |||
| 117 | $w = isset($this->pipes[0]) ? [$this->pipes[0]] : null;  | 
            ||
| 118 | $e = null;  | 
            ||
| 119 | |||
| 120 |         if (false === $n = @stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) { | 
            ||
| 121 | |||
| 122 |             if (!$this->hasSystemCallBeenInterrupted()) { | 
            ||
| 123 | $this->pipes = [];  | 
            ||
| 124 | }  | 
            ||
| 125 | |||
| 126 | return $read;  | 
            ||
| 127 | }  | 
            ||
| 128 | |||
| 129 |         if (0 === $n) { | 
            ||
| 130 | return $read;  | 
            ||
| 131 | }  | 
            ||
| 132 | |||
| 133 |         foreach ($r as $pipe) { | 
            ||
| 134 | |||
| 135 | $type = (false !== $found = array_search($pipe, $this->pipes)) ? $found : 'input';  | 
            ||
| 136 | $data = '';  | 
            ||
| 137 |             while ('' !== $dataread = (string) fread($pipe, self::CHUNK_SIZE)) { | 
            ||
| 138 | $data .= $dataread;  | 
            ||
| 139 | }  | 
            ||
| 140 | |||
| 141 |             if ('' !== $data) { | 
            ||
| 142 |                 if ('input' === $type) { | 
            ||
| 143 | $this->inputBuffer .= $data;  | 
            ||
| 144 |                 } else { | 
            ||
| 145 | $read[$type] = $data;  | 
            ||
| 146 | }  | 
            ||
| 147 | }  | 
            ||
| 148 | |||
| 149 |             if (false === $data || (true === $close && feof($pipe) && '' === $data)) { | 
            ||
| 150 |                 if ('input' === $type) { | 
            ||
| 151 | $this->input = null;  | 
            ||
| 152 |                 } else { | 
            ||
| 153 | fclose($this->pipes[$type]);  | 
            ||
| 154 | unset($this->pipes[$type]);  | 
            ||
| 155 | }  | 
            ||
| 156 | }  | 
            ||
| 157 | }  | 
            ||
| 158 | |||
| 159 |         if (null !== $w && 0 < count($w)) { | 
            ||
| 160 |             while (strlen($this->inputBuffer)) { | 
            ||
| 161 | $written = fwrite($w[0], $this->inputBuffer, 2 << 18); // write 512k  | 
            ||
| 162 |                 if ($written > 0) { | 
            ||
| 163 | $this->inputBuffer = (string) substr($this->inputBuffer, $written);  | 
            ||
| 164 |                 } else { | 
            ||
| 165 | break;  | 
            ||
| 166 | }  | 
            ||
| 167 | }  | 
            ||
| 168 | }  | 
            ||
| 169 | |||
| 170 |         if ('' === $this->inputBuffer && null === $this->input && isset($this->pipes[0])) { | 
            ||
| 171 | fclose($this->pipes[0]);  | 
            ||
| 172 | unset($this->pipes[0]);  | 
            ||
| 173 | }  | 
            ||
| 174 | |||
| 175 | return $read;  | 
            ||
| 176 | }  | 
            ||
| 197 |