TranslateController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 5 1
A indexAction() 0 38 5
1
<?php
2
/**
3
 * @copyright Copyright (c) 2011 - 2014 Aleksandr Torosh (http://wezoom.net)
4
 * @author Aleksandr Torosh <[email protected]>
5
 */
6
7
namespace Cms\Controller;
8
9
use Application\Mvc\Controller;
10
use Application\Mvc\Helper\CmsCache;
11
use Cms\Model\Translate;
12
use Cms\Scanner;
13
14
class TranslateController extends Controller
15
{
16
17
    public function initialize()
18
    {
19
        $this->setAdminEnvironment();
20
        $this->helper->activeMenu()->setActive('admin-translate');
21
    }
22
23
    public function indexAction()
24
    {
25
        $model = new Translate();
26
        if ($this->request->isPost()) {
27
            $post = $this->request->getPost();
28
            if (!empty($post)) {
29
                foreach ($post as $key => $value) {
30
                    $key = str_replace('_', ' ', $key); // При отправке формы POST-запросом, все пробелы заменяются на "_". Меняем обратно.
31
                    $phrase = $model->findByPhraseAndLang($key);
32
                    if ($phrase) {
33
                        $phrase->setTranslation($value);
34
                        $phrase->update();
35
                    } else {
36
                        $phraseNew = new Translate();
37
                        $phraseNew->setPhrase($key);
38
                        $phraseNew->setLang(LANG);
39
                        $phraseNew->setTranslation($value);
40
                        $phraseNew->create();
41
                    }
42
                }
43
            }
44
45
            CmsCache::getInstance()->save('translates', Translate::buildCmsTranslatesCache());
46
            $this->flash->success($this->helper->at('Saved has been successful'));
47
48
            $lang = LANG;
49
            $key = HOST_HASH . md5("Translate::findByLang($lang)");
50
            $this->cache->delete($key);
51
52
            return $this->redirect($this->url->get() . 'cms/translate?lang=' . LANG);
53
        }
54
55
        $scanner = new Scanner();
56
        $phrases = $scanner->search();
57
58
        $this->view->phrases = $phrases;
0 ignored issues
show
Bug introduced by
Accessing phrases on the interface Phalcon\Mvc\ViewInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
59
        $this->view->model = $model;
0 ignored issues
show
Bug introduced by
Accessing model on the interface Phalcon\Mvc\ViewInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
60
    }
61
62
63
}