QueryPrepared::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 1
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\Events;
15
16
use Couchbase\N1qlQuery;
17
18
/**
19
 * Class QueryPrepared
20
 *
21
 * @author Yuuki Takezawa<[email protected]>
22
 */
23
final class QueryPrepared
24
{
25
    /** @var N1qlQuery */
26
    private $object;
27
28
    /**
29
     * QueryPrepared constructor.
30
     *
31
     * @param mixed $queryObject
32
     */
33 16
    public function __construct($queryObject)
34
    {
35 16
        if ($this->isN1ql($queryObject)) {
36 16
            $this->object = $queryObject;
37
        }
38 16
    }
39
40
    /**
41
     * @param mixed $queryObject
42
     *
43
     * @return bool
44
     */
45 16
    private function isN1ql($queryObject): bool
46
    {
47 16
        if ($queryObject instanceof N1qlQuery) {
0 ignored issues
show
Bug introduced by
The class Couchbase\N1qlQuery 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...
48 16
            return true;
49
        }
50
51
        return false;
52
    }
53
54
    /**
55
     * @return N1qlQuery|null
56
     */
57 2
    public function getQuery(): ?N1qlQuery
58
    {
59 2
        return $this->object;
60
    }
61
}
62