GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

BoomerangPlugin::cardwall_event_displayed()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 11
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
/**
3
  * Copyright (c) Enalean, 2013. All rights reserved
4
  *
5
  * This file is a part of Tuleap.
6
  *
7
  * Tuleap is free software; you can redistribute it and/or modify
8
  * it under the terms of the GNU General Public License as published by
9
  * the Free Software Foundation; either version 2 of the License, or
10
  * (at your option) any later version.
11
  *
12
  * Tuleap is distributed in the hope that it will be useful,
13
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
  * GNU General Public License for more details.
16
  *
17
  * You should have received a copy of the GNU General Public License
18
  * along with Tuleap. If not, see <http://www.gnu.org/licenses/
19
  */
20
require_once('common/plugin/Plugin.class.php');
21
require_once('autoload.php');
22
require_once 'constants.php';
23
24
class BoomerangPlugin extends Plugin {
25
26
    const RENDERER_TYPE = 'plugin_boomerang';
27
28
    /**
29
     * Plugin constructor
30
     */
31
    public function __construct($id) {
32
        parent::__construct($id);
33
        $this->setScope(Plugin::SCOPE_SYSTEM);
34
    }
35
36
    public function getHooksAndCallbacks() {
37
        if (defined('CARDWALL_EVENT_DISPLAYED')) {
38
            $this->_addHook(CARDWALL_EVENT_DISPLAYED);
39
        }
40
        $this->_addHook('site_admin_option_hook', 'siteAdminHooks', false);
41
        $this->_addHook('cssfile');
42
        return parent::getHooksAndCallbacks();
43
    }
44
45
    public function cssfile($params) {
46
        // Only show the stylesheet if we're actually in the Boomerang plugin page.
47
        // This stops styles inadvertently clashing with the main site.
48
        if (strpos($_SERVER['REQUEST_URI'], $this->getPluginPath()) === 0) {
49
            echo '<link rel="stylesheet" type="text/css" href="css/barChart.css" />';
50
        }
51
    }
52
53
    public function process(Codendi_Request $request){
54
        switch ($request->get('action')) {
55
            case 'provide_datas':
56
                header('Content-type : text/csv');
57
                echo file_get_contents($this->getCacheFolder() . 'data.csv');
58
                break;
59
            case 'beacon':
60
                $this->processBoomerangDatas($request);
61
                break;
62
            default:
63
                require_once 'common/templating/TemplateRendererFactory.class.php';
64
                $header_params = array(
65
                    'title' => 'Boomerang'
66
                );
67
                site_header($header_params);
68
                $renderer = TemplateRendererFactory::build()->getRenderer(BOOMERANG_BASE_DIR.'/../templates');
69
                $presenter = new PerfDataPresenter();
70
                $renderer->renderToPage('perf-data', $presenter);
71
                site_footer(null);
72
                break;
73
        }
74
    }
75
76
    public function cardwall_event_displayed($params) {
77
        $token = $this->getCSRFToken();
78
        $params['html'] .= '<script src=/plugins/boomerang/js/boomerang-minified-bw.js></script>' . PHP_EOL;
79
        $params['html'] .= '
80
            <script type="text/javascript">
81
                BOOMR.init({
82
                    beacon_url: "/plugins/boomerang/?action=beacon&'.$token->getTokenName().'='.$token->getToken().'"
83
                });
84
            </script>
85
        ' . PHP_EOL;
86
    }
87
88
    /**
89
     * Obtain ArchiveDeletedItemsPluginInfo instance
90
     *
91
     * @return ArchiveDeletedItemsPluginInfo
92
     */
93
    public function getPluginInfo() {
94
        if (!is_a($this->pluginInfo, 'BoomerangPluginInfo')) {
95
            $this->pluginInfo = new BoomerangPluginInfo($this);
96
        }
97
        return $this->pluginInfo;
98
    }
99
100
    private function getCSRFToken() {
101
        require_once 'common/include/CSRFSynchronizerToken.class.php';
102
        return new CSRFSynchronizerToken('/plugins/boomerang/?action=beacon');
103
    }
104
105
    private function getCacheFolder() {
106
        return $GLOBALS['sys_data_dir'] . '/boomerang/';
107
    }
108
109
    private function makeArrayFromStringHashTable($string_hash_map) {
110
        $array_temp = split(',', $string_hash_map);
111
        $hash_table = array();
112
        foreach ($array_temp as $line) {
113
            $line_content = split('\|', $line);
114
            $hash_table[$line_content[0]] = $line_content[1];
115
        }
116
        return $hash_table;
117
    }
118
119
    private function processBoomerangDatas(Codendi_Request $request) {
120
        $csrf = $this->getCSRFToken();
121
        $csrf->check();
122
123
        $cache_folder =  $this->getCacheFolder();
124
        if (!file_exists($cache_folder)) {
125
            mkdir($cache_folder, 0755, TRUE);
126
        }
127
128
        $page_load_time             = $request->getValidated('t_done','uint',0);
129
130
        $dom_content_load_time      = 0;
131
        $boomerang_other_measures   = $this->makeArrayFromStringHashTable($request->getValidated('t_other','string',''));
132
        if(array_key_exists('boomr_fb', $boomerang_other_measures)) {
133
            $dom_content_load_time = (int)$boomerang_other_measures['boomr_fb'];
134
            $dom_content_load_time = ($dom_content_load_time > 0) ? $dom_content_load_time : 0 ;
135
        }
136
137
        parse_str(
138
            parse_url(
139
                $request->getValidated('u','string',''),
140
                PHP_URL_QUERY
141
            ),
142
            $url_parameters
143
        );
144
        $group_id = array_key_exists('group_id',$url_parameters) ? $url_parameters['group_id'] : null;
145
        $project_manager = ProjectManager::instance();
146
        if(!$project_manager->getProject($group_id)) {
147
            $group_id = 0;
148
        }
149
150
        $datas = array(
151
            "page_loading"  => $page_load_time,
152
            "dom_loading"   => $dom_content_load_time
153
        );
154
        if($datas["page_loading"] == 0 || $datas["dom_loading"] == 0 || $group_id == 0) {
155
            exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The method processBoomerangDatas() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
156
        }
157
        $boomerangDatasProcessor = new BoomerangDatasProcessor($cache_folder, $datas, $group_id);
158
        $boomerangDatasProcessor->handle();
159
    }
160
161
    /**
162
	 * for hook administration :display an URL to access Boomerang statistics..
163
	 * @param array $params:contains the data which comes from the envent listened.
0 ignored issues
show
Documentation introduced by
There is no parameter named $params:contains. Did you maybe mean $params?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
164
	 */
165
    function siteAdminHooks($params) {
166
       global $Language;
167
       $link_title= $GLOBALS['Language']->getText('plugin_boomerang','link_boomerang_admin_title');
168
       echo '<li><a href="'.$this->getPluginPath().'/">'.$link_title.'</a></li>';
169
    }
170
}
171
172
?>