mirror of
https://github.com/erusev/parsedown.git
synced 2024-09-20 03:51:29 +02:00
Utilise constant arrays over static vars
This commit is contained in:
parent
ea55a9ffb0
commit
37f306c3a8
@ -21,14 +21,12 @@ final class Emphasis implements Inline
|
||||
/** @var 'em'|'strong' */
|
||||
private $type;
|
||||
|
||||
/** @var array{*: string, _: string} */
|
||||
private static $STRONG_REGEX = [
|
||||
private const STRONG_REGEX = [
|
||||
'*' => '/^[*]{2}((?:\\\\\*|[^*]|[*][^*]*+[*])+?)[*]{2}(?![*])/s',
|
||||
'_' => '/^__((?:\\\\_|[^_]|_[^_]*+_)+?)__(?!_)/us',
|
||||
];
|
||||
|
||||
/** @var array{*: string, _: string} */
|
||||
private static $EM_REGEX = [
|
||||
private const EM_REGEX = [
|
||||
'*' => '/^[*]((?:\\\\\*|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s',
|
||||
'_' => '/^_((?:\\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us',
|
||||
];
|
||||
@ -58,9 +56,9 @@ final class Emphasis implements Inline
|
||||
return null;
|
||||
}
|
||||
|
||||
if (\preg_match(self::$STRONG_REGEX[$marker], $Excerpt->text(), $matches)) {
|
||||
if (\preg_match(self::STRONG_REGEX[$marker], $Excerpt->text(), $matches)) {
|
||||
$emphasis = 'strong';
|
||||
} elseif (\preg_match(self::$EM_REGEX[$marker], $Excerpt->text(), $matches)) {
|
||||
} elseif (\preg_match(self::EM_REGEX[$marker], $Excerpt->text(), $matches)) {
|
||||
$emphasis = 'em';
|
||||
} else {
|
||||
return null;
|
||||
|
@ -17,8 +17,7 @@ use Erusev\Parsedown\Configurable;
|
||||
|
||||
final class BlockTypes implements Configurable
|
||||
{
|
||||
/** @var array<array-key, array<int, class-string<Block>>> */
|
||||
private static $defaultBlockTypes = [
|
||||
private const DEFAULT_BLOCK_TYPES = [
|
||||
'#' => [Header::class],
|
||||
'*' => [Rule::class, TList::class],
|
||||
'+' => [TList::class],
|
||||
@ -44,8 +43,7 @@ final class BlockTypes implements Configurable
|
||||
'~' => [FencedCode::class],
|
||||
];
|
||||
|
||||
/** @var array<int, class-string<Block>> */
|
||||
private static $defaultUnmarkedBlockTypes = [
|
||||
private const DEFAULT_UNMARKED_BLOCK_TYPES = [
|
||||
IndentedCode::class,
|
||||
];
|
||||
|
||||
@ -69,8 +67,8 @@ final class BlockTypes implements Configurable
|
||||
public static function initial()
|
||||
{
|
||||
return new self(
|
||||
self::$defaultBlockTypes,
|
||||
self::$defaultUnmarkedBlockTypes
|
||||
self::DEFAULT_BLOCK_TYPES,
|
||||
self::DEFAULT_UNMARKED_BLOCK_TYPES
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,7 @@ use Erusev\Parsedown\Configurable;
|
||||
|
||||
final class InlineTypes implements Configurable
|
||||
{
|
||||
/** @var array<array-key, array<int, class-string<Inline>>> */
|
||||
private static $defaultInlineTypes = [
|
||||
private const DEFAULT_INLINE_TYPES = [
|
||||
'!' => [Image::class],
|
||||
'*' => [Emphasis::class],
|
||||
'_' => [Emphasis::class],
|
||||
@ -53,7 +52,7 @@ final class InlineTypes implements Configurable
|
||||
/** @return self */
|
||||
public static function initial()
|
||||
{
|
||||
return new self(self::$defaultInlineTypes);
|
||||
return new self(self::DEFAULT_INLINE_TYPES);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,8 +10,7 @@ final class Element implements Renderable
|
||||
{
|
||||
use CanonicalStateRenderable;
|
||||
|
||||
/** @var array<string, true> */
|
||||
public static $TEXT_LEVEL_ELEMENTS = [
|
||||
const TEXT_LEVEL_ELEMENTS = [
|
||||
'a' => true,
|
||||
'b' => true,
|
||||
'i' => true,
|
||||
@ -167,7 +166,7 @@ final class Element implements Renderable
|
||||
foreach ($this->Contents as $C) {
|
||||
if (
|
||||
$C instanceof Element
|
||||
&& ! \array_key_exists(\strtolower($C->name()), self::$TEXT_LEVEL_ELEMENTS)
|
||||
&& ! \array_key_exists(\strtolower($C->name()), self::TEXT_LEVEL_ELEMENTS)
|
||||
) {
|
||||
$html .= "\n";
|
||||
}
|
||||
@ -179,7 +178,7 @@ final class Element implements Renderable
|
||||
|
||||
if (
|
||||
$Last instanceof Element
|
||||
&& ! \array_key_exists(\strtolower($Last->name()), self::$TEXT_LEVEL_ELEMENTS)
|
||||
&& ! \array_key_exists(\strtolower($Last->name()), self::TEXT_LEVEL_ELEMENTS)
|
||||
) {
|
||||
$html .= "\n";
|
||||
}
|
||||
|
@ -4,8 +4,7 @@ namespace Erusev\Parsedown\Html\Sanitisation;
|
||||
|
||||
final class UrlSanitiser
|
||||
{
|
||||
/** @var string[] */
|
||||
private static $COMMON_SCHEMES = [
|
||||
private const COMMON_SCHEMES = [
|
||||
'http://',
|
||||
'https://',
|
||||
'ftp://',
|
||||
@ -33,7 +32,7 @@ final class UrlSanitiser
|
||||
public static function filter($url, $permittedSchemes = null)
|
||||
{
|
||||
if (! isset($permittedSchemes)) {
|
||||
$permittedSchemes = self::$COMMON_SCHEMES;
|
||||
$permittedSchemes = self::COMMON_SCHEMES;
|
||||
}
|
||||
|
||||
foreach ($permittedSchemes as $scheme) {
|
||||
|
@ -28,7 +28,7 @@ class CommonMarkTestWeak extends CommonMarkTestStrict
|
||||
*/
|
||||
public function __construct($name = null, array $data = [], $dataName = '')
|
||||
{
|
||||
$textLevelElements = \array_keys(Element::$TEXT_LEVEL_ELEMENTS);
|
||||
$textLevelElements = \array_keys(Element::TEXT_LEVEL_ELEMENTS);
|
||||
|
||||
\array_walk(
|
||||
$textLevelElements,
|
||||
|
Loading…
Reference in New Issue
Block a user