Failed Conditions
Push — master ( 674f38...37557b )
by Adrien
03:06
created

Bootstrap   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 136
Duplicated Lines 0 %

Test Coverage

Coverage 97.3%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 10
eloc 63
c 6
b 0
f 0
dl 0
loc 136
ccs 72
cts 74
cp 0.973
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A _initAutoload() 0 4 1
A _initPagination() 0 4 1
A _initDoctype() 0 8 1
A _initSession() 0 4 1
A _initNavigation() 0 43 1
A _initMyDb() 0 6 1
1
<?php
2
3
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
4
{
5
    public static $translator = null;
6
7 16
    protected function _initAutoload(): void
8
    {
9
        // Add our own action helpers
10 16
        Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/mQueue/Controller/ActionHelper', 'mQueue\\Controller\\ActionHelper\\');
11 16
    }
12
13 16
    protected function _initDoctype(): void
14
    {
15 16
        $this->bootstrap('view');
16 16
        $view = $this->getResource('view');
17 16
        $view->doctype(Zend_View_Helper_Doctype::XHTML1_STRICT);
18
19
        // Enable our own View Helpers
20 16
        $view->addHelperPath(APPLICATION_PATH . '/mQueue/View/Helper', 'mQueue\\View\\Helper');
21 16
    }
22
23 16
    protected function _initNavigation(): void
24
    {
25 16
        $this->bootstrap('view');
26 16
        $view = $this->getResource('view');
27
28 16
        $navigation = new Zend_Navigation([
29
            [
30 16
                'label' => $view->translate('Movies'),
31 16
                'controller' => 'movie',
32 16
                'route' => 'default',
33
                'pages' => [
34
                    [
35 16
                        'label' => $view->translate('Add movie'),
36 16
                        'controller' => 'movie',
37 16
                        'action' => 'add',
38 16
                        'route' => 'default',
39
                    ],
40
                    [
41 16
                        'label' => $view->translate('Import votes from IMDb'),
42 16
                        'controller' => 'movie',
43 16
                        'action' => 'import',
44 16
                        'route' => 'default',
45
                    ],
46
                ],
47
            ],
48
            [
49 16
                'label' => $view->translate('Activity'),
50 16
                'controller' => 'activity',
51 16
                'route' => 'default',
52
            ],
53
            [
54 16
                'label' => $view->translate('Users'),
55 16
                'controller' => 'user',
56 16
                'route' => 'default',
57
            ],
58
            [
59 16
                'label' => $view->translate('FAQ'),
60 16
                'controller' => 'faq',
61 16
                'route' => 'default',
62
            ],
63
        ]);
64
65 16
        $view->navigation($navigation);
66 16
    }
67
68 16
    protected function _initSession(): void
69
    {
70 16
        Zend_Session::setOptions(['name' => 'mqueue']);
71 16
        Zend_Session::rememberMe(1 * 60 * 60 * 24 * 31 * 12); // Cookie for 1 year
72 16
    }
73
74 16
    protected function _initLanguage(): void
75
    {
76 16
        $session = new Zend_Session_Namespace();
77
78
        // handle language switch
79 16
        if (isset($_GET['lang'])) {
80
            $session->locale = $_GET['lang'];
81
        }
82
83 16
        if (isset($session->locale)) {
84
            $locale = new Zend_Locale($session->locale);
85
        } else {
86 16
            $locale = new Zend_Locale(); // autodetect browser
87
        }
88 16
        Zend_Registry::set('Zend_Locale', $locale);
89
90 16
        $adapter = new Zend_Translate('gettext', APPLICATION_PATH . '/localization', $locale, ['scan' => Zend_Translate::LOCALE_FILENAME, 'disableNotices' => true]);
91 16
        Zend_Registry::set('Zend_Translate', $adapter);
92 16
        Zend_Form::setDefaultTranslator($adapter);
93 16
        self::$translator = $adapter;
94 16
    }
95
96 16
    protected function _initPagination(): void
97
    {
98 16
        Zend_Paginator::setDefaultScrollingStyle('Elastic');
99 16
        Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
100 16
    }
101
102 16
    protected function _initRoutes(): void
103
    {
104 16
        $front = Zend_Controller_Front::getInstance();
105 16
        $router = $front->getRouter();
106
107
        // Required for unit tests
108 16
        $router->addDefaultRoutes();
0 ignored issues
show
Bug introduced by
The method addDefaultRoutes() does not exist on Zend_Controller_Router_Interface. It seems like you code against a sub-type of Zend_Controller_Router_Interface such as Zend_Controller_Router_Rewrite. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

108
        $router->/** @scrutinizer ignore-call */ 
109
                 addDefaultRoutes();
Loading history...
109
110
        // A route for single id (typically view a single movie/user)
111 16
        $router->addRoute('singleid', new Zend_Controller_Router_Route(':controller/:action/:id', ['action' => 'view']));
0 ignored issues
show
Bug introduced by
The method addRoute() does not exist on Zend_Controller_Router_Interface. It seems like you code against a sub-type of Zend_Controller_Router_Interface such as Zend_Controller_Router_Rewrite. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

111
        $router->/** @scrutinizer ignore-call */ 
112
                 addRoute('singleid', new Zend_Controller_Router_Route(':controller/:action/:id', ['action' => 'view']));
Loading history...
112
113
        // A route for activities
114 16
        $router->addRoute('activity', new Zend_Controller_Router_Route('activity/*', ['controller' => 'activity', 'action' => 'index']));
115 16
        $router->addRoute('activityMovie', new Zend_Controller_Router_Route('activity/movie/:movie/*', ['controller' => 'activity', 'action' => 'index']));
116 16
        $router->addRoute('activityUser', new Zend_Controller_Router_Route('activity/user/:user/*', ['controller' => 'activity', 'action' => 'index']));
117
118
        // For backward compatibility with RSS readers we keep the old route
119 16
        $router->addRoute('activityOld', new Zend_Controller_Router_Route('activity/index/*', ['controller' => 'activity', 'action' => 'index']));
120 16
        $router->addRoute('activityMovieOld', new Zend_Controller_Router_Route('activity/index/movie/:movie/*', ['controller' => 'activity', 'action' => 'index']));
121 16
        $router->addRoute('activityUserOld', new Zend_Controller_Router_Route('activity/index/user/:user/*', ['controller' => 'activity', 'action' => 'index']));
122
123
        // Routes to define and view statuses
124 16
        $router->addRoute('status', new Zend_Controller_Router_Route_Regex('status/(\d+)/(\d)', ['controller' => 'status', 'action' => 'index'], [1 => 'movie', 2 => 'rating'], 'status/%s/%s'));
125 16
        $router->addRoute('statusView', new Zend_Controller_Router_Route_Regex('status/(\d+)', ['controller' => 'status', 'action' => 'index'], [1 => 'movie'], 'status/%s'));
126 16
    }
127
128
    /**
129
     * Add the Zend_Db_Adapter to the registry if we need to call it outside of the modules.
130
     *
131
     * @return Zend_Db_Adapter_Abstract
132
     */
133 16
    protected function _initMyDb()
134
    {
135 16
        $db = $this->getPluginResource('db')->getDbAdapter();
0 ignored issues
show
Bug introduced by
The method getDbAdapter() does not exist on Zend_Application_Resource_Resource. It seems like you code against a sub-type of Zend_Application_Resource_Resource such as Zend_Application_Resource_Db. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

135
        $db = $this->getPluginResource('db')->/** @scrutinizer ignore-call */ getDbAdapter();
Loading history...
136 16
        Zend_Registry::set('db', $db);
137
138 16
        return $db;
139
    }
140
}
141
142
/**
143
 * Global shortcut method that returns localized strings
144
 *
145
 * @param string $msgId the original string to translate
146
 *
147
 * @return string the translated string
148
 */
149
function _tr($msgId)
150
{
151 12
    return Bootstrap::$translator->translate($msgId);
152
}
153