DefaultRouter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 25 1
A addML() 0 15 3
1
<?php
2
3
/**
4
 * Default
5
 * @copyright Copyright (c) 2011 - 2014 Aleksandr Torosh (http://wezoom.com.ua)
6
 * @author Aleksandr Torosh <[email protected]>
7
 */
8
9
namespace Application\Mvc\Router;
10
11
use Application\Mvc\Helper\CmsCache;
12
use Phalcon\Mvc\Router;
13
use Cms\Model\Language;
14
15
class DefaultRouter extends Router
16
{
17
18
    const ML_PREFIX = 'ml__';
19
20
    public function __construct()
21
    {
22
        parent::__construct();
23
24
        $this->setDefaultController('index');
25
        $this->setDefaultAction('index');
26
27
        $this->add('/:module/:controller/:action/:params', [
0 ignored issues
show
Bug introduced by
The method setName cannot be called on $this->add('/:module/:co...' => 3, 'params' => 4)) (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
28
            'module' => 1,
29
            'controller' => 2,
30
            'action' => 3,
31
            'params' => 4
32
        ])->setName('default');
33
        $this->add('/:module/:controller', [
0 ignored issues
show
Bug introduced by
The method setName cannot be called on $this->add('/:module/:co..., 'action' => 'index')) (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
34
            'module' => 1,
35
            'controller' => 2,
36
            'action' => 'index',
37
        ])->setName('default_action');
38
        $this->add('/:module', [
0 ignored issues
show
Bug introduced by
The method setName cannot be called on $this->add('/:module', a..., 'action' => 'index')) (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
39
            'module' => 1,
40
            'controller' => 'index',
41
            'action' => 'index',
42
        ])->setName('default_controller');
43
44
    }
45
46
    public function addML($pattern, $paths = null, $name)
47
    {
48
        $languages = CmsCache::getInstance()->get('languages');
49
50
        foreach ($languages as $lang) {
51
            $iso = $lang['iso'];
52
            if ($lang['primary']) {
53
                $this->add($pattern, $paths)->setName(self::ML_PREFIX . $name . '_' . $iso);
0 ignored issues
show
Bug introduced by
The method setName cannot be called on $this->add($pattern, $paths) (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
54
            } else {
55
                $new_pattern = '/' . $lang['url'] . $pattern;
56
                $paths['lang'] = $iso; // будущее значение константы LANG
57
                $this->add($new_pattern, $paths)->setName(self::ML_PREFIX . $name . '_' . $iso);
0 ignored issues
show
Bug introduced by
The method setName cannot be called on $this->add($new_pattern, $paths) (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
58
            }
59
        }
60
    }
61
62
}
63