Completed
Push — master ( 87aba0...0e8729 )
by Andreas
25s queued 16s
created

lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Out.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
class Out extends BaseStage\Out
30
{
31
    /**
32
     * @var DocumentManager
33
     */
34
    private $dm;
35
36
    /**
37
     * @param Builder $builder
38
     * @param string $collection
39
     * @param DocumentManager $documentManager
40
     */
41 4
    public function __construct(Builder $builder, $collection, DocumentManager $documentManager)
42
    {
43 4
        $this->dm = $documentManager;
44
45 4
        parent::__construct($builder, $collection);
46 3
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 4
    public function out($collection)
52
    {
53
        try {
54 4
            $class = $this->dm->getClassMetadata($collection);
55 2
        } catch (BaseMappingException $e) {
56 2
            return parent::out($collection);
57
        }
58
59 2
        return $this->fromDocument($class);
60
    }
61
62
    /**
63
     * @param ClassMetadata $classMetadata
64
     * @return $this
65
     *
66
     * @throws MappingException
67
     */
68 2
    private function fromDocument(ClassMetadata $classMetadata)
69
    {
70 2
        if ($classMetadata->isSharded()) {
71 1
            throw MappingException::cannotUseShardedCollectionInOutStage($classMetadata->name);
72
        }
73
74 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...
75
    }
76
}
77