Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

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.
Passed
Pull Request — master (#44)
by Der Mundschenk
03:05
created

Default_Registry   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 1
dl 0
loc 152
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
C __construct() 0 37 8
A get_default_node_fixes() 0 61 1
A get_default_token_fixes() 0 9 1
1
<?php
2
/**
3
 *  This file is part of PHP-Typography.
4
 *
5
 *  Copyright 2017 Peter Putzer.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  (at your option) any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License along
18
 *  with this program; if not, write to the Free Software Foundation, Inc.,
19
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 *
21
 *  ***
22
 *
23
 *  @package mundschenk-at/php-typography
24
 *  @license http://www.gnu.org/licenses/gpl-2.0.html
25
 */
26
27
namespace PHP_Typography\Fixes;
28
29
use PHP_Typography\Settings;
30
31
use PHP_Typography\Fixes\Node_Fix;
32
use PHP_Typography\Fixes\Token_Fix;
33
34
use PHP_Typography\Hyphenator\Cache;
35
36
37
/**
38
 * A registry implementation containing the default fixes for PHP_Typography.
39
 *
40
 * @author Peter Putzer <[email protected]>
41
 *
42
 * @since 6.0.0
43
 */
44
class Default_Registry extends Registry {
45
46
	/**
47
	 * An array of CSS classes that are added for ampersands, numbers etc.
48
	 */
49
	const DEFAULT_CSS_CLASSES = [
50
		'caps'        => 'caps',
51
		'numbers'     => 'numbers',
52
		'amp'         => 'amp',
53
		'quo'         => 'quo',
54
		'dquo'        => 'dquo',
55
		'pull-single' => 'pull-single',
56
		'pull-double' => 'pull-double',
57
		'push-single' => 'push-single',
58
		'push-double' => 'push-double',
59
		'numerator'   => 'numerator',
60
		'denominator' => 'denominator',
61
		'ordinal'     => 'ordinal',
62
	];
63
64
	/**
65
	 * Creates new default registry instance.
66
	 *
67
	 * @param Cache|null $cache       Optional. A hyphenatation cache instance to use. Default null.
68
	 * @param string[]   $css_classes Optional. An array of CSS classes to use. Defaults to null (i.e. use the predefined classes).
69
	 */
70
	public function __construct( Cache $cache = null, array $css_classes = [] ) {
71
		parent::__construct();
72
73
		if ( empty( $css_classes ) ) {
74
			$css_classes = self::DEFAULT_CSS_CLASSES;
75
		}
76
77
		// Initialize node fixes.
78
		foreach ( self::get_default_node_fixes() as $group => $node_fixes ) {
79
			foreach ( $node_fixes as $fix => $params ) {
80
				$arguments = [];
81
82
				if ( ! empty( $params['classes'] ) ) {
83
					$arguments += array_map( function( $index ) use ( $css_classes ) {
84
						return $css_classes[ $index ];
85
					}, $params['classes'] );
86
				}
87
88
				if ( isset( $params['feed'] ) ) {
89
					$arguments += [ $params['feed'] ];
90
				}
91
92
				$this->register_node_fix( new $fix( ...$arguments ), $group );
93
			}
94
		}
95
96
		// Register token fixes.
97
		foreach ( self::get_default_token_fixes() as $fix => $params ) {
98
			$arguments = [];
99
100
			if ( ! empty( $params['cache'] ) ) {
101
				$arguments += [ $cache ];
102
			}
103
104
			$this->register_token_fix( new $fix( ...$arguments ) );
105
		}
106
	}
107
108
	/**
109
	 * Returns a configuration array for the default node fixes.
110
	 *
111
	 * @return array {
112
	 *     @type array $group {
113
	 *           A group of fixes.
114
	 *
115
	 *           @type array $fix_class Additional parameters for the fix constructor.
116
	 *     }
117
	 * }
118
	 */
119
	protected function get_default_node_fixes() {
120
		return [
121
			self::CHARACTERS         => [
122
				// Nodify anything that requires adjacent text awareness here.
123
				Node_Fixes\Smart_Maths_Fix::class      => [],
124
				Node_Fixes\Smart_Diacritics_Fix::class => [],
125
				Node_Fixes\Smart_Quotes_Fix::class     => [ 'feed' => true ],
126
				Node_Fixes\Smart_Dashes_Fix::class     => [ 'feed' => true ],
127
				Node_Fixes\Smart_Ellipses_Fix::class   => [ 'feed' => true ],
128
				Node_Fixes\Smart_Marks_Fix::class      => [ 'feed' => true ],
129
			],
130
131
			self::SPACING_PRE_WORDS  => [
132
				// Keep spacing after smart character replacement.
133
				Node_Fixes\Single_Character_Word_Spacing_Fix::class => [],
134
				Node_Fixes\Dash_Spacing_Fix::class                  => [],
135
				Node_Fixes\Unit_Spacing_Fix::class                  => [],
136
				Node_Fixes\Numbered_Abbreviation_Spacing_Fix::class => [],
137
				Node_Fixes\French_Punctuation_Spacing_Fix::class    => [],
138
			],
139
140
			self::SPACING_POST_WORDS => [
141
				// Some final space manipulation.
142
				Node_Fixes\Dewidow_Fix::class        => [],
143
				Node_Fixes\Space_Collapse_Fix::class => [],
144
			],
145
146
			self::HTML_INSERTION     => [
147
				// Everything that requires HTML injection occurs here (functions above assume tag-free content)
148
				// pay careful attention to functions below for tolerance of injected tags.
149
				Node_Fixes\Smart_Ordinal_Suffix_Fix::class      => [
150
					// call before "Style_Numbers_Fix" and "Smart_Fractions_Fix".
151
					'classes' => [ 'ordinal' ],
152
				],
153
				Node_Fixes\Smart_Exponents_Fix::class           => [
154
					// call before "Style_Numbers_Fix".
155
				],
156
				Node_Fixes\Smart_Fractions_Fix::class           => [
157
					// call before "Style_Numbers_Fix" and after "Smart_Ordinal_Suffix_Fix".
158
					'classes' => [ 'numerator', 'denominator' ],
159
				],
160
				Node_Fixes\Style_Caps_Fix::class                => [
161
					// Call before "Style_Numbers_Fix".
162
					'classes' => [ 'caps' ],
163
				],
164
				Node_Fixes\Style_Numbers_Fix::class             => [
165
					// Call after "Smart_Ordinal_Suffix_Fix", "Smart_Exponents_Fix", "Smart_Fractions_Fix", and "Style_Caps_Fix".
166
					'classes' => [ 'numbers' ],
167
				],
168
				Node_Fixes\Style_Ampersands_Fix::class          => [
169
					'classes' => [ 'amp' ],
170
				],
171
				Node_Fixes\Style_Initial_Quotes_Fix::class      => [
172
					'classes' => [ 'quo', 'dquo' ],
173
				],
174
				Node_Fixes\Style_Hanging_Punctuation_Fix::class => [
175
					'classes' => [ 'push-single', 'push-double', 'pull-single', 'pull-double' ],
176
				],
177
			],
178
		];
179
	}
180
181
	/**
182
	 * Returns a configuration array for the default token fixes.
183
	 *
184
	 * @return array
185
	 */
186
	protected function get_default_token_fixes() {
187
		return [
188
			Token_Fixes\Wrap_Hard_Hyphens_Fix::class   => [],
189
			Token_Fixes\Hyphenate_Compounds_Fix::class => [ 'cache' => true ],
190
			Token_Fixes\Hyphenate_Fix::class           => [ 'cache' => true ],
191
			Token_Fixes\Wrap_URLs_Fix::class           => [ 'cache' => true ],
192
			Token_Fixes\Wrap_Emails_Fix::class         => [],
193
		];
194
	}
195
}
196