diff --git a/src/Components/Inlines/Emphasis.php b/src/Components/Inlines/Emphasis.php index c98d89e..08bae6f 100644 --- a/src/Components/Inlines/Emphasis.php +++ b/src/Components/Inlines/Emphasis.php @@ -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; diff --git a/src/Configurables/BlockTypes.php b/src/Configurables/BlockTypes.php index c7a770f..694fc46 100644 --- a/src/Configurables/BlockTypes.php +++ b/src/Configurables/BlockTypes.php @@ -17,8 +17,7 @@ use Erusev\Parsedown\Configurable; final class BlockTypes implements Configurable { - /** @var array>> */ - 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> */ - 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 ); } diff --git a/src/Configurables/InlineTypes.php b/src/Configurables/InlineTypes.php index d8b09fb..8a61169 100644 --- a/src/Configurables/InlineTypes.php +++ b/src/Configurables/InlineTypes.php @@ -20,8 +20,7 @@ use Erusev\Parsedown\Configurable; final class InlineTypes implements Configurable { - /** @var array>> */ - 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); } /** diff --git a/src/Html/Renderables/Element.php b/src/Html/Renderables/Element.php index 627adb1..14ef739 100644 --- a/src/Html/Renderables/Element.php +++ b/src/Html/Renderables/Element.php @@ -10,8 +10,7 @@ final class Element implements Renderable { use CanonicalStateRenderable; - /** @var array */ - 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"; } diff --git a/src/Html/Sanitisation/UrlSanitiser.php b/src/Html/Sanitisation/UrlSanitiser.php index daefc70..47571a8 100644 --- a/src/Html/Sanitisation/UrlSanitiser.php +++ b/src/Html/Sanitisation/UrlSanitiser.php @@ -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) { diff --git a/tests/CommonMarkTestWeak.php b/tests/CommonMarkTestWeak.php index 22a4470..c4dc857 100644 --- a/tests/CommonMarkTestWeak.php +++ b/tests/CommonMarkTestWeak.php @@ -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,