Code Duplication    Length = 29-29 lines in 2 locations

src/Generics/Socket/Socket.php 2 locations

@@ 87-115 (lines=29) @@
84
     * {@inheritDoc}
85
     * @see \Generics\Streams\Stream::ready()
86
     */
87
    public function ready()
88
    {
89
        if (! is_resource($this->handle)) {
90
            return false;
91
        }
92
93
        $read = array(
94
            $this->handle
95
        );
96
        $write = null;
97
        $except = null;
98
99
        $num = @socket_select($read, $write, $except, 0);
100
101
        if ($num === false) {
102
            $code = socket_last_error($this->handle);
103
            throw new SocketException(socket_strerror($code), array(), $code);
104
        }
105
106
        if ($num < 1) {
107
            return false;
108
        }
109
110
        if (! in_array($this->handle, $read)) {
111
            return false;
112
        }
113
114
        return true;
115
    }
116
117
    /**
118
     * {@inheritDoc}
@@ 121-149 (lines=29) @@
118
     * {@inheritDoc}
119
     * @see \Generics\Streams\OutputStream::isWriteable()
120
     */
121
    public function isWriteable()
122
    {
123
        if (! is_resource($this->handle)) {
124
            return false;
125
        }
126
127
        $read = null;
128
        $write = array(
129
            $this->handle
130
        );
131
        $except = null;
132
133
        $num = @socket_select($read, $write, $except, 0, 0);
134
135
        if ($num === false) {
136
            $code = socket_last_error($this->handle);
137
            throw new SocketException(socket_strerror($code), array(), $code);
138
        }
139
140
        if ($num < 1) {
141
            return false;
142
        }
143
144
        if (! in_array($this->handle, $write)) {
145
            return false;
146
        }
147
148
        return true;
149
    }
150
151
    /**
152
     * {@inheritDoc}