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

Strings::_uchr()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 *  This file is part of PHP-Typography.
4
 *
5
 *  Copyright 2014-2017 Peter Putzer.
6
 *  Copyright 2009-2011 KINGdesk, LLC.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  (at your option) any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License along
19
 *  with this program; if not, write to the Free Software Foundation, Inc.,
20
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
 *
22
 *  ***
23
 *
24
 *  @package mundschenk-at/php-typography
25
 *  @license http://www.gnu.org/licenses/gpl-2.0.html
26
 */
27
28
namespace PHP_Typography;
29
30
/**
31
 * A utility class to handle fast and save string function access.
32
 *
33
 * @since 4.2.0
34
 */
35
abstract class Strings {
36
	/**
37
	 * Utility patterns for splitting string parameter lists into arrays.
38
	 *
39
	 * @var string
40
	 */
41
	const _RE_PARAMETER_SPLITTING = '/[\s,]+/S';
42
43
	/**
44
	 * An array of encodings in detection order.
45
	 *
46
	 * ASCII has to be first to have a chance of detection.
47
	 *
48
	 * @var array
49
	 */
50
	const _ENCODINGS = [ 'ASCII', 'UTF-8' ];
51
52
	/**
53
	 * A hash map for string functions according to encoding.
54
	 *
55
	 * @var array $encoding => [ 'strlen' => $function_name, ... ].
56
	 */
57
	const _STRING_FUNCTIONS = [
58
		'UTF-8' => [
59
			'strlen'     => 'mb_strlen',
60
			'str_split'  => [ __CLASS__, 'mb_str_split' ],
61
			'strtolower' => 'mb_strtolower',
62
			'strtoupper' => 'mb_strtoupper',
63
			'substr'     => 'mb_substr',
64
			'u'          => 'u',
65
		],
66
		'ASCII' => [
67
			'strlen'     => 'strlen',
68
			'str_split'  => 'str_split',
69
			'strtolower' => 'strtolower',
70
			'strtoupper' => 'strtoupper',
71
			'substr'     => 'substr',
72
			'u'          => '',
73
		],
74
		false   => [],
75
	];
76
77
	/**
78
	 * Retrieves str* functions.
79
	 *
80
	 * @param  string $str A string to detect the encoding from.
81
	 * @return array {
82
	 *         An array of string functions.
83
	 *
84
	 *         'strlen'     => callable,
85
	 *         'str_split'  => callable,
86
	 *         'strtolower' => callable,
87
	 *         'strtoupper' => callable,
88
	 *         'substr'     => callable,
89
	 *         'u'          => modifier string
90
	 * }
91
	 */
92
	public static function functions( $str ) {
93
		return self::_STRING_FUNCTIONS[ mb_detect_encoding( $str, self::_ENCODINGS, true ) ];
94
	}
95
96
	/**
97
	 * Multibyte-safe str_split function.
98
	 *
99
	 * Unlike str_split, a $split_length less than 1 is ignored (and thus
100
	 * equivalent to the default).
101
	 *
102
	 * @param string $str           Required.
103
	 * @param int    $split_length  Optional. Default 1.
104
	 *
105
	 * @return array                An array of $split_length character chunks.
106
	 */
107
	public static function mb_str_split( $str, $split_length = 1 ) {
108
		$result = preg_split( '//u', $str , -1, PREG_SPLIT_NO_EMPTY );
109
110
		if ( $split_length > 1 ) {
111
			$splits = [];
112
			foreach ( array_chunk( $result, $split_length ) as $chunk ) {
113
				$splits[] = join( '', $chunk );
114
			}
115
116
			$result = $splits;
117
		}
118
119
		return $result;
120
	}
121
122
	/**
123
	 * Converts decimal value to unicode character.
124
	 *
125
	 * @param int|string|array $codes Decimal value(s) coresponding to unicode character(s).
126
	 *
127
	 * @return string Unicode character(s).
128
	 */
129
	public static function uchr( $codes ) {
130
131
		// Single character code.
132
		if ( is_scalar( $codes ) ) {
133
			$codes = func_get_args();
134
		}
135
136
		// Deal with an array of character codes.
137
		$str = '';
138
		foreach ( $codes as $code ) {
139
			$str .= html_entity_decode( '&#' . (int) $code . ';', ENT_NOQUOTES, 'UTF-8' );
140
		}
141
142
		return $str;
143
	}
144
145
	/**
146
	 * If necessary, split the passed parameters string into an array.
147
	 *
148
	 * @param  array|string $params Parameters.
149
	 *
150
	 * @return array
151
	 */
152
	public static function maybe_split_parameters( $params ) {
153
		if ( ! is_array( $params ) ) {
154
			$params = preg_split( self::_RE_PARAMETER_SPLITTING, $params, -1, PREG_SPLIT_NO_EMPTY );
155
		}
156
157
		return $params;
158
	}
159
}
160