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
Push — master ( 0a62a2...3df5ad )
by
unknown
05:31
created

SetupAfterCache::adjustConfiguration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * File containing the SetupAfterCache class
4
 *
5
 * This file is part of the MediaWiki skin Chameleon.
6
 *
7
 * @copyright 2013 - 2016, Stephan Gambke, mwjames
8
 * @license   GNU General Public License, version 3 (or any later version)
9
 *
10
 * The Chameleon skin is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by the Free
12
 * Software Foundation, either version 3 of the License, or (at your option) any
13
 * later version.
14
 *
15
 * The Chameleon skin is distributed in the hope that it will be useful, but
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18
 * details.
19
 *
20
 * You should have received a copy of the GNU General Public License along
21
 * with this program. If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 * @file
24
 * @ingroup Skins
25
 */
26
27
namespace Skins\Chameleon\Hooks;
28
29
use Bootstrap\BootstrapManager;
30
use RuntimeException;
31
32
/**
33
 * @see https://www.mediawiki.org/wiki/Manual:Hooks/SetupAfterCache
34
 *
35
 * @since 1.0
36
 *
37
 * @author mwjames
38
 * @author Stephan Gambke
39
 * @since 1.0
40
 * @ingroup Skins
41
 */
42
class SetupAfterCache {
43
44
	protected $bootstrapManager = null;
45
	protected $configuration = array();
46
47
	/**
48
	 * @since  1.0
49
	 *
50
	 * @param BootstrapManager $bootstrapManager
51
	 * @param array $configuration
52
	 */
53 1
	public function __construct( BootstrapManager $bootstrapManager, array &$configuration ) {
54 1
		$this->bootstrapManager = $bootstrapManager;
55 1
		$this->configuration = &$configuration;
56 1
	}
57
58
	/**
59
	 * @since  1.0
60
	 *
61
	 * @return self
62
	 */
63 9
	public function process() {
64
65 9
		$this->setInstallPaths();
66 9
		$this->addLateSettings();
67 9
		$this->registerCommonBootstrapModules();
68 9
		$this->registerExternalLessModules();
69 8
		$this->registerExternalLessVariables();
70
71 8
		return $this;
72
	}
73
74
	/**
75
	 * @since 1.0
76
	 *
77
	 * @param array $configuration
78
	 */
79 1
	public function adjustConfiguration( array &$configuration ) {
80
81 1
		foreach ( $this->configuration as $key => $value ) {
82 1
			$configuration[ $key ] = $value;
83 1
		}
84 1
	}
85
86
	/**
87
	 * Set local and remote base path of the Chameleon skin
88
	 */
89 9
	protected function setInstallPaths() {
90
91 9
		$this->configuration[ 'chameleonLocalPath' ] = $this->configuration['wgStyleDirectory'] . DIRECTORY_SEPARATOR . 'chameleon';
92 9
		$this->configuration[ 'chameleonRemotePath' ] = $this->configuration['wgStylePath'] . '/chameleon';
93 9
	}
94
95 9
	protected function addLateSettings() {
96
97
		// if Visual Editor is installed and there is a setting to enable or disable it
98 9
		if ( $this->hasConfiguration( 'wgVisualEditorSupportedSkins' ) && $this->hasConfiguration( 'egChameleonEnableVisualEditor' ) ) {
99
100
			// if VE should be enabled
101 3
			if ( $this->configuration[ 'egChameleonEnableVisualEditor' ] === true ) {
102
103
				// if Chameleon is not yet in the list of VE-enabled skins
104 2
				if ( !in_array( 'chameleon', $this->configuration[ 'wgVisualEditorSupportedSkins' ] ) ) {
105 1
					$this->configuration[ 'wgVisualEditorSupportedSkins' ][ ] = 'chameleon';
106 1
				}
107
108 2
			} else {
109
				// remove all entries of Chameleon from the list of VE-enabled skins
110 1
				$this->configuration[ 'wgVisualEditorSupportedSkins' ] = array_diff(
111 1
					$this->configuration[ 'wgVisualEditorSupportedSkins' ],
112 1
					array( 'chameleon' )
113 1
				);
114
			}
115 3
		}
116
117 9
		$this->configuration[ 'wgResourceModules' ][ 'skin.chameleon.jquery-sticky' ] = array(
118 9
			'localBasePath' => $this->configuration[ 'chameleonLocalPath' ] . '/resources/js',
119 9
			'remoteBasePath' => $this->configuration[ 'chameleonRemotePath' ] . '/resources/js',
120 9
			'group' => 'skin.chameleon',
121 9
			'skinScripts' => array( 'chameleon' => array( 'jquery-sticky/jquery.sticky.js', 'Components/Modifications/sticky.js' ) )
122 9
		);
123
124 9
	}
125
126 9
	protected function registerCommonBootstrapModules() {
127
128 9
		$this->bootstrapManager->addAllBootstrapModules();
129
130 9
		if ( file_exists( $this->configuration[ 'wgStyleDirectory' ] . '/common/shared.css' ) ) { // MW < 1.24
131
			$this->bootstrapManager->addExternalModule(
132
				$this->configuration[ 'wgStyleDirectory' ] . '/common/shared.css',
133
				$this->configuration[ 'wgStylePath' ] . '/common/'
134
			);
135
		} else {
136 9
			if ( file_exists( $this->configuration[ 'IP' ] . '/resources/src/mediawiki.legacy/shared.css' ) ) { // MW >= 1.24
137 6
				$this->bootstrapManager->addExternalModule(
138 6
					$this->configuration[ 'IP' ] . '/resources/src/mediawiki.legacy/shared.css',
139 6
					$this->configuration[ 'wgScriptPath' ] . '/resources/src/mediawiki.legacy/'
140 6
				);
141 6
			}
142
		}
143
144 9
		$this->bootstrapManager->addExternalModule(
145 9
			$this->configuration[ 'chameleonLocalPath' ] . '/resources/styles/core.less',
146 9
			$this->configuration[ 'chameleonRemotePath' ] . '/resources/styles/'
147 9
		);
148 9
	}
149
150 9
	protected function registerExternalLessModules() {
151
152 9
		if ( $this->hasConfigurationOfTypeArray( 'egChameleonExternalStyleModules' ) ) {
153
154 2
			foreach ( $this->configuration[ 'egChameleonExternalStyleModules' ] as $localFile => $remotePath ) {
155
156 2
				list( $localFile, $remotePath ) = $this->matchAssociativeElement( $localFile, $remotePath );
157
158 2
				$this->bootstrapManager->addExternalModule(
159 2
					$this->isReadableFile( $localFile ),
160
					$remotePath
161 1
				);
162 1
			}
163 1
		}
164 8
	}
165
166 8
	protected function registerExternalLessVariables() {
167
168 8
		if ( $this->hasConfigurationOfTypeArray( 'egChameleonExternalLessVariables' ) ) {
169
170 1
			foreach ( $this->configuration[ 'egChameleonExternalLessVariables' ] as $key => $value ) {
171 1
				$this->bootstrapManager->setLessVariable( $key, $value );
172 1
			}
173 1
		}
174 8
	}
175
176
	/**
177
	 * @param $id
178
	 * @return bool
179
	 */
180 9
	private function hasConfiguration( $id ) {
181 9
		return isset( $this->configuration[ $id ] );
182
	}
183
184
	/**
185
	 * @param string $id
186
	 * @return bool
187
	 */
188 9
	private function hasConfigurationOfTypeArray( $id ) {
189 9
		return $this->hasConfiguration( $id ) && is_array( $this->configuration[ $id ] );
190
	}
191
192
	/**
193
	 * @param $localFile
194
	 * @param $remotePath
195
	 * @return array
196
	 */
197 2
	private function matchAssociativeElement( $localFile, $remotePath ) {
198
199 2
		if ( is_integer( $localFile ) ) {
200 2
			return array( $remotePath, '' );
201
		}
202
203 1
		return array( $localFile, $remotePath );
204
	}
205
206
	/**
207
	 * @param string $file
208
	 * @return string
209
	 */
210 2
	private function isReadableFile( $file ) {
211
212 2
		if ( is_readable( $file ) ) {
213 1
			return $file;
214
		}
215
216 1
		throw new RuntimeException( "Expected an accessible {$file} file" );
217
	}
218
219
}
220