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) { |
|
|
|
|
54
|
2 |
|
return true; |
55
|
|
|
} |
56
|
2 |
|
} catch (CouchbaseException $e) { |
|
|
|
|
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
|
|
|
|
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 thecomposer.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
orrequire-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 you have not tested against this specific condition, such errors might go unnoticed.