Code Duplication    Length = 39-39 lines in 3 locations

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

@@ 28-66 (lines=39) @@
25
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
26
use Doctrine\ODM\MongoDB\Types\Type;
27
28
class Bucket extends BaseStage\Bucket
29
{
30
    /**
31
     * @var DocumentManager
32
     */
33
    private $dm;
34
35
    /**
36
     * @var ClassMetadata
37
     */
38
    private $class;
39
40
    public function __construct(Builder $builder, DocumentManager $documentManager, ClassMetadata $class)
41
    {
42
        $this->dm = $documentManager;
43
        $this->class = $class;
44
45
        parent::__construct($builder);
46
    }
47
48
    protected function convertExpression($expression)
49
    {
50
        if (is_array($expression)) {
51
            return array_map([$this, 'convertExpression'], $expression);
52
        } elseif (is_string($expression) && substr($expression, 0, 1) === '$') {
53
            return '$' . $this->getDocumentPersister()->prepareFieldName(substr($expression, 1));
54
        } else {
55
            return Type::convertPHPToDatabaseValue(parent::convertExpression($expression));
56
        }
57
    }
58
59
    /**
60
     * @return \Doctrine\ODM\MongoDB\Persisters\DocumentPersister
61
     */
62
    private function getDocumentPersister()
63
    {
64
        return $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name);
65
    }
66
}
67

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

@@ 28-66 (lines=39) @@
25
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
26
use Doctrine\ODM\MongoDB\Types\Type;
27
28
class BucketAuto extends BaseStage\BucketAuto
29
{
30
    /**
31
     * @var DocumentManager
32
     */
33
    private $dm;
34
35
    /**
36
     * @var ClassMetadata
37
     */
38
    private $class;
39
40
    public function __construct(Builder $builder, DocumentManager $documentManager, ClassMetadata $class)
41
    {
42
        $this->dm = $documentManager;
43
        $this->class = $class;
44
45
        parent::__construct($builder);
46
    }
47
48
    protected function convertExpression($expression)
49
    {
50
        if (is_array($expression)) {
51
            return array_map([$this, 'convertExpression'], $expression);
52
        } elseif (is_string($expression) && substr($expression, 0, 1) === '$') {
53
            return '$' . $this->getDocumentPersister()->prepareFieldName(substr($expression, 1));
54
        } else {
55
            return Type::convertPHPToDatabaseValue(parent::convertExpression($expression));
56
        }
57
    }
58
59
    /**
60
     * @return \Doctrine\ODM\MongoDB\Persisters\DocumentPersister
61
     */
62
    private function getDocumentPersister()
63
    {
64
        return $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name);
65
    }
66
}
67

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

@@ 28-66 (lines=39) @@
25
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
26
use Doctrine\ODM\MongoDB\Types\Type;
27
28
class ReplaceRoot extends BaseStage\ReplaceRoot
29
{
30
    /**
31
     * @var DocumentManager
32
     */
33
    private $dm;
34
35
    /**
36
     * @var ClassMetadata
37
     */
38
    private $class;
39
40
    public function __construct(Builder $builder, DocumentManager $documentManager, ClassMetadata $class, $expression = null)
41
    {
42
        $this->dm = $documentManager;
43
        $this->class = $class;
44
45
        parent::__construct($builder, $expression);
46
    }
47
48
    protected function convertExpression($expression)
49
    {
50
        if (is_array($expression)) {
51
            return array_map([$this, 'convertExpression'], $expression);
52
        } elseif (is_string($expression) && substr($expression, 0, 1) === '$') {
53
            return '$' . $this->getDocumentPersister()->prepareFieldName(substr($expression, 1));
54
        } else {
55
            return Type::convertPHPToDatabaseValue(parent::convertExpression($expression));
56
        }
57
    }
58
59
    /**
60
     * @return \Doctrine\ODM\MongoDB\Persisters\DocumentPersister
61
     */
62
    private function getDocumentPersister()
63
    {
64
        return $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name);
65
    }
66
}
67