DatabaseSchema   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 67
Duplicated Lines 23.88 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 34.88%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 3
c 3
b 0
f 1
lcom 0
cbo 3
dl 16
loc 67
ccs 15
cts 43
cp 0.3488
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A initialize() 16 62 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
namespace tomzx\IRCStats;
4
5
use Illuminate\Database\Connection;
6
use Illuminate\Database\Schema\Blueprint;
7
8
class DatabaseSchema {
9
	/**
10
	 * @param \Illuminate\Database\Connection $db
11
	 */
12 1
	public function initialize(Connection $db)
13
	{
14 1
		$builder = $db->getSchemaBuilder();
15
16
		$tables = [
17
			'networks'   => function (Blueprint $table) {
18
				$table->increments('id');
19
				$table->string('server');
20
				$table->unique(['server']);
21 1
			},
22 View Code Duplication
			'channels'   => function (Blueprint $table) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
23
				$table->increments('id');
24
				$table->integer('network_id')->unsigned();
25
				$table->string('channel');
26
				$table->unique(['network_id', 'channel']);
27
28
				$table->foreign('network_id')->references('id')->on('networks');
29 1
			},
30 View Code Duplication
			'nicks'      => function (Blueprint $table) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
31
				$table->increments('id');
32
				$table->integer('network_id')->unsigned();
33
				$table->string('nick');
34
				$table->unique(['network_id', 'nick']);
35
36
				$table->foreign('network_id')->references('id')->on('networks');
37 1
			},
38
			'logs'       => function (Blueprint $table) {
39
				$table->increments('id');
40
				$table->integer('channel_id')->unsigned();
41
				$table->integer('nick_id')->unsigned();
42
				$table->timestamp('timestamp');
43
				$table->text('message');
44
45
				$table->foreign('channel_id')->references('id')->on('channels');
46
				$table->foreign('nick_id')->references('id')->on('nicks');
47 1
			},
48
			// Generated data tables based on the content of the previous tables
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% 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...
49
//			'dictionary' => function (Blueprint $table) {
50
//				$table->increments('id');
51
//				$table->string('word', 40);
52
//			},
53
			'words'      => function (Blueprint $table) {
54
				$table->increments('id');
55
				$table->string('word', 40);
56 1
			},
57 1
			'logs_words' => function (Blueprint $table) {
58
				$table->increments('id');
59
				$table->integer('logs_id')->unsigned();
60
				$table->integer('word_id')->unsigned();
61
62
				$table->foreign('logs_id')->references('id')->on('logs');
63
				$table->foreign('word_id')->references('id')->on('words');
64 1
			},
65 1
		];
66
67 1
		foreach ($tables as $table => $callback) {
68 1
			if ($builder->hasTable($table)) {
69
				continue;
70
			}
71 1
			$builder->create($table, $callback);
72 1
		}
73 1
	}
74
}
75