Completed
Pull Request — master (#10)
by Andreas
02:41
created

MongoCommandCursor::createFromDocument()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
nc 1
cc 1
eloc 2
nop 3
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 */
15
16
use Alcaeus\MongoDbAdapter\AbstractCursor;
17
use Alcaeus\MongoDbAdapter\TypeConverter;
18
19
class MongoCommandCursor extends AbstractCursor implements MongoCursorInterface
1 ignored issue
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
20
{
21
    /**
22
     * @var array
23
     */
24
    private $command;
25
26
    /**
27
     * MongoCommandCursor constructor.
28
     * @param MongoClient $connection
29
     * @param string $ns
30
     * @param array $command
31
     */
32
    public function __construct(MongoClient $connection, $ns, array $command = [])
33
    {
34
        parent::__construct($connection, $ns);
35
36
        $this->command = $command;
37
    }
38
39
    /**
40
     * @param MongoClient $connection
41
     * @param string $hash
42
     * @param array $document
43
     * @return MongoCommandCursor
44
     */
45
    public static function createFromDocument(MongoClient $connection, $hash, array $document)
0 ignored issues
show
Unused Code introduced by
The parameter $connection is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $hash is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $document is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
    {
47
        throw new \Exception('Not implemented');
48
    }
49
50
    /**
51
     * @return \MongoDB\Driver\Cursor
52
     */
53
    protected function ensureCursor()
54
    {
55
        if ($this->cursor === null) {
56
            $this->cursor = $this->db->command(TypeConverter::convertLegacyArrayToObject($this->command), $this->getOptions());
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->db->command(\Alca...), $this->getOptions()) of type integer is incompatible with the declared type object<MongoDB\Driver\Cursor> of property $cursor.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
57
        }
58
59
        return $this->cursor;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->cursor; of type integer|MongoDB\Driver\Cursor adds the type integer to the return on line 59 which is incompatible with the return type declared by the abstract method Alcaeus\MongoDbAdapter\A...actCursor::ensureCursor of type MongoDB\Driver\Cursor.
Loading history...
60
    }
61
62
    /**
63
     * @return array
64
     */
65
    protected function getCursorInfo()
66
    {
67
        return [
68
            'ns' => $this->ns,
69
            'limit' => 0,
70
            'batchSize' => 0,
71
            'skip' => 0,
72
            'flags' => 0,
73
            'query' => $this->command,
74
            'fields' => null,
75
        ];
76
    }
77
}
78