CouchbaseLock::release()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
8
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
10
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
11
 * THE SOFTWARE.
12
 */
13
14
namespace Ytake\LaravelCouchbase\Cache;
15
16
use Couchbase\Bucket;
17
use Couchbase\Document;
18
use Couchbase\Exception as CouchbaseException;
19
use Illuminate\Cache\Lock;
20
use Illuminate\Contracts\Cache\Lock as Lockable;
21
22
/**
23
 * Class CouchbaseLock
24
 *
25
 * @author Yuuki Takezawa<[email protected]>
26
 */
27
class CouchbaseLock extends Lock implements Lockable
28
{
29
    /** @var Bucket */
30
    protected $bucket;
31
32
    /**
33
     * CouchbaseLock constructor.
34
     *
35
     * @param Bucket $bucket
36
     * @param string $name
37
     * @param int    $seconds
38
     */
39 2
    public function __construct(Bucket $bucket, string $name, int $seconds)
40
    {
41 2
        parent::__construct($name, $seconds);
42
43 2
        $this->bucket = $bucket;
44 2
    }
45
46
    /**
47
     * @return bool
48
     */
49 2
    public function acquire()
50
    {
51
        try {
52 2
            $result = $this->bucket->insert($this->name, 1, ['expiry' => $this->seconds]);
53 2
            if ($result instanceof Document) {
0 ignored issues
show
Bug introduced by
The class Couchbase\Document does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
54 2
                return true;
55
            }
56 2
        } catch (CouchbaseException $e) {
0 ignored issues
show
Bug introduced by
The class Couchbase\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
57 2
            return false;
58
        }
59
60
        return false;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 2
    public function release()
67
    {
68 2
        $this->bucket->remove($this->name);
69 2
    }
70
}
71