Code Duplication    Length = 14-14 lines in 3 locations

src/Async.php 3 locations

@@ 121-134 (lines=14) @@
118
            }
119
            if (is_callable($func)) {
120
                $this->logCallable($func, $args, $depth);
121
                $args[] = function ($error, $result) use ($flow, $callback, $depth) {
122
                    if ($error) {
123
                        if ($this->logger) {
124
                            $this->logger->error((string)$error, compact('depth'));
125
                        }
126
                        if (is_callable($callback)) {
127
                            $callback($error);
128
                        }
129
130
                        return;
131
                    }
132
                    $flow->send($result);
133
                    ($this->exec)($flow, $callback, $depth);
134
                };
135
                call_user_func_array($func, $args);
136
            } elseif ($value instanceof Generator) {
137
                $this->logGenerator($value, $depth);
@@ 138-151 (lines=14) @@
135
                call_user_func_array($func, $args);
136
            } elseif ($value instanceof Generator) {
137
                $this->logGenerator($value, $depth);
138
                ($this->exec)($value, function ($error, $result) use ($flow, $callback, $depth) {
139
                    if ($error) {
140
                        if ($this->logger) {
141
                            $this->logger->error((string)$error);
142
                        }
143
                        if (is_callable($callback)) {
144
                            $callback($error);
145
                        }
146
147
                        return;
148
                    }
149
                    $flow->send($result);
150
                    ($this->exec)($flow, $callback, $depth);
151
                }, $depth + 1);
152
            } elseif (is_a($value, static::PROMISE_REACT)) {
153
                $this->handlePromise($flow, $callback, $depth, $value, 'react');
154
            } elseif (is_a($value, static::PROMISE_GUZZLE)) {
@@ 165-178 (lines=14) @@
162
                    $this->logger->info('await $ampPromise;');
163
                }
164
                $value->onResolve(
165
                    function ($error, $result) use ($flow, $callback, $depth) {
166
                        if ($error) {
167
                            if ($this->logger) {
168
                                $this->logger->error((string)$error);
169
                            }
170
                            if (is_callable($callback)) {
171
                                $callback($error);
172
                            }
173
174
                            return;
175
                        }
176
                        $flow->send($result);
177
                        ($this->exec)($flow, $callback, $depth);
178
                    }
179
                );
180
            } else {
181
                $flow->send($value);