TranslationModelBehavior::objectMethods()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4286
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace ItBlaster\TranslationBundle\Behavior;
4
5
/**
6
 * Используется только в модели Translation
7
 *
8
 * Class TranslationModelBehavior
9
 * @package ItBlaster\TranslationBundle\Behavior
10
 */
11
class TranslationModelBehavior extends TranslationBehavior
12
{
13
    protected $get_column_method;
14
    protected $set_column_method;
15
16
    /**
17
     * @throws InvalidArgumentException
18
     */
19
    public function modifyTable()
20
    {
21
        $this->get_column_method = 'get'.$this->getColumnForParameter('primary_string')->getPhpName();
22
        $this->set_column_method = 'set'.$this->getColumnForParameter('primary_string')->getPhpName();
23
    }
24
25
    /**
26
     * добавляем методы в модель
27
     *
28
     * @param $builder
29
     * @return string
30
     */
31
    public function objectMethods($builder)
32
    {
33
        $this->builder = $builder;
0 ignored issues
show
Bug introduced by
The property builder does not seem to exist. Did you mean additionalBuilders?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
34
        $script = '';
35
        $this->getFieldTranslation($script);    //методы переводов указанного поля
36
37
        return $script;
38
    }
39
40
    public function getFieldTranslation(&$script)
41
    {
42
        $locales = $this->getContainer()->getParameter("it_blaster_translation.locales");
43
        $field = $this->getColumnForParameter('primary_string');
44
        foreach ($locales as $locale) {
45
            $script .= '
46
/**
47
 * Return '.$field.' in locale '.$locale.'
48
 *
49
 * @return string
50
 */
51
public function '.$this->get_column_method.$locale.'()
52
{
53
    return $this->setLocale("'.$locale.'")->'.$this->get_column_method.'();
54
}
55
56
/**
57
 * Set '.$field.' in locale '.$locale.'
58
 */
59
public function '.$this->set_column_method.$locale.'($v)
60
{
61
    $this->setLocale("'.$locale.'")->'.$this->set_column_method.'($v);
62
63
    return $this;
64
}
65
    ';
66
        }
67
68
    }
69
}