Completed
Pull Request — master (#1448)
by Andreas
11:03
created

Out::fromDocument()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
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
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\ODM\MongoDB\Aggregation\Stage;
21
22
use Doctrine\Common\Persistence\Mapping\MappingException as BaseMappingException;
23
use Doctrine\MongoDB\Aggregation\Stage as BaseStage;
24
use Doctrine\ODM\MongoDB\Aggregation\Builder;
25
use Doctrine\ODM\MongoDB\DocumentManager;
26
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
27
use Doctrine\ODM\MongoDB\Mapping\MappingException;
28
29
/**
30
 * @author alcaeus <[email protected]>
31
 */
32
class Out extends BaseStage\Out
33
{
34
    /**
35
     * @var DocumentManager
36
     */
37
    private $dm;
38
39
    /**
40
     * @param Builder $builder
41
     * @param string $collection
42
     * @param DocumentManager $documentManager
43
     */
44 4
    public function __construct(Builder $builder, $collection, DocumentManager $documentManager)
45
    {
46 4
        $this->dm = $documentManager;
47
48 4
        parent::__construct($builder, $collection);
49 3
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 4
    public function out($collection)
55
    {
56
        try {
57 4
            $class = $this->dm->getClassMetadata($collection);
58 2
        } catch (BaseMappingException $e) {
59 2
            return parent::out($collection);
60
        }
61
62 2
        return $this->fromDocument($class);
63
    }
64
65
    /**
66
     * @param ClassMetadata $classMetadata
67
     * @return $this
68
     *
69
     * @throws MappingException
70
     */
71 2
    private function fromDocument(ClassMetadata $classMetadata)
72
    {
73 2
        if ($classMetadata->isSharded()) {
74 1
            throw MappingException::cannotUseShardedCollectionInOutStage($classMetadata->name);
75
        }
76
77 1
        return parent::out($classMetadata->getCollection());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (out() instead of fromDocument()). Are you sure this is correct? If so, you might want to change this to $this->out().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
78
    }
79
}
80