update: helpers

This commit is contained in:
HDVinnie
2022-02-28 04:59:08 -05:00
parent 59cb757daf
commit c0eeef8808
10 changed files with 101 additions and 107 deletions
+4 -4
View File
@@ -22,26 +22,26 @@ class BackupEncryption
*
* @var string
*/
public const ENCRYPTION_DEFAULT = ZipArchive::EM_AES_128;
public final const ENCRYPTION_DEFAULT = ZipArchive::EM_AES_128;
/**
* AES-128 encryption contants.
*
* @var string
*/
public const ENCRYPTION_WINZIP_AES_128 = ZipArchive::EM_AES_128;
public final const ENCRYPTION_WINZIP_AES_128 = ZipArchive::EM_AES_128;
/**
* AES-192 encryption contants.
*
* @var string
*/
public const ENCRYPTION_WINZIP_AES_192 = ZipArchive::EM_AES_192;
public final const ENCRYPTION_WINZIP_AES_192 = ZipArchive::EM_AES_192;
/**
* AES-256 encryption contants.
*
* @var string
*/
public const ENCRYPTION_WINZIP_AES_256 = ZipArchive::EM_AES_256;
public final const ENCRYPTION_WINZIP_AES_256 = ZipArchive::EM_AES_256;
}
+1 -1
View File
@@ -313,7 +313,7 @@ class Bbcode
*/
protected function searchAndReplace(string $pattern, string $replace, string $source): ?string
{
while (\preg_match($pattern, $source)) {
while (\preg_match($pattern, (string) $source)) {
$source = \preg_replace($pattern, $replace, $source);
}
+4 -4
View File
@@ -19,7 +19,7 @@ class Bencode
{
public static function parse_integer($s, &$pos)
{
$len = \strlen($s);
$len = \strlen((string) $s);
if ($len === 0 || $s[$pos] != 'i') {
return;
}
@@ -52,7 +52,7 @@ class Bencode
public static function parse_string($s, &$pos)
{
$len = \strlen($s);
$len = \strlen((string) $s);
$lengthStr = '';
while ($pos < $len && $s[$pos] != ':') {
@@ -94,7 +94,7 @@ class Bencode
public static function bdecode($s, &$pos = 0)
{
$len = \strlen($s);
$len = \strlen((string) $s);
if ($pos >= $len) {
return;
}
@@ -180,7 +180,7 @@ class Bencode
foreach ($d as $key => $value) {
if ($isDict) {
$ret .= \strlen($key).':'.$key;
$ret .= \strlen((string) $key).':'.$key;
}
if (\is_int($value) || \is_float($value)) {
+1 -3
View File
@@ -23,8 +23,6 @@ class CacheUser
return;
}
return \cache()->remember('cachedUser.'.$id, 30, function () use ($id) {
return User::find($id);
});
return \cache()->remember('cachedUser.'.$id, 30, fn() => User::find($id));
}
}
+7 -7
View File
@@ -27,15 +27,15 @@ class LanguageCensor
protected static function isSpecial($c): bool
{
return \str_contains(self::SPECIAL_CHARS, $c);
return \str_contains(self::SPECIAL_CHARS, (string) $c);
}
protected static function matchWordIndexes($string, $word): array
{
$result = [];
$length = \strlen($word);
$stringLength = \strlen($string);
$pos = \stripos($string, $word, 0);
$length = \strlen((string) $word);
$stringLength = \strlen((string) $string);
$pos = \stripos($string, (string) $word, 0);
while ($pos !== false) {
$prev = ($pos === 0) ? ' ' : $string[$pos - 1];
$last = ($pos + $length) < $stringLength ? $string[$pos + $length] : ' ';
@@ -43,7 +43,7 @@ class LanguageCensor
$result[] = $pos;
}
$pos = \stripos($string, $word, $pos + $length);
$pos = \stripos($string, (string) $word, $pos + $length);
}
return $result;
@@ -56,8 +56,8 @@ class LanguageCensor
{
foreach (\config('censor.redact', []) as $word) {
$result = '';
$length = \strlen($source);
$wordLength = \strlen($word);
$length = \strlen((string) $source);
$wordLength = \strlen((string) $word);
\assert($wordLength > 0);
$indexes = self::matchWordIndexes($source, $word);
$ignore = 0;
+50 -49
View File
@@ -373,7 +373,7 @@ class Markdown
],
];
if (\str_contains($Line['text'], '-->')) {
if (\str_contains((string) $Line['text'], '-->')) {
$Block['closed'] = true;
}
@@ -389,7 +389,7 @@ class Markdown
$Block['element']['rawHtml'] .= "\n".$Line['body'];
if (\str_contains($Line['text'], '-->')) {
if (\str_contains((string) $Line['text'], '-->')) {
$Block['closed'] = true;
}
@@ -517,8 +517,8 @@ class Markdown
{
[$name, $pattern] = $Line['text'][0] <= '-' ? ['ul', '[*+-]'] : ['ol', '[0-9]{1,9}+[.\)]'];
if (\preg_match('/^('.$pattern.'([ ]++|$))(.*+)/', $Line['text'], $matches)) {
$contentIndent = \strlen($matches[2]);
if (\preg_match('/^('.$pattern.'([ ]++|$))(.*+)/', (string) $Line['text'], $matches)) {
$contentIndent = \strlen((string) $matches[2]);
if ($contentIndent >= 5) {
$contentIndent--;
@@ -546,7 +546,7 @@ class Markdown
$Block['data']['markerTypeRegex'] = \preg_quote($Block['data']['markerType'], '/');
if ($name === 'ol') {
$listStart = \ltrim(\strstr($matches[1], $Block['data']['markerType'], true), '0') ?: '0';
$listStart = \ltrim(\strstr($matches[1], (string) $Block['data']['markerType'], true), '0') ?: '0';
if ($listStart !== '1') {
if (
@@ -576,13 +576,14 @@ class Markdown
protected function blockListContinue($Line, array $Block)
{
$matches = [];
if (isset($Block['interrupted']) && empty($Block['li']['handler']['argument'])) {
return null;
}
$requiredIndent = ($Block['indent'] + \strlen($Block['data']['marker']));
$requiredIndent = ($Block['indent'] + \strlen((string) $Block['data']['marker']));
if ($Line['indent'] < $requiredIndent && ($Block['data']['type'] === 'ol' && \preg_match('/^[0-9]++'.$Block['data']['markerTypeRegex'].'(?:[ ]++(.*)|$)/', $Line['text'], $matches) || $Block['data']['type'] === 'ul' && \preg_match('/^'.$Block['data']['markerTypeRegex'].'(?:[ ]++(.*)|$)/', $Line['text'], $matches))) {
if ($Line['indent'] < $requiredIndent && ($Block['data']['type'] === 'ol' && \preg_match('/^[0-9]++'.$Block['data']['markerTypeRegex'].'(?:[ ]++(.*)|$)/', (string) $Line['text'], $matches) || $Block['data']['type'] === 'ul' && \preg_match('/^'.$Block['data']['markerTypeRegex'].'(?:[ ]++(.*)|$)/', (string) $Line['text'], $matches))) {
if (isset($Block['interrupted'])) {
$Block['li']['handler']['argument'][] = '';
@@ -663,7 +664,7 @@ class Markdown
protected function blockQuote($Line)
{
if (\preg_match('#^>[ ]?+(.*+)#', $Line['text'], $matches)) {
if (\preg_match('#^>[ ]?+(.*+)#', (string) $Line['text'], $matches)) {
return [
'element' => [
'name' => 'blockquote',
@@ -683,7 +684,7 @@ class Markdown
return;
}
if ($Line['text'][0] === '>' && \preg_match('#^>[ ]?+(.*+)#', $Line['text'], $matches)) {
if ($Line['text'][0] === '>' && \preg_match('#^>[ ]?+(.*+)#', (string) $Line['text'], $matches)) {
$Block['element']['handler']['argument'][] = $matches[1];
return $Block;
@@ -737,7 +738,7 @@ class Markdown
return;
}
if (\preg_match('/^<[\/]?+(\w*)(?:[ ]*+'.$this->regexHtmlAttribute.')*+[ ]*+(\/)?>/', $Line['text'], $matches)) {
if (\preg_match('/^<[\/]?+(\w*)(?:[ ]*+'.$this->regexHtmlAttribute.')*+[ ]*+(\/)?>/', (string) $Line['text'], $matches)) {
$element = \strtolower($matches[1]);
if (\in_array($element, $this->textLevelElements)) {
@@ -770,7 +771,7 @@ class Markdown
protected function blockReference($Line)
{
if (\str_contains($Line['text'], ']') && \preg_match('#^\[(.+?)\]:[ ]*+<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*+$#', $Line['text'], $matches)
if (\str_contains((string) $Line['text'], ']') && \preg_match('#^\[(.+?)\]:[ ]*+<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*+$#', (string) $Line['text'], $matches)
) {
$id = \strtolower($matches[1]);
@@ -797,8 +798,8 @@ class Markdown
}
if (
(! \str_contains($Block['element']['handler']['argument'], '|') && ! \str_contains($Line['text'], '|') && ! \str_contains($Line['text'],
':')) || \str_contains($Block['element']['handler']['argument'], "\n")
(! \str_contains((string) $Block['element']['handler']['argument'], '|') && ! \str_contains((string) $Line['text'], '|') && ! \str_contains((string) $Line['text'],
':')) || \str_contains((string) $Block['element']['handler']['argument'], "\n")
) {
return;
}
@@ -908,7 +909,7 @@ class Markdown
return;
}
if (\count($Block['alignments']) === 1 || $Line['text'][0] === '|' || \strpos($Line['text'], '|')) {
if ((is_countable($Block['alignments']) ? \count($Block['alignments']) : 0) === 1 || $Line['text'][0] === '|' || \strpos($Line['text'], '|')) {
$Elements = [];
$row = $Line['text'];
@@ -918,7 +919,7 @@ class Markdown
\preg_match_all('#(?:(\\\[|])|[^|`]|`[^`]++`|`)++#', $row, $matches);
$cells = \array_slice($matches[0], 0, \count($Block['alignments']));
$cells = \array_slice($matches[0], 0, is_countable($Block['alignments']) ? \count($Block['alignments']) : 0);
foreach ($cells as $index => $cell) {
$cell = \trim($cell);
@@ -1029,7 +1030,7 @@ class Markdown
while ($excerpt = \strpbrk($text, $this->inlineMarkerList)) {
$marker = $excerpt[0];
$markerPosition = \strlen($text) - \strlen($excerpt);
$markerPosition = \strlen((string) $text) - \strlen($excerpt);
$Excerpt = ['text' => $excerpt, 'context' => $text];
@@ -1109,7 +1110,7 @@ class Markdown
protected function inlineText($text)
{
$Inline = [
'extent' => \strlen($text),
'extent' => \strlen((string) $text),
'element' => [],
];
@@ -1129,12 +1130,12 @@ class Markdown
{
$marker = $Excerpt['text'][0];
if (\preg_match('/^(['.$marker.']++)[ ]*+(.+?)[ ]*+(?<!['.$marker.'])\1(?!'.$marker.')/s', $Excerpt['text'], $matches)) {
if (\preg_match('/^(['.$marker.']++)[ ]*+(.+?)[ ]*+(?<!['.$marker.'])\1(?!'.$marker.')/s', (string) $Excerpt['text'], $matches)) {
$text = $matches[2];
$text = \preg_replace('#[ ]*+\n#', ' ', $text);
return [
'extent' => \strlen($matches[0]),
'extent' => \strlen((string) $matches[0]),
'element' => [
'name' => 'code',
'text' => $text,
@@ -1150,7 +1151,7 @@ class Markdown
$commonMarkEmail = '[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]++@'
.$hostnameLabel.'(?:\.'.$hostnameLabel.')*';
if (\str_contains($Excerpt['text'], '>') && \preg_match(\sprintf('/^<((mailto:)?%s)>/i', $commonMarkEmail), $Excerpt['text'], $matches)
if (\str_contains((string) $Excerpt['text'], '>') && \preg_match(\sprintf('/^<((mailto:)?%s)>/i', $commonMarkEmail), (string) $Excerpt['text'], $matches)
) {
$url = $matches[1];
@@ -1159,7 +1160,7 @@ class Markdown
}
return [
'extent' => \strlen($matches[0]),
'extent' => \strlen((string) $matches[0]),
'element' => [
'name' => 'a',
'text' => $matches[1],
@@ -1179,16 +1180,16 @@ class Markdown
$marker = $Excerpt['text'][0];
if ($Excerpt['text'][1] === $marker && \preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches)) {
if ($Excerpt['text'][1] === $marker && \preg_match($this->StrongRegex[$marker], (string) $Excerpt['text'], $matches)) {
$emphasis = 'strong';
} elseif (\preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches)) {
} elseif (\preg_match($this->EmRegex[$marker], (string) $Excerpt['text'], $matches)) {
$emphasis = 'em';
} else {
return;
}
return [
'extent' => \strlen($matches[0]),
'extent' => \strlen((string) $matches[0]),
'element' => [
'name' => $emphasis,
'handler' => [
@@ -1263,10 +1264,10 @@ class Markdown
$remainder = $Excerpt['text'];
if (\preg_match('#\[((?:[^][]++|(?R))*+)\]#', $remainder, $matches)) {
if (\preg_match('#\[((?:[^][]++|(?R))*+)\]#', (string) $remainder, $matches)) {
$Element['handler']['argument'] = $matches[1];
$extent += \strlen($matches[0]);
$extent += \strlen((string) $matches[0]);
$remainder = \substr($remainder, $extent);
} else {
@@ -1280,13 +1281,13 @@ class Markdown
$Element['attributes']['title'] = \substr($matches[2], 1, -1);
}
$extent += \strlen($matches[0]);
$extent += \strlen((string) $matches[0]);
} else {
if (\preg_match('#^\s*\[(.*?)\]#', $remainder, $matches)) {
$definition = $matches[1] != '' ? $matches[1] : $Element['handler']['argument'];
$definition = \strtolower($definition);
$extent += \strlen($matches[0]);
$extent += \strlen((string) $matches[0]);
} else {
$definition = \strtolower($Element['handler']['argument']);
}
@@ -1309,39 +1310,39 @@ class Markdown
protected function inlineMarkup($Excerpt)
{
if ($this->markupEscaped || $this->safeMode || ! \str_contains($Excerpt['text'], '>')) {
if ($this->markupEscaped || $this->safeMode || ! \str_contains((string) $Excerpt['text'], '>')) {
return;
}
if ($Excerpt['text'][1] === '/' && \preg_match('#^<\/\w[\w-]*+[ ]*+>#s', $Excerpt['text'], $matches)) {
if ($Excerpt['text'][1] === '/' && \preg_match('#^<\/\w[\w-]*+[ ]*+>#s', (string) $Excerpt['text'], $matches)) {
return [
'element' => ['rawHtml' => $matches[0]],
'extent' => \strlen($matches[0]),
'extent' => \strlen((string) $matches[0]),
];
}
if ($Excerpt['text'][1] === '!' && \preg_match('#^<!---?[^>-](?:-?+[^-])*-->#s', $Excerpt['text'], $matches)) {
if ($Excerpt['text'][1] === '!' && \preg_match('#^<!---?[^>-](?:-?+[^-])*-->#s', (string) $Excerpt['text'], $matches)) {
return [
'element' => ['rawHtml' => $matches[0]],
'extent' => \strlen($matches[0]),
'extent' => \strlen((string) $matches[0]),
];
}
if ($Excerpt['text'][1] !== ' ' && \preg_match('/^<\w[\w-]*+(?:[ ]*+'.$this->regexHtmlAttribute.')*+[ ]*+\/?>/s', $Excerpt['text'], $matches)) {
if ($Excerpt['text'][1] !== ' ' && \preg_match('/^<\w[\w-]*+(?:[ ]*+'.$this->regexHtmlAttribute.')*+[ ]*+\/?>/s', (string) $Excerpt['text'], $matches)) {
return [
'element' => ['rawHtml' => $matches[0]],
'extent' => \strlen($matches[0]),
'extent' => \strlen((string) $matches[0]),
];
}
}
protected function inlineSpecialCharacter($Excerpt)
{
if (\substr($Excerpt['text'], 1, 1) !== ' ' && \str_contains($Excerpt['text'], ';') && \preg_match('/^&(#?+[0-9a-zA-Z]++);/', $Excerpt['text'], $matches)
if (\substr($Excerpt['text'], 1, 1) !== ' ' && \str_contains((string) $Excerpt['text'], ';') && \preg_match('/^&(#?+[0-9a-zA-Z]++);/', (string) $Excerpt['text'], $matches)
) {
return [
'element' => ['rawHtml' => '&'.$matches[1].';'],
'extent' => \strlen($matches[0]),
'extent' => \strlen((string) $matches[0]),
];
}
}
@@ -1352,9 +1353,9 @@ class Markdown
return;
}
if ($Excerpt['text'][1] === '~' && \preg_match('#^~~(?=\S)(.+?)(?<=\S)~~#', $Excerpt['text'], $matches)) {
if ($Excerpt['text'][1] === '~' && \preg_match('#^~~(?=\S)(.+?)(?<=\S)~~#', (string) $Excerpt['text'], $matches)) {
return [
'extent' => \strlen($matches[0]),
'extent' => \strlen((string) $matches[0]),
'element' => [
'name' => 'del',
'handler' => [
@@ -1373,12 +1374,12 @@ class Markdown
return;
}
if (\str_contains($Excerpt['context'], 'http') && \preg_match('#\bhttps?+:[\/]{2}[^\s<]+\b\/*+#ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE)
if (\str_contains((string) $Excerpt['context'], 'http') && \preg_match('#\bhttps?+:[\/]{2}[^\s<]+\b\/*+#ui', (string) $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE)
) {
$url = $matches[0][0];
return [
'extent' => \strlen($matches[0][0]),
'extent' => \strlen((string) $matches[0][0]),
'position' => $matches[0][1],
'element' => [
'name' => 'a',
@@ -1393,11 +1394,11 @@ class Markdown
protected function inlineUrlTag($Excerpt)
{
if (\str_contains($Excerpt['text'], '>') && \preg_match('#^<(\w++:\/{2}[^ >]++)>#i', $Excerpt['text'], $matches)) {
if (\str_contains((string) $Excerpt['text'], '>') && \preg_match('#^<(\w++:\/{2}[^ >]++)>#i', (string) $Excerpt['text'], $matches)) {
$url = $matches[1];
return [
'extent' => \strlen($matches[0]),
'extent' => \strlen((string) $matches[0]),
'element' => [
'name' => 'a',
'text' => $url,
@@ -1617,10 +1618,10 @@ class Markdown
{
$newElements = [];
while (\preg_match($regexp, $text, $matches, PREG_OFFSET_CAPTURE)) {
while (\preg_match($regexp, (string) $text, $matches, PREG_OFFSET_CAPTURE)) {
$offset = $matches[0][1];
$before = \substr($text, 0, $offset);
$after = \substr($text, $offset + \strlen($matches[0][0]));
$after = \substr($text, $offset + \strlen((string) $matches[0][0]));
$newElements[] = ['text' => $before];
@@ -1666,7 +1667,7 @@ class Markdown
if (! empty($Element['attributes'])) {
foreach (\array_keys($Element['attributes']) as $att) {
// filter out badly parsed attribute
if (! \preg_match($goodAttribute, $att)) {
if (! \preg_match($goodAttribute, (string) $att)) {
unset($Element['attributes'][$att]);
}
// dump onevent attribute
@@ -1703,9 +1704,9 @@ class Markdown
protected static function striAtStart($string, $needle)
{
$len = \strlen($needle);
$len = \strlen((string) $needle);
if ($len > \strlen($string)) {
if ($len > \strlen((string) $string)) {
return false;
}
@@ -1725,7 +1726,7 @@ class Markdown
return $static;
}
private static $instances = [];
private static array $instances = [];
//
// Fields
+21 -27
View File
@@ -65,7 +65,7 @@ class MarkdownExtra extends Markdown
protected function blockAbbreviation($Line)
{
if (\preg_match('#^\*\[(.+?)\]:[ ]*(.+?)[ ]*$#', $Line['text'], $matches)) {
if (\preg_match('#^\*\[(.+?)\]:[ ]*(.+?)[ ]*$#', (string) $Line['text'], $matches)) {
$this->DefinitionData['Abbreviation'][$matches[1]] = $matches[2];
return [
@@ -79,7 +79,7 @@ class MarkdownExtra extends Markdown
protected function blockFootnote($Line)
{
if (\preg_match('#^\[\^(.+?)\]:[ ]?(.*)$#', $Line['text'], $matches)) {
if (\preg_match('#^\[\^(.+?)\]:[ ]?(.*)$#', (string) $Line['text'], $matches)) {
return [
'label' => $matches[1],
'text' => $matches[2],
@@ -90,7 +90,7 @@ class MarkdownExtra extends Markdown
protected function blockFootnoteContinue($Line, $Block)
{
if ($Line['text'][0] === '[' && \preg_match('#^\[\^(.+?)\]:#', $Line['text'])) {
if ($Line['text'][0] === '[' && \preg_match('#^\[\^(.+?)\]:#', (string) $Line['text'])) {
return;
}
@@ -132,7 +132,7 @@ class MarkdownExtra extends Markdown
'elements' => [],
];
$terms = \explode("\n", $Block['element']['handler']['argument']);
$terms = \explode("\n", (string) $Block['element']['handler']['argument']);
foreach ($terms as $term) {
$Element['elements'][] = [
@@ -183,7 +183,7 @@ class MarkdownExtra extends Markdown
{
$Block = parent::blockHeader($Line);
if ($Block !== null && \preg_match('/[ #]*{('.$this->regexAttribute.'+)}[ ]*$/', $Block['element']['handler']['argument'], $matches, PREG_OFFSET_CAPTURE)) {
if ($Block !== null && \preg_match('/[ #]*{('.$this->regexAttribute.'+)}[ ]*$/', (string) $Block['element']['handler']['argument'], $matches, PREG_OFFSET_CAPTURE)) {
$attributeString = $matches[1][0];
$Block['element']['attributes'] = $this->parseAttributeData($attributeString);
@@ -203,7 +203,7 @@ class MarkdownExtra extends Markdown
return;
}
if (\preg_match('/^<(\w[\w-]*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches)) {
if (\preg_match('/^<(\w[\w-]*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', (string) $Line['text'], $matches)) {
$element = \strtolower($matches[1]);
if (\in_array($element, $this->textLevelElements)) {
@@ -219,7 +219,7 @@ class MarkdownExtra extends Markdown
],
];
$length = \strlen($matches[0]);
$length = \strlen((string) $matches[0]);
$remainder = \substr($Line['text'], $length);
if (\trim($remainder) === '') {
@@ -247,11 +247,11 @@ class MarkdownExtra extends Markdown
return;
}
if (\preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) { // open
if (\preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', (string) $Line['text'])) { // open
$Block['depth']++;
}
if (\preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) { // close
if (\preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', (string) $Line['text'], $matches)) { // close
if ($Block['depth'] > 0) {
$Block['depth']--;
} else {
@@ -285,7 +285,7 @@ class MarkdownExtra extends Markdown
{
$Block = parent::blockSetextHeader($Line, $Block);
if ($Block !== null && \preg_match('/[ ]*{('.$this->regexAttribute.'+)}[ ]*$/', $Block['element']['handler']['argument'], $matches, PREG_OFFSET_CAPTURE)) {
if ($Block !== null && \preg_match('/[ ]*{('.$this->regexAttribute.'+)}[ ]*$/', (string) $Block['element']['handler']['argument'], $matches, PREG_OFFSET_CAPTURE)) {
$attributeString = $matches[1][0];
$Block['element']['attributes'] = $this->parseAttributeData($attributeString);
@@ -305,7 +305,7 @@ class MarkdownExtra extends Markdown
protected function inlineFootnoteMarker($Excerpt)
{
if (\preg_match('#^\[\^(.+?)\]#', $Excerpt['text'], $matches)) {
if (\preg_match('#^\[\^(.+?)\]#', (string) $Excerpt['text'], $matches)) {
$name = $matches[1];
if (! isset($this->DefinitionData['Footnote'][$name])) {
@@ -329,13 +329,13 @@ class MarkdownExtra extends Markdown
];
return [
'extent' => \strlen($matches[0]),
'extent' => \strlen((string) $matches[0]),
'element' => $Element,
];
}
}
private $footnoteCount = 0;
private int $footnoteCount = 0;
//
// Link
@@ -349,7 +349,7 @@ class MarkdownExtra extends Markdown
if (\preg_match('/^[ ]*{('.$this->regexAttribute.'+)}/', $remainder, $matches)) {
$Link['element']['attributes'] += $this->parseAttributeData($matches[1]);
$Link['extent'] += \strlen($matches[0]);
$Link['extent'] += \strlen((string) $matches[0]);
}
return $Link;
@@ -482,27 +482,21 @@ class MarkdownExtra extends Markdown
unset($backLinkElements[0]);
$n = \count($textElements) - 1;
$n = (is_countable($textElements) ? \count($textElements) : 0) - 1;
if ($textElements[$n]['name'] === 'p') {
$backLinkElements = \array_merge(
$backLinkElements = [...[
[
[
'rawHtml' => '&#160;',
'allowRawHtmlInSafeMode' => true,
],
'rawHtml' => '&#160;',
'allowRawHtmlInSafeMode' => true,
],
$backLinkElements
);
], ...$backLinkElements];
unset($textElements[$n]['name']);
$textElements[$n] = [
'name' => 'p',
'elements' => \array_merge(
[$textElements[$n]],
$backLinkElements
),
'elements' => [...[$textElements[$n]], ...$backLinkElements],
];
} else {
$textElements[] = [
@@ -529,7 +523,7 @@ class MarkdownExtra extends Markdown
{
$Data = [];
$attributes = \preg_split('#[ ]+#', $attributeString, -1, PREG_SPLIT_NO_EMPTY);
$attributes = \preg_split('#[ ]+#', (string) $attributeString, -1, PREG_SPLIT_NO_EMPTY);
foreach ($attributes as $attribute) {
if ($attribute[0] === '#') {
+6 -6
View File
@@ -15,15 +15,15 @@ namespace App\Helpers;
class StringHelper
{
public const KIB = 1_024;
public final const KIB = 1_024;
public const MIB = 1_024 * 1_024;
public final const MIB = 1_024 * 1_024;
public const GIB = 1_024 * 1_024 * 1_024;
public final const GIB = 1_024 * 1_024 * 1_024;
public const TIB = 1_024 * 1_024 * 1_024 * 1_024;
public final const TIB = 1_024 * 1_024 * 1_024 * 1_024;
public const PIB = 1_024 * 1_024 * 1_024 * 1_024 * 1_024;
public final const PIB = 1_024 * 1_024 * 1_024 * 1_024 * 1_024;
/**
* @var string
@@ -39,7 +39,7 @@ class StringHelper
{
$string = '';
for ($i = 0; $i < $length; $i++) {
$string .= self::CHARACTERS[\rand(0, \strlen(self::CHARACTERS) - 1)];
$string .= self::CHARACTERS[random_int(0, \strlen(self::CHARACTERS) - 1)];
}
return $string;
+2 -2
View File
@@ -44,9 +44,9 @@ class SystemInformation
{
if (\is_readable('/proc/meminfo')) {
$content = \file_get_contents('/proc/meminfo');
\preg_match('#^MemTotal: \s*(\d*)#m', $content, $matches);
\preg_match('#^MemTotal: \s*(\d*)#m', (string) $content, $matches);
$total = $matches[1] * 1_024;
\preg_match('#^MemFree: \s*(\d*)#m', $content, $matches);
\preg_match('#^MemFree: \s*(\d*)#m', (string) $content, $matches);
$free = $matches[1] * 1_024;
//preg_match('/^MemAvailable: \s*(\d*)/m', $content, $matches);
//$used = $this->formatBytes($matches[1] * 1024);
+5 -4
View File
@@ -98,6 +98,7 @@ class TorrentTools
*/
public static function getTorrentFiles($decodedTorrent): array
{
$files = [];
if (\array_key_exists('files', $decodedTorrent['info']) && (\is_countable($decodedTorrent['info']['files']) ? \count($decodedTorrent['info']['files']) : 0)) {
foreach ($decodedTorrent['info']['files'] as $k => $file) {
$dir = '';
@@ -188,10 +189,10 @@ class TorrentTools
public static function isValidFilename($filename): bool
{
$result = true;
if (\strlen($filename) > 255 ||
\preg_match('#[/?<>\\:*|"\x00-\x1f]#', $filename) ||
\preg_match('#(^\.+|[\. ]+)$#', $filename) ||
\preg_match('#^(con|prn|aux|nul|com\d|lpt\d)(\..*)?$#i', $filename)) {
if (\strlen((string) $filename) > 255 ||
\preg_match('#[/?<>\\:*|"\x00-\x1f]#', (string) $filename) ||
\preg_match('#(^\.+|[\. ]+)$#', (string) $filename) ||
\preg_match('#^(con|prn|aux|nul|com\d|lpt\d)(\..*)?$#i', (string) $filename)) {
$result = false;
}