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.

ArchivedeleteditemsPlugin   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 13
lcom 1
cbo 2
dl 0
loc 110
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigurationParameter() 0 3 1
A __construct() 0 6 1
A getPluginInfo() 0 7 2
C archive_deleted_item() 0 48 7
A getWellFormattedArchivePath() 0 10 2
1
<?php
2
/**
3
 * Copyright (c) STMicroelectronics 2012. All rights reserved
4
 * Copyright (c) Enalean, 2015. All Rights Reserved.
5
 *
6
 * Tuleap is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * Tuleap is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with Tuleap. If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
require_once('common/plugin/Plugin.class.php');
21
22
/**
23
 * Archive
24
 */
25
class ArchivedeleteditemsPlugin extends Plugin {
26
27
    private $archiveScript;
28
29
    /**
30
     * Constructor of the class
31
     *
32
     * @param Integer $id Id of the plugin
33
     *
34
     * @return Void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
35
     */
36
    public function __construct($id) {
37
        parent::__construct($id);
38
        $this->setScope(Plugin::SCOPE_SYSTEM);
39
        $this->archiveScript = $GLOBALS['codendi_bin_prefix'] . "/archive-deleted-items.pl";
40
        $this->_addHook('archive_deleted_item', 'archive_deleted_item', false);
41
    }
42
43
    /**
44
     * Obtain ArchiveDeletedItemsPluginInfo instance
45
     *
46
     * @return ArchiveDeletedItemsPluginInfo
47
     */
48
    public function getPluginInfo() {
49
        if (!is_a($this->pluginInfo, 'ArchiveDeletedItemsPluginInfo')) {
50
            require_once('ArchiveDeletedItemsPluginInfo.class.php');
51
            $this->pluginInfo = new ArchiveDeletedItemsPluginInfo($this);
52
        }
53
        return $this->pluginInfo;
54
    }
55
56
    /**
57
     * Returns the configuration defined for given variable name
58
     *
59
     * @param String $key name of the param
60
     *
61
     * @return String
62
     */
63
    public function getConfigurationParameter($key) {
64
        return $this->getPluginInfo()->getPropertyValueForName($key);
65
    }
66
67
    /**
68
     * Copy files to the archiving directory
69
     *
70
     * @param Array $params Hook parameters
71
     *
72
     * @return Boolean
73
     */
74
    public function archive_deleted_item($params) {
75
        $params['status'] = false;
76
77
        if (!empty($params['source_path'])) {
78
            $source_path = $params['source_path'];
79
        } else {
80
            $params['error'] = 'Missing argument source path';
81
            return false;
82
        }
83
84
        $archive_path = $this->getWellFormattedArchivePath();
85
86
        if (!empty($archive_path)) {
87
            if(!is_dir($archive_path)) {
88
                $params['error'] = 'Non-existing archive path';
89
                return false;
90
            }
91
        } else {
92
            $params['error'] = 'Missing argument archive path';
93
            return false;
94
        }
95
96
        if (!empty($params['archive_prefix'])) {
97
            $archive_prefix = $params['archive_prefix'];
98
        } else {
99
            $params['error'] = 'Missing argument archive prefix';
100
            return false;
101
        }
102
103
        $ret_val         = null;
104
        $exec_res        = null;
105
        if (file_exists($source_path)) {
106
            $destination_path = $archive_path.$archive_prefix.'_'.basename($source_path);
107
            $cmd              = $this->archiveScript." ".$source_path." " .$destination_path;
108
109
            exec($cmd, $exec_res, $ret_val);
110
            if ($ret_val == 0) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $ret_val of type integer|null to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
111
                $params['status'] = true;
112
                return true;
113
            } else {
114
                $params['error'] = 'Archiving of "'.$source_path.'" in "'.$destination_path.'" failed';
115
                return false;
116
            }
117
        } else {
118
            $params['error'] = 'Skipping file "'.$source_path.'": not found in file system.';
119
            return false;
120
        }
121
    }
122
123
    private function getWellFormattedArchivePath() {
124
        $archive_path = $this->getConfigurationParameter('archive_path');
125
126
        if ($archive_path) {
127
            $archive_path  = rtrim($archive_path, '/');
128
            $archive_path .= '/';
129
        }
130
131
        return $archive_path;
132
    }
133
134
}