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
02:15
created

Registry::create()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 46
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 8.9411
c 0
b 0
f 0
cc 2
eloc 31
nc 2
nop 2
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\Hyphenator\Cache;
30
31
use PHP_Typography\Fixes\Node_Fix;
32
use PHP_Typography\Fixes\Token_Fix;
33
use PHP_Typography\Fixes\Token_Fixes\Hyphenate_Fix;
34
35
/**
36
 * Manages the fixes used by PHP_Typography.
37
 *
38
 * @author Peter Putzer <[email protected]>
39
 *
40
 * @since 6.0.0
41
 */
42
class Registry {
43
44
	const CHARACTERS         = 10;
45
	const SPACING_PRE_WORDS  = 20;
46
	const PROCESS_WORDS      = 30;
47
	const SPACING_POST_WORDS = 40;
48
	const HTML_INSERTION     = 50;
49
50
	const GROUPS = [ self::CHARACTERS, self::SPACING_PRE_WORDS, self::PROCESS_WORDS, self::SPACING_POST_WORDS, self::HTML_INSERTION ];
51
52
	/**
53
	 * An array of CSS classes that are added for ampersands, numbers etc.
54
	 */
55
	const DEFAULT_CSS_CLASSES = [
56
		'caps'        => 'caps',
57
		'numbers'     => 'numbers',
58
		'amp'         => 'amp',
59
		'quo'         => 'quo',
60
		'dquo'        => 'dquo',
61
		'pull-single' => 'pull-single',
62
		'pull-double' => 'pull-double',
63
		'push-single' => 'push-single',
64
		'push-double' => 'push-double',
65
		'numerator'   => 'numerator',
66
		'denominator' => 'denominator',
67
		'ordinal'     => 'ordinal',
68
	];
69
70
	/**
71
	 * An array of Node_Fix implementations.
72
	 *
73
	 * @var array
74
	 */
75
	private $node_fixes = [
76
		self::CHARACTERS         => [],
77
		self::SPACING_PRE_WORDS  => [],
78
		self::PROCESS_WORDS      => [],
79
		self::SPACING_POST_WORDS => [],
80
		self::HTML_INSERTION     => [],
81
	];
82
83
	/**
84
	 * The token fix registry.
85
	 *
86
	 * @var Node_Fixes\Process_Words_Fix
87
	 */
88
	private $process_words_fix;
89
90
	/**
91
	 * Creates new registry instance.
92
	 */
93
	public function __construct() {
94
		// Parse and process individual words.
95
		$this->process_words_fix = new Node_Fixes\Process_Words_Fix();
96
		$this->register_node_fix( $this->process_words_fix, self::PROCESS_WORDS );
97
	}
98
99
	/**
100
	 * Retrieves the registered node fixes.
101
	 *
102
	 * @return Node_Fix[][]
103
	 */
104
	public function get_node_fixes() {
105
		return $this->node_fixes;
106
	}
107
108
	/**
109
	 * Registers a node fix.
110
	 *
111
	 * @since 5.0.0
112
	 *
113
	 * @param Node_Fix $fix   Required.
114
	 * @param int      $group Required. Only the constants CHARACTERS, SPACING_PRE_WORDS, SPACING_POST_WORDS, HTML_INSERTION are valid.
115
	 *
116
	 * @throws \InvalidArgumentException Group is invalid.
117
	 */
118
	public function register_node_fix( Node_Fix $fix, $group ) {
119
		if ( isset( $this->node_fixes[ $group ] ) ) {
120
			$this->node_fixes[ $group ][] = $fix;
121
		} else {
122
			throw new \InvalidArgumentException( "Invalid fixer group $group." );
123
		}
124
	}
125
126
	/**
127
	 * Registers a token fix.
128
	 *
129
	 * @param Token_Fix $fix Required.
130
	 */
131
	public function register_token_fix( Token_Fix $fix ) {
132
		$this->process_words_fix->register_token_fix( $fix );
133
	}
134
135
	/**
136
	 * Sets the hyphenator cache for all registered token fixes (that require one).
137
	 *
138
	 * @param Cache $cache A hyphenator cache instance.
139
	 */
140
	public function update_hyphenator_cache( Cache $cache ) {
141
		$this->process_words_fix->update_hyphenator_cache( $cache );
142
	}
143
144
	/**
145
	 * Creates a new default registry instance.
146
	 *
147
	 * @param Cache|null    $cache       Optional. A hyphenatation cache instance to use. Default null.
148
	 * @param string[]|null $css_classes Optional. An array of CSS classes to use. Defaults to null (i.e. use the predefined classes).
149
	 *
150
	 * @return Registry
151
	 */
152
	public static function create( Cache $cache = null, array $css_classes = null ) {
153
		$registry = new Registry();
154
155
		if ( null === $css_classes ) {
156
			$css_classes = self::DEFAULT_CSS_CLASSES;
157
		}
158
159
		// Nodify anything that requires adjacent text awareness here.
160
		$registry->register_node_fix( new Node_Fixes\Smart_Maths_Fix(),          self::CHARACTERS );
161
		$registry->register_node_fix( new Node_Fixes\Smart_Diacritics_Fix(),     self::CHARACTERS );
162
		$registry->register_node_fix( new Node_Fixes\Smart_Quotes_Fix( true ),   self::CHARACTERS );
163
		$registry->register_node_fix( new Node_Fixes\Smart_Dashes_Fix( true ),   self::CHARACTERS );
164
		$registry->register_node_fix( new Node_Fixes\Smart_Ellipses_Fix( true ), self::CHARACTERS );
165
		$registry->register_node_fix( new Node_Fixes\Smart_Marks_Fix( true ),    self::CHARACTERS );
166
167
		// Keep spacing after smart character replacement.
168
		$registry->register_node_fix( new Node_Fixes\Single_Character_Word_Spacing_Fix(), self::SPACING_PRE_WORDS );
169
		$registry->register_node_fix( new Node_Fixes\Dash_Spacing_Fix(),                  self::SPACING_PRE_WORDS );
170
		$registry->register_node_fix( new Node_Fixes\Unit_Spacing_Fix(),                  self::SPACING_PRE_WORDS );
171
		$registry->register_node_fix( new Node_Fixes\Numbered_Abbreviation_Spacing_Fix(), self::SPACING_PRE_WORDS );
172
		$registry->register_node_fix( new Node_Fixes\French_Punctuation_Spacing_Fix(),    self::SPACING_PRE_WORDS );
173
174
		// Some final space manipulation.
175
		$registry->register_node_fix( new Node_Fixes\Dewidow_Fix(),        self::SPACING_POST_WORDS );
176
		$registry->register_node_fix( new Node_Fixes\Space_Collapse_Fix(), self::SPACING_POST_WORDS );
177
178
		// Everything that requires HTML injection occurs here (functions above assume tag-free content)
179
		// pay careful attention to functions below for tolerance of injected tags.
180
		$registry->register_node_fix( new Node_Fixes\Smart_Ordinal_Suffix_Fix( $css_classes['ordinal'] ),                           self::HTML_INSERTION ); // call before "style_numbers" and "smart_fractions".
181
		$registry->register_node_fix( new Node_Fixes\Smart_Exponents_Fix(),                                                         self::HTML_INSERTION ); // call before "style_numbers".
182
		$registry->register_node_fix( new Node_Fixes\Smart_Fractions_Fix( $css_classes['numerator'], $css_classes['denominator'] ), self::HTML_INSERTION ); // call before "style_numbers" and after "smart_ordinal_suffix".
183
		$registry->register_node_fix( new Node_Fixes\Style_Caps_Fix( $css_classes['caps'] ),                                        self::HTML_INSERTION ); // Call before "style_numbers".
184
		$registry->register_node_fix( new Node_Fixes\Style_Numbers_Fix( $css_classes['numbers'] ),                                  self::HTML_INSERTION ); // Call after "smart_ordinal_suffix", "smart_exponents", "smart_fractions", and "style_caps".
185
		$registry->register_node_fix( new Node_Fixes\Style_Ampersands_Fix( $css_classes['amp'] ),                                   self::HTML_INSERTION );
186
		$registry->register_node_fix( new Node_Fixes\Style_Initial_Quotes_Fix( $css_classes['quo'], $css_classes['dquo'] ),         self::HTML_INSERTION );
187
		$registry->register_node_fix( new Node_Fixes\Style_Hanging_Punctuation_Fix( $css_classes['push-single'], $css_classes['push-double'], $css_classes['pull-single'], $css_classes['pull-double'] ), self::HTML_INSERTION );
188
189
		// Register token fixes.
190
		$registry->register_token_fix( new Token_Fixes\Wrap_Hard_Hyphens_Fix() );
191
		$registry->register_token_fix( new Token_Fixes\Hyphenate_Compounds_Fix( $cache ) );
192
		$registry->register_token_fix( new Token_Fixes\Hyphenate_Fix( $cache ) );
193
		$registry->register_token_fix( new Token_Fixes\Wrap_URLs_Fix( $cache ) );
194
		$registry->register_token_fix( new Token_Fixes\Wrap_Emails_Fix() );
195
196
		return $registry;
197
	}
198
}
199