Code Duplication    Length = 39-39 lines in 3 locations

lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket.php 1 location

@@ 11-49 (lines=39) @@
8
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
9
use Doctrine\ODM\MongoDB\Types\Type;
10
11
class Bucket extends BaseStage\Bucket
12
{
13
    /**
14
     * @var DocumentManager
15
     */
16
    private $dm;
17
18
    /**
19
     * @var ClassMetadata
20
     */
21
    private $class;
22
23
    public function __construct(Builder $builder, DocumentManager $documentManager, ClassMetadata $class)
24
    {
25
        $this->dm = $documentManager;
26
        $this->class = $class;
27
28
        parent::__construct($builder);
29
    }
30
31
    protected function convertExpression($expression)
32
    {
33
        if (is_array($expression)) {
34
            return array_map([$this, 'convertExpression'], $expression);
35
        } elseif (is_string($expression) && substr($expression, 0, 1) === '$') {
36
            return '$' . $this->getDocumentPersister()->prepareFieldName(substr($expression, 1));
37
        } else {
38
            return Type::convertPHPToDatabaseValue(parent::convertExpression($expression));
39
        }
40
    }
41
42
    /**
43
     * @return \Doctrine\ODM\MongoDB\Persisters\DocumentPersister
44
     */
45
    private function getDocumentPersister()
46
    {
47
        return $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name);
48
    }
49
}
50

lib/Doctrine/ODM/MongoDB/Aggregation/Stage/BucketAuto.php 1 location

@@ 11-49 (lines=39) @@
8
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
9
use Doctrine\ODM\MongoDB\Types\Type;
10
11
class BucketAuto extends BaseStage\BucketAuto
12
{
13
    /**
14
     * @var DocumentManager
15
     */
16
    private $dm;
17
18
    /**
19
     * @var ClassMetadata
20
     */
21
    private $class;
22
23
    public function __construct(Builder $builder, DocumentManager $documentManager, ClassMetadata $class)
24
    {
25
        $this->dm = $documentManager;
26
        $this->class = $class;
27
28
        parent::__construct($builder);
29
    }
30
31
    protected function convertExpression($expression)
32
    {
33
        if (is_array($expression)) {
34
            return array_map([$this, 'convertExpression'], $expression);
35
        } elseif (is_string($expression) && substr($expression, 0, 1) === '$') {
36
            return '$' . $this->getDocumentPersister()->prepareFieldName(substr($expression, 1));
37
        } else {
38
            return Type::convertPHPToDatabaseValue(parent::convertExpression($expression));
39
        }
40
    }
41
42
    /**
43
     * @return \Doctrine\ODM\MongoDB\Persisters\DocumentPersister
44
     */
45
    private function getDocumentPersister()
46
    {
47
        return $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name);
48
    }
49
}
50

lib/Doctrine/ODM/MongoDB/Aggregation/Stage/ReplaceRoot.php 1 location

@@ 11-49 (lines=39) @@
8
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
9
use Doctrine\ODM\MongoDB\Types\Type;
10
11
class ReplaceRoot extends BaseStage\ReplaceRoot
12
{
13
    /**
14
     * @var DocumentManager
15
     */
16
    private $dm;
17
18
    /**
19
     * @var ClassMetadata
20
     */
21
    private $class;
22
23
    public function __construct(Builder $builder, DocumentManager $documentManager, ClassMetadata $class, $expression = null)
24
    {
25
        $this->dm = $documentManager;
26
        $this->class = $class;
27
28
        parent::__construct($builder, $expression);
29
    }
30
31
    protected function convertExpression($expression)
32
    {
33
        if (is_array($expression)) {
34
            return array_map([$this, 'convertExpression'], $expression);
35
        } elseif (is_string($expression) && substr($expression, 0, 1) === '$') {
36
            return '$' . $this->getDocumentPersister()->prepareFieldName(substr($expression, 1));
37
        } else {
38
            return Type::convertPHPToDatabaseValue(parent::convertExpression($expression));
39
        }
40
    }
41
42
    /**
43
     * @return \Doctrine\ODM\MongoDB\Persisters\DocumentPersister
44
     */
45
    private function getDocumentPersister()
46
    {
47
        return $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name);
48
    }
49
}
50