Completed
Pull Request — master (#23)
by Armando
15:35
created

AddPrefixToTables   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 60 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 30
loc 50
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 15 15 4
A down() 15 15 4

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
use Illuminate\Support\Facades\Log;
6
use Illuminate\Support\Facades\Schema;
7
use PhpTelegramBot\Laravel\Migration;
8
9
class AddPrefixToTables extends Migration
10
{
11
    /** @var string[] All PHP Telegram Bot database tables. */
12
    private $tables = [
13
        'botan_shortener',
14
        'callback_query',
15
        'chat',
16
        'chosen_inline_result',
17
        'conversation',
18
        'edited_message',
19
        'inline_query',
20
        'message',
21
        'user',
22
        'request_limiter',
23
        'telegram_update',
24
        'user_chat',
25
    ];
26
27 View Code Duplication
    public function up(): void
0 ignored issues
show
Duplication introduced by
This method 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...
28
    {
29
        foreach ($this->tables as $table) {
30
            try {
31
                if (Schema::hasTable($this->prefix . $table)) {
32
                    Log::warning("Prefixed table '{$this->prefix}{$table}' already exists. Verify your migration status.");
33
                    continue; // Migration may be partly done already...
34
                }
35
36
                Schema::rename($table, $this->prefix . $table);
37
            } catch (Throwable $e) {
38
                Log::error($e->getMessage());
39
            }
40
        }
41
    }
42
43 View Code Duplication
    public function down(): void
0 ignored issues
show
Duplication introduced by
This method 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...
44
    {
45
        foreach ($this->tables as $table) {
46
            try {
47
                if (Schema::hasTable($table)) {
48
                    Log::warning("Un-prefixed table '{$table}' already exists. Verify your migration status.");
49
                    continue; // Migration may be partly done already...
50
                }
51
52
                Schema::rename($this->prefix . $table, $table);
53
            } catch (Throwable $e) {
54
                Log::error($e->getMessage());
55
            }
56
        }
57
    }
58
}
59