DatabaseSchema::initialize()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 62
Code Lines 40

Duplication

Lines 16
Ratio 25.81 %

Code Coverage

Tests 15
CRAP Score 5.4852

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 16
loc 62
ccs 15
cts 43
cp 0.3488
rs 9.4743
cc 3
eloc 40
nc 3
nop 1
crap 5.4852

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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