Completed
Pull Request — master (#467)
by Maxence
01:47
created

Version0019Date20200726125713   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 44
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 3 3 1
A changeSchema() 19 19 3

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
declare(strict_types=1);
4
5
/**
6
 * Circles - Bring cloud-users closer together.
7
 *
8
 * This file is licensed under the Affero General Public License version 3 or
9
 * later. See the COPYING file.
10
 *
11
 * @author Maxence Lange <[email protected]>
12
 * @copyright 2019
13
 * @license GNU AGPL version 3 or any later version
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
 *
28
 */
29
30
31
namespace OCA\Circles\Migration;
32
33
34
use Closure;
35
use Doctrine\DBAL\Schema\SchemaException;
36
use OCP\DB\ISchemaWrapper;
37
use OCP\IDBConnection;
38
use OCP\Migration\IOutput;
39
use OCP\Migration\SimpleMigrationStep;
40
41
42
/**
43
 * Class Version0019Date20200726125713
44
 *
45
 * @package OCA\Circles\Migration
46
 */
47 View Code Duplication
class Version0019Date20200726125713 extends SimpleMigrationStep {
0 ignored issues
show
Duplication introduced by
This class 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...
48
49
50
	/** @var IDBConnection */
51
	private $connection;
52
53
54
	/**
55
	 * @param IDBConnection $connection
56
	 */
57
	public function __construct(IDBConnection $connection) {
58
		$this->connection = $connection;
59
	}
60
61
62
	/**
63
	 * @param IOutput $output
64
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
65
	 * @param array $options
66
	 *
67
	 * @return null|ISchemaWrapper
68
	 * @throws SchemaException
69
	 */
70
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
71
		/** @var ISchemaWrapper $schema */
72
		$schema = $schemaClosure();
73
74
		if ($schema->hasTable('circle_circles')) {
75
			$table = $schema->getTable('circle_circles');
76
			if (!$table->hasColumn('alt_name')) {
77
				$table->addColumn(
78
					'alt_name', 'string', [
79
								  'notnull' => true,
80
								  'length'  => 127,
81
								  'default' => ''
82
							  ]
83
				);
84
			}
85
		}
86
87
		return $schema;
88
	}
89
90
}
91
92