Skip to content

Commit 38b321c

Browse files
committed
improve code
1 parent b9d732c commit 38b321c

6 files changed

+9
-19
lines changed

build/build-emoji-regex.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
// -- modify class file
4242
$classContent = file_get_contents($classFile);
43-
$replacedClassContent = preg_replace('/(\s+const VALID_EMOJI_PATTERN = \')(?:.*)(\';)/', '$1/' . $regex . '/u$2', $classContent);
43+
$replacedClassContent = preg_replace('/(\s+public const VALID_EMOJI_PATTERN = \')(?:.*)(\';)/', '$1/' . $regex . '/u$2', $classContent);
4444

4545
echo $replacedClassContent;
4646

lib/Twitter/Text/Configuration.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function __construct(array $config = null)
139139
*/
140140
public function __get($name)
141141
{
142-
return isset($this->config[$name]) ? $this->config[$name] : null;
142+
return $this->config[$name] ?? null;
143143
}
144144

145145
/**

lib/Twitter/Text/EmojiRegex.php

+1-1
Large diffs are not rendered by default.

lib/Twitter/Text/HitHighlighter.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,10 @@ public function highlight($tweet = null, array $hits = null)
140140
$offset = 0;
141141
$start_in_chunk = false;
142142
# Flatten the multidimensional hits array:
143-
$hits_flat = call_user_func_array('array_merge', array_values($hits));
144-
$hits_flat_count = count($hits_flat);
143+
$hits_flat = array_merge(...array_values($hits));
145144
# Loop over the hit indices:
146-
for ($index = 0; $index < $hits_flat_count; $index++) {
147-
$hit = $hits_flat[$index];
145+
foreach ($hits_flat as $index => $indexValue) {
146+
$hit = $indexValue;
148147
$tag = $tags[$index % 2];
149148
$placed = false;
150149
while ($chunk !== null && $hit >= ($i = $offset + StringUtils::strlen($chunk))) {
@@ -159,7 +158,7 @@ public function highlight($tweet = null, array $hits = null)
159158
$offset += StringUtils::strlen($chunk);
160159
$chunk_cursor = 0;
161160
$chunk_index += 2;
162-
$chunk = (isset($chunks[$chunk_index]) ? $chunks[$chunk_index] : null);
161+
$chunk = $chunks[$chunk_index] ?? null;
163162
$start_in_chunk = false;
164163
}
165164
if (!$placed && $chunk !== null) {

lib/Twitter/Text/ParseResults.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function __get($name)
106106
return $this->validTextRange[1];
107107
}
108108

109-
return isset($this->result[$name]) ? $this->result[$name] : null;
109+
return $this->result[$name] ?? null;
110110
}
111111

112112
/**

lib/Twitter/Text/StringUtils.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ class StringUtils
3030
*/
3131
public static function substr($str, $start, $length = null, $encoding = 'UTF-8')
3232
{
33-
if ($length === null) {
34-
// for PHP <= 5.4.7
35-
$length = mb_strlen($str, $encoding);
36-
}
3733
return mb_substr($str, $start, $length, $encoding);
3834
}
3935

@@ -109,12 +105,7 @@ public static function substrReplace($string, $replacement, $start, $length = nu
109105
*/
110106
public static function idnToAscii($domain)
111107
{
112-
// INTL_IDNA_VARIANT_UTS46 defined PHP 5.4.0 or later
113-
if (defined('INTL_IDNA_VARIANT_UTS46')) {
114-
return idn_to_ascii($domain, IDNA_ALLOW_UNASSIGNED, INTL_IDNA_VARIANT_UTS46);
115-
}
116-
117-
return idn_to_ascii($domain, IDNA_ALLOW_UNASSIGNED);
108+
return idn_to_ascii($domain, IDNA_ALLOW_UNASSIGNED, INTL_IDNA_VARIANT_UTS46);
118109
}
119110

120111
/**

0 commit comments

Comments
 (0)