Code Duplication    Length = 29-35 lines in 2 locations

Classes/RedisLockStrategy.php 1 location

@@ 163-191 (lines=29) @@
160
161
        if ($mode & self::LOCK_CAPABILITY_EXCLUSIVE) {
162
163
            if ($mode & self::LOCK_CAPABILITY_NOBLOCK) {
164
165
                // this does not block
166
                $this->isAcquired = $this->lock();
167
168
                if (!$this->isAcquired) {
169
                    throw new LockAcquireWouldBlockException('could not acquire lock');
170
                }
171
            } else {
172
173
                // try to acquire the lock
174
                // N.B. we do this in a loop because between
175
                // wait() and lock() another process may acquire the lock
176
                $waited = 0;
177
                do {
178
                    $start = time();
179
180
                    // this blocks till the lock gets released or timeout is reached
181
                    if (!$this->wait($this->blTo - $waited)) {
182
                        throw new LockAcquireException('could not acquire lock');
183
                    }
184
185
                    $waited += time() - $start;
186
187
                    // this does not block
188
                    $this->isAcquired = $this->lock();
189
190
                } while (!$this->isAcquired);
191
            }
192
        } else {
193
            throw new LockAcquireException('insufficient capabilities');
194
        }

Tests/test.php 1 location

@@ 166-200 (lines=35) @@
163
        }
164
165
        //if ($mode & self::LOCK_CAPABILITY_EXCLUSIVE) {
166
        if ($mode) {
167
168
            //if ($mode & self::LOCK_CAPABILITY_NOBLOCK) {
169
            if (!$mode) {
170
171
                $this->isAcquired = $this->lock();
172
173
                if (!$this->isAcquired) {
174
                    //throw new LockAcquireWouldBlockException('could not acquire lock');
175
                    throw new \Exception('could not acquire lock');
176
                }
177
            } else {
178
179
                // try to acquire the lock
180
                // N.B. we do this in a loop because between
181
                // wait() and lock() another process may acquire the lock
182
                $waited = 0;
183
                do {
184
                    $start = time();
185
186
                    // this blocks till the lock gets released or timeout is reached
187
                    if (!$this->wait($this->blTo - $waited)) {
188
                        throw new \Exception('could not acquire lock');
189
                    }
190
191
                    $waited += time() - $start;
192
193
                    $this->isAcquired = $this->lock();
194
195
                } while (!$this->isAcquired);
196
            }
197
        } else {
198
            //throw new LockAcquireException('insufficient capabilities');
199
            throw new \Exception('insufficient capabilities');
200
        }
201
202
        echo $this->id.' acquired lock: '.$this->value.PHP_EOL;
203