Code Duplication    Length = 26-28 lines in 2 locations

Entity/Repository/BlockRepository.php 1 location

@@ 31-56 (lines=26) @@
28
            ->getOneOrNullResult();
29
    }
30
31
    public function findTranslation(Block $block, $locale)
32
    {
33
        $source = null;
34
35
        // We are checking if the node is the translation provider or translated
36
        // from an other node
37
        if ($block->getTranslationSource() !== null) {
38
            $source = $block->getTranslationSource();
39
            if ($source->getLocale() == $locale) {
40
                return $source;
41
            }
42
        } else {
43
            $source = $block;
44
        }
45
46
        return $this->createQueryBuilder('n')
47
            ->addSelect('n')
48
            ->andWhere('n.translationSource = :source')
49
            ->andWhere('n.locale = :locale')
50
            ->setParameters([
51
                'source' => $source,
52
                'locale' => $locale,
53
            ])
54
            ->getQuery()
55
            ->getOneOrNullResult();
56
    }
57
}
58

Entity/Repository/NodeRepository.php 1 location

@@ 84-111 (lines=28) @@
81
     * @param $locale
82
     * @return \Alpixel\Bundle\CMSBundle\Entity\Node|null
83
     */
84
    public function findTranslation(Node $node, $locale)
85
    {
86
        $nodeSource = null;
87
88
        // We are checking if the node is the translation provider or translated
89
        // from an other node
90
        if ($node->getTranslationSource() !== null) {
91
            $nodeSource = $node->getTranslationSource();
92
            if ($nodeSource->getLocale() == $locale) {
93
                return $nodeSource;
94
            }
95
        } else {
96
            $nodeSource = $node;
97
        }
98
99
        return $this->createQueryBuilder('n')
100
            ->addSelect('n')
101
            ->andWhere('n.translationSource = :source')
102
            ->andWhere('n.locale = :locale')
103
            ->setParameters(
104
                [
105
                    'source' => $nodeSource,
106
                    'locale' => $locale,
107
                ]
108
            )
109
            ->getQuery()
110
            ->getOneOrNullResult();
111
    }
112
113
    /**
114
     * @param \Alpixel\Bundle\CMSBundle\Entity\Node $node