Failed Conditions
Pull Request — user-welcomefix (#623)
by Simon
32:14 queued 18:22
created

MigrateToDomains::execute()   A

Complexity

Conditions 5
Paths 9

Size

Total Lines 58
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 35
c 1
b 0
f 0
dl 0
loc 58
rs 9.0488
cc 5
nc 9
nop 0

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
 * 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\ConsoleTasks;
10
11
use Waca\DataObjects\Domain;
12
use Waca\DataObjects\RequestQueue;
13
use Waca\Tasks\ConsoleTaskBase;
14
15
class MigrateToDomains extends ConsoleTaskBase
16
{
17
    public function execute()
18
    {
19
        $siteConfiguration = $this->getSiteConfiguration();
20
21
        /** @noinspection PhpDeprecationInspection */
22
        $requestStates = $siteConfiguration->getRequestStates();
0 ignored issues
show
Deprecated Code introduced by
The function Waca\SiteConfiguration::getRequestStates() has been deprecated: To be removed after dynamic queues hit production. This will need to be major point release. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

22
        $requestStates = /** @scrutinizer ignore-deprecated */ $siteConfiguration->getRequestStates();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
23
        $database = $this->getDatabase();
24
25
        $domain = new Domain();
26
        $domain->setEnabled(true);
27
        $domain->setShortName('enwiki');
28
        $domain->setLongName('English Wikipedia');
29
        $domain->setWikiArticlePath($siteConfiguration->getMediawikiScriptPath());
30
        $domain->setWikiApiPath($siteConfiguration->getMediawikiWebServiceEndpoint());
31
        $domain->setEnabled(true);
32
        /** @noinspection PhpDeprecationInspection */
33
        $domain->setDefaultClose($siteConfiguration->getDefaultCreatedTemplateId());
0 ignored issues
show
Deprecated Code introduced by
The function Waca\SiteConfiguration::...aultCreatedTemplateId() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

33
        $domain->setDefaultClose(/** @scrutinizer ignore-deprecated */ $siteConfiguration->getDefaultCreatedTemplateId());
Loading history...
34
        $domain->setDefaultLanguage('en');
35
        $domain->setEmailSender('[email protected]');
36
        $domain->setNotificationTarget($siteConfiguration->getIrcNotificationType());
37
38
        $domain->setDatabase($database);
39
        $domain->save();
40
41
        foreach ($requestStates as $key => $data) {
42
            $state = new RequestQueue();
43
44
            /** @noinspection PhpDeprecationInspection */
45
            if ($siteConfiguration->getDefaultRequestStateKey() === $key) {
0 ignored issues
show
Deprecated Code introduced by
The function Waca\SiteConfiguration::...efaultRequestStateKey() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

45
            if (/** @scrutinizer ignore-deprecated */ $siteConfiguration->getDefaultRequestStateKey() === $key) {
Loading history...
46
                $state->setDefault(true);
47
            }
48
49
            /** @noinspection PhpDeprecationInspection */
50
            if ($siteConfiguration->getDefaultRequestDeferredStateKey() === $key) {
0 ignored issues
show
Deprecated Code introduced by
The function Waca\SiteConfiguration::...questDeferredStateKey() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

50
            if (/** @scrutinizer ignore-deprecated */ $siteConfiguration->getDefaultRequestDeferredStateKey() === $key) {
Loading history...
51
                $state->setDefaultAntispoof(true);
52
                $state->setDefaultTitleBlacklist(true);
53
            }
54
55
            $state->setDomain($domain->getId());
56
            $state->setApiName($data['api']);
57
            $state->setDisplayName($data['deferto']);
58
            $state->setHeader($data['header']);
59
            /** @noinspection PhpDeprecationInspection */
60
            $state->setLogName($data['defertolog']);
0 ignored issues
show
Deprecated Code introduced by
The function Waca\DataObjects\RequestQueue::setLogName() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

60
            /** @scrutinizer ignore-deprecated */ $state->setLogName($data['defertolog']);
Loading history...
61
            /** @noinspection PhpDeprecationInspection */
62
            $state->setLegacyStatus($key);
0 ignored issues
show
Deprecated Code introduced by
The function Waca\DataObjects\RequestQueue::setLegacyStatus() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

62
            /** @scrutinizer ignore-deprecated */ $state->setLegacyStatus($key);
Loading history...
63
            $state->setEnabled(true);
64
65
            if (isset($data['help'])) {
66
                $state->setHelp($data['help']);
67
            }
68
69
            $state->setDatabase($database);
70
            $state->save();
71
        }
72
73
        /** @noinspection SqlWithoutWhere */
74
        $database->exec("UPDATE schemaversion SET version = 37;");
75
    }
76
}
77