ActivateOperation   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
use Icybee\Modules\Users\Module;
17
use Icybee\Modules\Users\User;
18
19
/**
20
 * Enables a user account.
21
 *
22
 * @property User $record
23
 */
24 View Code Duplication
class ActivateOperation extends Operation
25
{
26
	/**
27
	 * @inheritdoc
28
	 */
29
	protected function get_controls()
30
	{
31
		return [
32
33
			self::CONTROL_PERMISSION => Module::PERMISSION_ADMINISTER,
34
			self::CONTROL_RECORD => true,
35
			self::CONTROL_OWNERSHIP => true
36
37
		] + parent::get_controls();
38
	}
39
40
	/**
41
	 * @inheritdoc
42
	 */
43
	protected function validate(ErrorCollection $errors)
44
	{
45
		return true;
46
	}
47
48
	/**
49
	 * @inheritdoc
50
	 */
51
	protected function process()
52
	{
53
		$record = $this->record;
54
		$record->is_activated = true;
55
		$record->save();
56
57
		$this->response->message = $this->format('!name account is active.', [
58
59
			'!name' => $record->name
60
61
		]);
62
63
		return true;
64
	}
65
}
66