From 7398fd13af2a0d1f36eb2d657a3eb67237a75532 Mon Sep 17 00:00:00 2001 From: Tac Tacelosky Date: Sun, 7 Nov 2021 07:46:59 -0500 Subject: [PATCH 1/3] type arrays for class and subclass --- Michelf/Markdown.php | 6 +++--- Michelf/MarkdownExtra.php | 6 +++--- composer.json | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index 61778ba..22b1438 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -1248,7 +1248,7 @@ protected function makeCodeSpan($code) { * Define the emphasis operators with their regex matches * @var array */ - protected $em_relist = array( + protected array $em_relist = array( '' => '(?:(? '(? '(? '(?:(? '(? '(? '(?:(? '(? '(? '(?:(? '(? '(? '(?:(? '(? '(? '(?:(? '(? '(?= 9.5" + "phpunit/phpunit": ">= 9.5", + "rector/rector": "^0.11.60" } } From f8590729636c9d9a228a8734923fcc5078e3e657 Mon Sep 17 00:00:00 2001 From: Tac Tacelosky Date: Sun, 7 Nov 2021 07:57:10 -0500 Subject: [PATCH 2/3] remove rector --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 73fc79e..9990ce1 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,6 @@ "psr-4": { "Michelf\\": "Michelf/" } }, "require-dev": { - "phpunit/phpunit": ">= 9.5", - "rector/rector": "^0.11.60" + "phpunit/phpunit": ">= 9.5" } } From 814ea61f11f538dfd48132ee90d98edda77f44a2 Mon Sep 17 00:00:00 2001 From: Tac Tacelosky Date: Sun, 7 Nov 2021 07:57:49 -0500 Subject: [PATCH 3/3] declare types in php rather than annotations --- Michelf/Markdown.php | 64 ++++++++++------------------ Michelf/MarkdownExtra.php | 88 ++++++++++++++------------------------- 2 files changed, 53 insertions(+), 99 deletions(-) diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index 22b1438..b1ebee1 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -31,7 +31,7 @@ class Markdown implements MarkdownInterface { */ public static function defaultTransform($text) { // Take parser class on which this function was called. - $parser_class = \get_called_class(); + $parser_class = static::class; // Try to take parser from the static parser list static $parser_list; @@ -49,25 +49,21 @@ public static function defaultTransform($text) { /** * Configuration variables */ - /** * Change to ">" for HTML output. - * @var string */ - public $empty_element_suffix = " />"; + public string $empty_element_suffix = " />"; /** * The width of indentation of the output markup - * @var int */ - public $tab_width = 4; + public int $tab_width = 4; /** * Change to `true` to disallow markup or entities. - * @var boolean */ - public $no_markup = false; - public $no_entities = false; + public bool $no_markup = false; + public bool $no_entities = false; /** @@ -78,10 +74,9 @@ public static function defaultTransform($text) { /** * Predefined URLs and titles for reference links and images. - * @var array */ - public $predef_urls = array(); - public $predef_titles = array(); + public array $predef_urls = array(); + public array $predef_titles = array(); /** * Optional filter function for URLs @@ -121,32 +116,27 @@ public static function defaultTransform($text) { *
  • List item two
  • *
  • List item three
  • * - * - * @var bool */ - public $enhanced_ordered_list = false; + public bool $enhanced_ordered_list = false; /** * Parser implementation */ - /** * Regex to match balanced [brackets]. * Needed to insert a maximum bracked depth while converting to PHP. - * @var int */ - protected $nested_brackets_depth = 6; + protected int $nested_brackets_depth = 6; protected $nested_brackets_re; - protected $nested_url_parenthesis_depth = 4; + protected int $nested_url_parenthesis_depth = 4; protected $nested_url_parenthesis_re; /** * Table of hash values for escaped characters: - * @var string */ - protected $escape_chars = '\`*_{}[]()>#+-.!'; - protected $escape_chars_re; + protected string $escape_chars = '\`*_{}[]()>#+-.!'; + protected string $escape_chars_re; /** * Constructor function. Initialize appropriate member variables. @@ -175,23 +165,20 @@ public function __construct() { /** * Internal hashes used during transformation. - * @var array */ - protected $urls = array(); + protected array $urls = array(); protected $titles = array(); - protected $html_hashes = array(); + protected array $html_hashes = array(); /** * Status flag to avoid invalid nesting. - * @var boolean */ - protected $in_anchor = false; + protected bool $in_anchor = false; /** * Status flag to avoid invalid nesting. - * @var boolean */ - protected $in_emphasis_processing = false; + protected bool $in_emphasis_processing = false; /** * Called before the transformation process starts to setup parser states. @@ -263,9 +250,8 @@ public function transform($text) { /** * Define the document gamut - * @var array */ - protected $document_gamut = array( + protected array $document_gamut = array( // Strip link definitions, store in hashes. "stripLinkDefinitions" => 20, "runBasicBlockGamut" => 30, @@ -525,9 +511,8 @@ protected function hashBlock($text) { /** * Define the block gamut - these are all the transformations that form * block-level tags like paragraphs, headers, and list items. - * @var array */ - protected $block_gamut = array( + protected array $block_gamut = array( "doHeaders" => 10, "doHorizontalRules" => 20, "doLists" => 40, @@ -597,9 +582,8 @@ protected function doHorizontalRules($text) { /** * These are all the transformations that occur *within* block-level * tags like paragraphs, headers, and list items. - * @var array */ - protected $span_gamut = array( + protected array $span_gamut = array( // Process character escapes, code spans, and inline HTML // in one shot. "parseSpan" => -30, @@ -1105,9 +1089,8 @@ protected function _doLists_callback($matches) { /** * Nesting tracker for list levels - * @var integer */ - protected $list_level = 0; + protected int $list_level = 0; /** * Process the contents of a single ordered or unordered list, splitting it @@ -1276,9 +1259,8 @@ protected function makeCodeSpan($code) { /** * Container for prepared regular expressions - * @var array */ - protected $em_strong_prepared_relist; + protected ?array $em_strong_prepared_relist = null; /** * Prepare regular expressions for searching emphasis tokens in any @@ -1883,9 +1865,7 @@ protected function _initDetab() { return; } - $this->utf8_strlen = function($text) { - return preg_match_all('/[\x00-\xBF]|[\xC0-\xFF][\x80-\xBF]*/', $text, $m); - }; + $this->utf8_strlen = fn($text) => preg_match_all('/[\x00-\xBF]|[\xC0-\xFF][\x80-\xBF]*/', $text, $m); } /** diff --git a/Michelf/MarkdownExtra.php b/Michelf/MarkdownExtra.php index 2bf1865..8485c5c 100644 --- a/Michelf/MarkdownExtra.php +++ b/Michelf/MarkdownExtra.php @@ -17,25 +17,21 @@ class MarkdownExtra extends \Michelf\Markdown { /** * Configuration variables */ - /** * Prefix for footnote ids. - * @var string */ - public $fn_id_prefix = ""; + public string $fn_id_prefix = ""; /** * Optional title attribute for footnote links. - * @var string */ - public $fn_link_title = ""; + public string $fn_link_title = ""; /** * Optional class attribute for footnote links and backlinks. - * @var string */ - public $fn_link_class = "footnote-ref"; - public $fn_backlink_class = "footnote-backref"; + public string $fn_link_class = "footnote-ref"; + public string $fn_backlink_class = "footnote-backref"; /** * Content to be displayed within footnote backlinks. The default is '↩'; @@ -43,59 +39,51 @@ class MarkdownExtra extends \Michelf\Markdown { * from displaying the arrow character as an emoji. * Optionally use '^^' and '%%' to refer to the footnote number and * reference number respectively. {@see parseFootnotePlaceholders()} - * @var string */ - public $fn_backlink_html = '↩︎'; + public string $fn_backlink_html = '↩︎'; /** * Optional title and aria-label attributes for footnote backlinks for * added accessibility (to ensure backlink uniqueness). * Use '^^' and '%%' to refer to the footnote number and reference number * respectively. {@see parseFootnotePlaceholders()} - * @var string */ - public $fn_backlink_title = ""; - public $fn_backlink_label = ""; + public string $fn_backlink_title = ""; + public string $fn_backlink_label = ""; /** * Class name for table cell alignment (%% replaced left/center/right) * For instance: 'go-%%' becomes 'go-left' or 'go-right' or 'go-center' * If empty, the align attribute is used instead of a class name. - * @var string */ - public $table_align_class_tmpl = ''; + public string $table_align_class_tmpl = ''; /** * Optional class prefix for fenced code block. - * @var string */ - public $code_class_prefix = ""; + public string $code_class_prefix = ""; /** * Class attribute for code blocks goes on the `code` tag; * setting this to true will put attributes on the `pre` tag instead. - * @var boolean */ - public $code_attr_on_pre = false; + public bool $code_attr_on_pre = false; /** * Predefined abbreviations. - * @var array */ - public $predef_abbr = array(); + public array $predef_abbr = array(); /** * Only convert atx-style headers if there's a space between the header and # - * @var boolean */ - public $hashtag_protection = false; + public bool $hashtag_protection = false; /** * Determines whether footnotes should be appended to the end of the document. * If true, footnote html can be retrieved from $this->footnotes_assembled. - * @var boolean */ - public $omit_footnotes = false; + public bool $omit_footnotes = false; /** @@ -107,9 +95,8 @@ class MarkdownExtra extends \Michelf\Markdown { * `section` that will enclose the list of footnotes so they are * reachable to accessibility tools the same way they would be with the * default HTML output. - * @var null|string */ - public $footnotes_assembled = null; + public ?string $footnotes_assembled = null; /** * Parser implementation @@ -149,27 +136,23 @@ public function __construct() { /** * Extra variables used during extra transformations. - * @var array */ - protected $footnotes = array(); - protected $footnotes_ordered = array(); - protected $footnotes_ref_count = array(); - protected $footnotes_numbers = array(); - protected $abbr_desciptions = array(); - /** @var string */ - protected $abbr_word_re = ''; + protected array $footnotes = array(); + protected array $footnotes_ordered = array(); + protected array $footnotes_ref_count = array(); + protected array $footnotes_numbers = array(); + protected array $abbr_desciptions = array(); + protected string $abbr_word_re = ''; /** * Give the current footnote number. - * @var integer */ - protected $footnote_counter = 1; + protected int $footnote_counter = 1; /** - * Ref attribute for links - * @var array - */ - protected $ref_attr = array(); + * Ref attribute for links + */ + protected array $ref_attr = array(); /** * Setting up Extra-specific variables. @@ -215,18 +198,15 @@ protected function teardown() { /** * Extra attribute parser */ - /** * Expression to use to catch attributes (includes the braces) - * @var string */ - protected $id_class_attr_catch_re = '\{((?>[ ]*[#.a-z][-_:a-zA-Z0-9=]+){1,})[ ]*\}'; + protected string $id_class_attr_catch_re = '\{((?>[ ]*[#.a-z][-_:a-zA-Z0-9=]+){1,})[ ]*\}'; /** * Expression to use when parsing in a context when no capture is desired - * @var string */ - protected $id_class_attr_nocatch_re = '\{(?>[ ]*[#.a-z][-_:a-zA-Z0-9=]+){1,}[ ]*\}'; + protected string $id_class_attr_nocatch_re = '\{(?>[ ]*[#.a-z][-_:a-zA-Z0-9=]+){1,}[ ]*\}'; /** * Parse attributes caught by the $this->id_class_attr_catch_re expression @@ -340,37 +320,31 @@ protected function _stripLinkDefinitions_callback($matches) { /** * HTML block parser */ - /** * Tags that are always treated as block tags - * @var string */ - protected $block_tags_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend|article|section|nav|aside|hgroup|header|footer|figcaption|figure|details|summary'; + protected string $block_tags_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend|article|section|nav|aside|hgroup|header|footer|figcaption|figure|details|summary'; /** * Tags treated as block tags only if the opening tag is alone on its line - * @var string */ - protected $context_block_tags_re = 'script|noscript|style|ins|del|iframe|object|source|track|param|math|svg|canvas|audio|video'; + protected string $context_block_tags_re = 'script|noscript|style|ins|del|iframe|object|source|track|param|math|svg|canvas|audio|video'; /** * Tags where markdown="1" default to span mode: - * @var string */ - protected $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address'; + protected string $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address'; /** * Tags which must not have their contents modified, no matter where * they appear - * @var string */ - protected $clean_tags_re = 'script|style|math|svg'; + protected string $clean_tags_re = 'script|style|math|svg'; /** * Tags that do not need to be closed. - * @var string */ - protected $auto_close_tags_re = 'hr|img|param|source|track'; + protected string $auto_close_tags_re = 'hr|img|param|source|track'; /** * Hashify HTML Blocks and "clean tags".