Conditions | 11 |
Paths | 15 |
Total Lines | 40 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
53 | public function __construct($path, LoopInterface $loop = null, array $context = array()) |
||
54 | { |
||
55 | $this->loop = $loop ?: Loop::get(); |
||
56 | |||
57 | if (\strpos($path, '://') === false) { |
||
58 | $path = 'unix://' . $path; |
||
59 | } elseif (\substr($path, 0, 7) !== 'unix://') { |
||
60 | throw new \InvalidArgumentException( |
||
61 | 'Given URI "' . $path . '" is invalid (EINVAL)', |
||
62 | \defined('SOCKET_EINVAL') ? \SOCKET_EINVAL : 22 |
||
63 | ); |
||
64 | } |
||
65 | |||
66 | $this->master = @\stream_socket_server( |
||
67 | $path, |
||
68 | $errno, |
||
69 | $errstr, |
||
70 | \STREAM_SERVER_BIND | \STREAM_SERVER_LISTEN, |
||
71 | \stream_context_create(array('socket' => $context)) |
||
72 | ); |
||
73 | if (false === $this->master) { |
||
74 | // PHP does not seem to report errno/errstr for Unix domain sockets (UDS) right now. |
||
75 | // This only applies to UDS server sockets, see also https://3v4l.org/NAhpr. |
||
76 | // Parse PHP warning message containing unknown error, HHVM reports proper info at least. |
||
77 | if ($errno === 0 && $errstr === '') { |
||
78 | $error = \error_get_last(); |
||
79 | if (\preg_match('/\(([^\)]+)\)|\[(\d+)\]: (.*)/', $error['message'], $match)) { |
||
80 | $errstr = isset($match[3]) ? $match['3'] : $match[1]; |
||
81 | $errno = isset($match[2]) ? (int)$match[2] : 0; |
||
82 | } |
||
83 | } |
||
84 | |||
85 | throw new \RuntimeException( |
||
86 | 'Failed to listen on Unix domain socket "' . $path . '": ' . $errstr . SocketServer::errconst($errno), |
||
87 | $errno |
||
88 | ); |
||
89 | } |
||
90 | \stream_set_blocking($this->master, 0); |
||
91 | |||
92 | $this->resume(); |
||
93 | } |
||
155 |