Completed
Push — master ( 2bbbb9...ccf771 )
by Tobias
02:33
created

delete::version()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 13

Duplication

Lines 24
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 24
loc 24
rs 8.9713
cc 3
eloc 13
nc 4
nop 1
1
<?php
2
/**
3
*
4
* @package phpBB Extension - Wiki
5
 * @copyright (c) 2015 tas2580 (https://tas2580.net)
6
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
*
8
*/
9
namespace tas2580\wiki\wiki;
10
11
class delete extends \tas2580\wiki\wiki\functions
12
{
13
14
	/** @var \phpbb\auth\auth */
15
	protected $auth;
16
17
	/** @var \phpbb\db\driver\driver_interface */
18
	protected $db;
19
20
	/** @var \phpbb\controller\helper */
21
	protected $helper;
22
23
	/** @var \parse_message */
24
	protected $message_parser;
25
26
	/** @var \phpbb\user */
27
	protected $user;
28
29
	/** @var string article_table */
30
	protected $article_table;
31
32
33
	/**
34
	* Constructor
35
	*
36
	* @param \phpbb\auth\auth						$auth					Auth object
37
	* @param \phpbb\config\config					$config
0 ignored issues
show
Bug introduced by
There is no parameter named $config. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

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

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

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

Loading history...
38
	* @param \phpbb\db\driver\driver_interface		$db						Database object
39
	* @param \phpbb\controller\helper				$helper					Controller helper object
40
	* @param \phpbb\notification\manager			$notification_manager
0 ignored issues
show
Bug introduced by
There is no parameter named $notification_manager. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

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

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

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

Loading history...
41
	* @param \phpbb\request\request					$request				Request object
0 ignored issues
show
Bug introduced by
There is no parameter named $request. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

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

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

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

Loading history...
42
	* @param \phpbb\template\template				$template				Template object
0 ignored issues
show
Bug introduced by
There is no parameter named $template. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

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

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

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

Loading history...
43
	* @param \phpbb\user							$user
44
	* @param string									$article_table
45
	* @param string									$phpbb_root_path
0 ignored issues
show
Bug introduced by
There is no parameter named $phpbb_root_path. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

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

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

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

Loading history...
46
	* @param string									$php_ext
0 ignored issues
show
Bug introduced by
There is no parameter named $php_ext. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

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

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

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

Loading history...
47
48
	*/
49
	public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\controller\helper $helper, \phpbb\user $user, $article_table)
50
	{
51
		$this->auth = $auth;
52
		$this->db = $db;
53
		$this->helper = $helper;
54
		$this->user = $user;
55
		$this->article_table = $article_table;
56
	}
57
58
	/**
59
	 * Delete a version of an article
60
	 *
61
	 * @param	int		$id	Id of the version to delete
62
	 * @return	object
63
	 */
64 View Code Duplication
	public function version($id)
0 ignored issues
show
Duplication introduced by
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...
65
	{
66
		if (!$this->auth->acl_get('u_wiki_delete'))
67
		{
68
			trigger_error('NOT_AUTHORISED');
69
		}
70
71
		if (confirm_box(true))
72
		{
73
			$sql = 'DELETE FROM ' . $this->article_table . '
74
				WHERE article_id = ' . (int) $id;
75
			$this->db->sql_query($sql);
76
			//return $helper->message('DELETE_VERSION_SUCCESS', array());
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
77
			trigger_error($this->user->lang['DELETE_VERSION_SUCCESS'] . '<br /><br /><a href="' . $this->helper->route('tas2580_wiki_index', array())  . '">' . $this->user->lang['BACK_TO_WIKI'] . '</a>');
78
		}
79
		else
80
		{
81
			$s_hidden_fields = build_hidden_fields(array(
82
				'id'    => $id,
83
			));
84
			confirm_box(false, $this->user->lang['CONFIRM_DELETE_VERSION'], $s_hidden_fields);
85
		}
86
		redirect($this->helper->route('tas2580_wiki_index', array('id' => $id)));
87
	}
88
89
	/**
90
	 * Delete an complete article
91
	 *
92
	 * @param	string	$article	URL of the article to delete
93
	 * @return	object
94
	 */
95 View Code Duplication
	public function article($article)
0 ignored issues
show
Duplication introduced by
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...
96
	{
97
		if (!$this->auth->acl_get('u_wiki_delete_article'))
98
		{
99
			trigger_error('NOT_AUTHORISED');
100
		}
101
102
		if (confirm_box(true))
103
		{
104
			$sql = 'DELETE FROM ' . $this->article_table . "
105
				WHERE article_url = '" . $this->db->sql_escape($article) . "'";
106
			$this->db->sql_query($sql);
107
			trigger_error($this->user->lang['DELETE_ARTICLE_SUCCESS'] . '<br /><br /><a href="' . $this->helper->route('tas2580_wiki_index', array())  . '">' . $this->user->lang['BACK_TO_WIKI'] . '</a>');
108
		}
109
		else
110
		{
111
			$s_hidden_fields = build_hidden_fields(array(
112
				'article'    => $article,
113
			));
114
			confirm_box(false, $this->user->lang['CONFIRM_DELETE_ARTICLE'], $s_hidden_fields);
115
		}
116
		redirect($this->helper->route('tas2580_wiki_index', array('article' => $article)));
117
	}
118
}
119