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.
Completed
Push — develop ( 85b535...144fe2 )
by
unknown
10s
created

component/admin/controllers/package.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @package     Com_Localise
4
 * @subpackage  controller
5
 *
6
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
7
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
8
 */
9
10
defined('_JEXEC') or die;
11
12
/**
13
 * Package Controller class for the Localise component
14
 *
15
 * @package     Extensions.Components
16
 * @subpackage  Localise
17
 * @since       1.0
18
 */
19
class LocaliseControllerPackage extends JControllerForm
20
{
21
	/**
22
	 * Method to check if you can add a new record.
23
	 *
24
	 * Extended classes can override this if necessary.
25
	 *
26
	 * @param   array  $data  An array of input data.
27
	 *
28
	 * @return  boolean
29
	 */
30
	protected function allowAdd($data = array())
31
	{
32
		// @todo: $data parameter is unused
33
		return JFactory::getUser()->authorise('localise.create', $this->option);
34
	}
35
36
	/**
37
	 * Method to check if you can add a new record.
38
	 *
39
	 * Extended classes can override this if necessary.
40
	 *
41
	 * @param   array   $data  An array of input data.
42
	 * @param   string  $key   The name of the key for the primary key.
43
	 *
44
	 * @return  boolean
45
	 */
46
	protected function allowEdit($data = array(), $key = 'id')
47
	{
48
		return JFactory::getUser()->authorise('localise.edit', $this->option . '.' . $data[$key]);
49
	}
50
51
	/**
52
	 * Todo: description missing
53
	 *
54
	 * @return void
55
	 */
56 View Code Duplication
	public function download()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
	{
58
		// Initialise variables.
59
		$app = JFactory::getApplication();
60
		$input = $app->input;
61
		$model   = $this->getModel();
62
63
		$data = $input->get('jform', array(), 'array');
64
		$model->download($data);
65
66
		// Redirect to the export view
67
		// todo: this feature is not finished.
68
69
		/*
70
		$app  = JFactory::getApplication();
71
		$name = $app->getUserState('com_localise.package.name');
72
		$path = JPATH_COMPONENT_ADMINISTRATOR . '/packages/' . $name . '.xml';
73
		$id   = LocaliseHelper::getFileId($path);
74
		*/
75
76
		// Check if the package exists
77
78
		/*
79
		if (empty($id))
80
		{
81
			$this->setRedirect(
82
				JRoute::_('index.php?option=' . $this->_option . '&view=packages', false),
83
				JText::sprintf('COM_LOCALISE_ERROR_DOWNLOADPACKAGE_UNEXISTING', $name),
84
				'error'
85
			);
86
		}
87
		else
88
		{
89
			$model   = $this->getModel();
90
			$package = $model->getItem();
91
92
			if (!$package->standalone)
93
			{
94
				$msg  = JText::sprintf('COM_LOCALISE_NOTICE_DOWNLOADPACKAGE_NOTSTANDALONE', $name);
95
				$type = 'notice';
96
			}
97
			else
98
			{
99
				$msg  = '';
100
				$type = 'message';
101
			}
102
103
			setcookie(JApplicationHelper::getHash($this->context . '.author'), $package->author, time() + 60 * 60 * 24 * 30);
104
			setcookie(JApplicationHelper::getHash($this->context . '.copyright'), $package->copyright, time() + 60 * 60 * 24 * 30);
105
			setcookie(JApplicationHelper::getHash($this->context . '.email'), $package->email, time() + 60 * 60 * 24 * 30);
106
			setcookie(JApplicationHelper::getHash($this->context . '.url'), $package->url, time() + 60 * 60 * 24 * 30);
107
			setcookie(JApplicationHelper::getHash($this->context . '.version'), $package->version, time() + 60 * 60 * 24 * 30);
108
			setcookie(JApplicationHelper::getHash($this->context . '.license'), $package->license, time() + 60 * 60 * 24 * 30);
109
110
			$this->setRedirect(
111
				JRoute::_('index.php?option=com_localise&tmpl=component&view=downloadpackage&name=' . $name . '&standalone=' . $package->standalone, false),
112
				$msg,
113
				$type
114
			);
115
		}
116
		*/
117
	}
118
119
	/**
120
	 * Method for uploading a file.
121
	 *
122
	 * @return  void
123
	 *
124
	 * @since   3.2
125
	 */
126
	public function uploadFile()
127
	{
128
		$app      = JFactory::getApplication();
129
		$model    = $this->getModel();
130
		$upload   = $app->input->files->get('files');
131
132
		if ($return = $model->uploadFile($upload))
0 ignored issues
show
$return is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
133
		{
134
			$app->enqueueMessage(JText::sprintf('COM_LOCALISE_FILE_UPLOAD_SUCCESS', $upload['name']));
135
		}
136
		else
137
		{
138
			$app->enqueueMessage(JText::_('COM_LOCALISE_ERROR_FILE_UPLOAD'), 'error');
139
		}
140
141
		$url = 'index.php?option=com_localise&view=packages';
142
		$this->setRedirect(JRoute::_($url, false));
143
	}
144
145
	/**
146
	 * Method for uploading a css or a php file in the language xx-XX folder.
147
	 *
148
	 * @return  void
149
	 *
150
	 * @since   3.2
151
	 */
152
	public function uploadOtherFile()
153
	{
154
		$app		= JFactory::getApplication();
155
		$id			= $app->getUserState('com_localise.edit.package.id');
156
		$model		= $this->getModel();
157
		$upload		= $app->input->files->get('files');
158
		$location	= $app->input->get('location');
159
160
		if ($location == "admin")
161
		{
162
			$location = LOCALISEPATH_ADMINISTRATOR;
163
		}
164
		elseif ($location == "site")
165
		{
166
			$location = LOCALISEPATH_SITE;
167
		}
168
169
		if ($return = $model->uploadOtherFile($upload, $location))
0 ignored issues
show
$return is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
170
		{
171
			$app->enqueueMessage(JText::sprintf('COM_LOCALISE_OTHER_FILE_UPLOAD_SUCCESS', $upload['name']));
172
		}
173
		else
174
		{
175
			$app->enqueueMessage(JText::_('COM_LOCALISE_ERROR_OTHER_FILE_UPLOAD'), 'error');
176
		}
177
178
		$url = 'index.php?option=com_localise&task=package.edit&cid[]=' . $id;
179
180
		$this->setRedirect(JRoute::_($url, false));
181
	}
182
}
183