GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — integration (#2604)
by Brendan
05:28
created

UpdaterPage   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 156
Duplicated Lines 21.79 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 34
loc 156
rs 10
wmc 18
lcom 1
cbo 5

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B __build() 0 23 4
A viewUptodate() 0 11 1
B viewReady() 6 41 5
A viewFailure() 20 20 2
B viewSuccess() 8 46 5

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
/**
4
 * @package install
5
 */
6
namespace SymphonyCms\Installer\Lib;
7
8
use Exception;
9
use Symphony;
10
use Widget;
11
use XMLElement;
12
13
class UpdaterPage extends InstallerPage
14
{
15
    public function __construct($template, $params = array())
16
    {
17
        parent::__construct($template, $params);
18
19
        $this->_template = $template;
20
        $this->_page_title = __('Update Symphony');
21
    }
22
23
    protected function __build($version = VERSION, XMLElement $extra = null)
24
    {
25
        parent::__build(
26
            // Replace the installed version with the updated version
27
            isset($this->_params['version'])
28
                ? $this->_params['version']
29
                : Symphony::Configuration()->get('version', 'symphony')
30
        );
31
32
        // Add Release Notes for the latest migration
33
        if (isset($this->_params['release-notes'])) {
34
            $nodeset = $this->Form->getChildrenByName('h1');
35
            $h1 = end($nodeset);
36
            if ($h1 instanceof XMLElement) {
37
                $h1->appendChild(
38
                    new XMLElement(
39
                        'em',
40
                        Widget::Anchor(__('Release Notes'), $this->_params['release-notes'])
41
                    )
42
                );
43
            }
44
        }
45
    }
46
47
    protected function viewUptodate()
48
    {
49
        $h2 = new XMLElement('h2', __('Symphony is already up-to-date'));
50
        $p = new XMLElement(
51
            'p',
52
            __('It appears that Symphony has already been installed at this location and is up to date.')
53
        );
54
55
        $this->Form->appendChild($h2);
56
        $this->Form->appendChild($p);
57
    }
58
59
    protected function viewReady()
60
    {
61
        $h2 = new XMLElement('h2', __('Updating Symphony'));
62
        $p = new XMLElement('p', __(
63
            'This script will update your existing Symphony installation to version %s.',
64
            array('<code>' . $this->_params['version'] . '</code>')
65
        ));
66
67
        $this->Form->appendChild($h2);
68
        $this->Form->appendChild($p);
69
70
        if (!is_writable(CONFIG)) {
71
            $this->Form->appendChild(
72
                new XMLElement(
73
                    'p',
74
                    __('Please check that your configuration file is writable before proceeding'),
75
                    array('class' => 'warning')
76
                )
77
            );
78
        }
79
80
        if (!empty($this->_params['pre-notes'])) {
81
            $h2 = new XMLElement('h2', __('Pre-Installation Notes:'));
82
            $dl = new XMLElement('dl');
83
84 View Code Duplication
            foreach ($this->_params['pre-notes'] as $version => $notes) {
85
                $dl->appendChild(new XMLElement('dt', $version));
86
                foreach ($notes as $note) {
87
                    $dl->appendChild(new XMLElement('dd', $note));
88
                }
89
            }
90
91
            $this->Form->appendChild($h2);
92
            $this->Form->appendChild($dl);
93
        }
94
95
        $submit = new XMLElement('div', null, array('class' => 'submit'));
96
        $submit->appendChild(Widget::Input('action[update]', __('Update Symphony'), 'submit'));
97
98
        $this->Form->appendChild($submit);
99
    }
100
101 View Code Duplication
    protected function viewFailure()
102
    {
103
        $h2 = new XMLElement('h2', __('Updating Failure'));
104
        $p = new XMLElement('p', __('An error occurred while updating Symphony.'));
105
106
        // Attempt to get update information from the log fileØ
107
        try {
108
            $log = file_get_contents(INSTALL_LOGS . '/update');
109
        } catch (Exception $ex) {
110
            $log = (string)$ex;
111
        }
112
113
        $code = new XMLElement('code', $log);
114
115
        $this->Form->appendChild($h2);
116
        $this->Form->appendChild($p);
117
        $this->Form->appendChild(
118
            new XMLElement('pre', $code)
119
        );
120
    }
121
122
    protected function viewSuccess()
123
    {
124
        $this->Form->setAttribute('action', SYMPHONY_URL);
125
126
        $h2 = new XMLElement('h2', __('Updating Complete'));
127
        $this->Form->appendChild($h2);
128
129
        if (!empty($this->_params['post-notes'])) {
130
            $dl = new XMLElement('dl');
131
132 View Code Duplication
            foreach ($this->_params['post-notes'] as $version => $notes) {
133
                if ($notes) {
134
                    $dl->appendChild(new XMLElement('dt', $version));
135
                    foreach ($notes as $note) {
136
                        $dl->appendChild(new XMLElement('dd', $note));
137
                    }
138
                }
139
            }
140
141
            $this->Form->appendChild($dl);
142
        }
143
144
        $this->Form->appendChild(
145
            new XMLElement(
146
                'p',
147
                __(
148
                    'And the crowd goes wild! A victory dance is in order; and look, your mum is watching. She\'s proud.',
149
                    array(Symphony::Configuration()->get('sitename', 'general'))
150
                )
151
            )
152
        );
153
        $this->Form->appendChild(
154
            new XMLElement(
155
                'p',
156
                __(
157
                    'Your mum is also nagging you about removing that %s directory before you log in.',
158
                    array('<code>' . basename(INSTALL_URL) . '</code>')
159
                )
160
            )
161
        );
162
163
        $submit = new XMLElement('div', null, array('class' => 'submit'));
164
        $submit->appendChild(Widget::Input('submit', __('Complete'), 'submit'));
165
166
        $this->Form->appendChild($submit);
167
    }
168
}
169