Code Duplication    Length = 42-50 lines in 2 locations

src/Model/Gedmo/AbstractPersonalTranslatable.php 1 location

@@ 27-76 (lines=50) @@
24
 *
25
 * @see https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/translatable.md : Personal translations
26
 */
27
abstract class AbstractPersonalTranslatable extends AbstractTranslatable
28
{
29
    /**
30
     * @var ArrayCollection|AbstractPersonalTranslation[]
31
     */
32
    protected $translations;
33
34
    public function __construct()
35
    {
36
        $this->translations = new ArrayCollection();
37
    }
38
39
    /**
40
     * @return ArrayCollection|AbstractPersonalTranslation[]
41
     */
42
    public function getTranslations()
43
    {
44
        return $this->translations;
45
    }
46
47
    /**
48
     * @param string $field
49
     * @param string $locale
50
     *
51
     * @return string|null
52
     */
53
    public function getTranslation($field, $locale)
54
    {
55
        foreach ($this->getTranslations() as $translation) {
56
            if (0 === strcmp($translation->getField(), $field) && 0 === strcmp($translation->getLocale(), $locale)) {
57
                return $translation->getContent();
58
            }
59
        }
60
61
        return null;
62
    }
63
64
    /**
65
     * @return $this
66
     */
67
    public function addTranslation(AbstractPersonalTranslation $translation)
68
    {
69
        if (!$this->translations->contains($translation)) {
70
            $translation->setObject($this);
71
            $this->translations->add($translation);
72
        }
73
74
        return $this;
75
    }
76
}
77

src/Traits/Gedmo/PersonalTranslatableTrait.php 1 location

@@ 23-64 (lines=42) @@
20
 *
21
 * @author Nicolas Bastien <[email protected]>
22
 */
23
trait PersonalTranslatableTrait
24
{
25
    use TranslatableTrait;
26
27
    /**
28
     * @return ArrayCollection|AbstractPersonalTranslation[]
29
     */
30
    public function getTranslations()
31
    {
32
        return $this->translations;
33
    }
34
35
    /**
36
     * @param $field
37
     * @param $locale
38
     *
39
     * @return string|null
40
     */
41
    public function getTranslation($field, $locale)
42
    {
43
        foreach ($this->getTranslations() as $translation) {
44
            if (0 === strcmp($translation->getField(), $field) && 0 === strcmp($translation->getLocale(), $locale)) {
45
                return $translation->getContent();
46
            }
47
        }
48
49
        return null;
50
    }
51
52
    /**
53
     * @return $this
54
     */
55
    public function addTranslation(AbstractPersonalTranslation $translation)
56
    {
57
        if (!$this->translations->contains($translation)) {
58
            $translation->setObject($this);
59
            $this->translations->add($translation);
60
        }
61
62
        return $this;
63
    }
64
}
65