Completed
Push — master ( 9ba851...d8a65a )
by Vladimir
09:32 queued 26s
created

BanMuteSupportIssue157   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 88.57 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 31
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 17 17 1
A down() 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
use Phinx\Migration\AbstractMigration;
4
5
/**
6
 * Restructure the `bans` table to better support bans and mutes.
7
 *
8
 * - The `allow_server_join` column was never correctly used and therefore has been dropped; due to incorrect use, the
9
 *   data did not need to be migrated or saved.
10
 * - The `is_soft_ban` column is being added to differentiate between bans that should penalize players on the site
11
 *   itself and bans that will only affect players on league servers. A soft ban will not affect a player on BZiON.
12
 *
13
 * @link https://github.com/allejo/bzion/issues/157
14
 */
15
class BanMuteSupportIssue157 extends AbstractMigration
16
{
17 View Code Duplication
    public function up()
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...
18
    {
19
        $bansTable = $this->table('bans');
20
        $bansTable
21
            ->removeColumn('allow_server_join')
22
            ->addColumn('is_soft_ban', 'boolean', [
23
                'after' => 'author',
24
                'null' => false,
25
                'default' => false,
26
                'comment' => 'A soft ban will not penalize a user on the site or servers',
27
            ])
28
            ->update()
29
        ;
30
31
        // Unban any currently banned players
32
        $this->query("UPDATE players SET status = 'active' WHERE status = 'banned';");
33
    }
34
35 View Code Duplication
    public function down()
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...
36
    {
37
        $bansTable = $this->table('bans');
38
        $bansTable
39
            ->removeColumn('is_soft_ban')
40
            ->addColumn('allow_server_join', 'boolean', [
41
                'after' => 'reason',
42
                'null' => false,
43
                'default' => false,
44
                'comment' => 'Whether or not to allow players to join servers while banned'
45
            ])
46
            ->update()
47
        ;
48
    }
49
}
50