DeactivateOperation   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 3
dl 42
loc 42
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 4 4 1
A get_controls() 10 10 1
A process() 14 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the Icybee package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Icybee\Modules\Users\Operation;
13
14
use ICanBoogie\ErrorCollection;
15
use ICanBoogie\Operation;
16
17
use Icybee\Modules\Users\Module;
18
use Icybee\Modules\Users\User;
19
20
/**
21
 * Disables a user account.
22
 *
23
 * @property User $record
24
 */
25 View Code Duplication
class DeactivateOperation extends Operation
26
{
27
	/**
28
	 * @inheritdoc
29
	 */
30
	protected function get_controls()
31
	{
32
		return [
33
34
			self::CONTROL_PERMISSION => Module::PERMISSION_ADMINISTER,
35
			self::CONTROL_RECORD => true,
36
			self::CONTROL_OWNERSHIP => true
37
38
		] + parent::get_controls();
39
	}
40
41
	/**
42
	 * @inheritdoc
43
	 */
44
	protected function validate(ErrorCollection $errors)
45
	{
46
		return true;
47
	}
48
49
	/**
50
	 * @inheritdoc
51
	 */
52
	protected function process()
53
	{
54
		$record = $this->record;
55
		$record->is_activated = false;
56
		$record->save();
57
58
		$this->response->message = $this->format('!name account is deactivated.', [
59
60
			'!name' => $record->name
61
62
		]);
63
64
		return true;
65
	}
66
}
67