Passed
Pull Request — multiproject/db (#703)
by Simon
02:48
created

RequestQueueHelper   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
eloc 8
c 1
b 0
f 0
dl 0
loc 30
ccs 8
cts 8
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B configureDefaults() 0 21 11
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca\Helpers;
10
11
use Waca\DataObjects\RequestQueue;
12
13
class RequestQueueHelper
14
{
15
    /**
16
     * @param RequestQueue $queue
17
     * @param bool         $enabled
18
     * @param bool         $default
19
     * @param bool         $antiSpoof
20
     * @param bool         $titleBlacklist
21
     */
22 256
    public function configureDefaults(
23
        RequestQueue $queue,
24
        bool $enabled,
25
        bool $default,
26
        bool $antiSpoof,
27
        bool $titleBlacklist
28
    ) {
29
        // always allow enabling a queue
30 256
        if ($enabled) {
31 128
            $queue->setEnabled($enabled);
32
        }
33
34
        // only allow other enable-flag changes if we're not a default
35 256
        if (!($queue->isDefault() || $queue->isDefaultAntispoof() || $queue->isDefaultTitleBlacklist())) {
36 32
            $queue->setEnabled($enabled);
37
        }
38
39
        // only allow enabling the default flags, and only when we're enabled.
40 256
        $queue->setDefault(($queue->isDefault() || $default) && $queue->isEnabled());
41 256
        $queue->setDefaultAntispoof(($queue->isDefaultAntispoof() || $antiSpoof) && $queue->isEnabled());
42 256
        $queue->setDefaultTitleBlacklist(($queue->isDefaultTitleBlacklist() || $titleBlacklist) && $queue->isEnabled());
43
    }
44
}