ext   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 19
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 114
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B enable_step() 0 50 5
A disable_step() 0 15 2
C purge_step() 0 42 12
1
<?php
2
3
namespace florinp\messenger;
4
5
6
class ext extends \phpbb\extension\base
7
{
8
9
    public function enable_step($old_state)
10
    {
11
        global $phpbb_root_path;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
12
13
        switch ($old_state) {
14
            case '':
15
                $db = new \florinp\messenger\libs\database();
16
                $db->exec("
17
          CREATE TABLE IF NOT EXISTS messages (
18
            `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
19
            `sender_id` INTEGER NOT NULL,
20
            `receiver_id` INTEGER NOT NULL,
21
            `text` TEXT NOT NULL,
22
            `newMsg` INTEGER DEFAULT 0,
23
            `sentAt` INTEGER NOT NULL
24
          );
25
          CREATE TABLE IF NOT EXISTS files (
26
            `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
27
            `sender_id` INTEGER NOT NULL,
28
            `receiver_id` INTEGER NOT NULL,
29
            `fileName` VARCHAR(255) NOT NULL,
30
            `file` VARCHAR(255) NOT NULL,
31
            `type` VARCHAR(255) NOT NULL,
32
            `sentAt` INTEGER NOT NULL
33
          );
34
        ");
35
36
                $messengerDir = $phpbb_root_path . 'store/messenger';
37
                if (!is_dir($messengerDir)) {
38
                    mkdir($messengerDir, 0777);
39
                    $filesDir = $messengerDir . '/files';
40
                    if (!is_dir($filesDir)) {
41
                        mkdir($filesDir, 0777);
42
                    }
43
                }
44
                return 'notifications';
45
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
46
47
            case 'notifications':
48
                $phpbb_notifications = $this->container->get('notification_manager');
49
                $phpbb_notifications->enable_notifications('florinp.messenger.notification.type.friend_request');
50
                return 'step2';
51
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
52
53
            default:
54
                return parent::enable_step($old_state);
55
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
56
        }
57
58
    }
59
60
    public function disable_step($old_state)
61
    {
62
        switch ($old_state) {
63
            case '':
64
                $phpbb_notifications = $this->container->get('notification_manager');
65
                $phpbb_notifications->disable_notifications('florinp.messenger.notification.type.friend_request');
66
                return 'notifications';
67
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
68
69
            default:
0 ignored issues
show
Coding Style introduced by
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
70
71
                return parent::disable_step($old_state);
72
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
73
        }
74
    }
75
76
    public function purge_step($old_state)
77
    {
78
        global $phpbb_root_path;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
79
80
        $database = $phpbb_root_path . 'store/messenger.db';
81
        if (is_file($database)) {
82
            unlink($database);
83
        }
84
85
        $messengerDir = $phpbb_root_path . 'store/messenger';
86
        if (is_dir($messengerDir)) {
87
            $objects = scandir($messengerDir);
88
            foreach ($objects as $object) {
89
                if ($object != '.' && $object != '..') {
90
                    if (filetype($messengerDir . "/" . $object) == "dir") {
91
                        $dir = $messengerDir . "/" . $object;
92
                        $subObjects = scandir($dir);
93
                        if(count($subObjects) > 0) {
94
                            foreach($subObjects as $subObject) {
95
                                if($subObject != '.' && $subObject != '..') {
96
                                    if(filetype($dir . '/' . $subObject) != 'dir') {
97
                                        unlink($dir . '/' . $subObject);
98
                                    }
99
                                } else {
100
                                    continue;
101
                                }
102
                            }
103
104
                        }
105
                        rmdir($messengerDir . "/" . $object);
106
                    } else {
107
                        unlink($messengerDir . "/" . $object);
108
                    }
109
                }
110
            }
111
            reset($objects);
112
            rmdir($messengerDir);
113
        }
114
115
        return parent::purge_step($old_state);
116
117
    }
118
119
}
120