From e736da4fedfb23da3e78482e7f6832562f3e1bff Mon Sep 17 00:00:00 2001 From: Jitendra Adhikari Date: Tue, 24 Oct 2017 17:44:09 +0000 Subject: [PATCH 1/2] Apply fixes from StyleCI --- examples/example.php | 14 ++++++------ src/HtmlUp.php | 42 +++++++++++++++++----------------- tests/bootstrap.php | 10 ++++---- tests/src/HtmlUpTest.php | 49 ++++++++++++++++++++-------------------- 4 files changed, 57 insertions(+), 58 deletions(-) diff --git a/examples/example.php b/examples/example.php index 2836843..71c13bf 100644 --- a/examples/example.php +++ b/examples/example.php @@ -2,19 +2,19 @@ use Ahc\HtmlUp; -require dirname(__DIR__).'/vendor/autoload.php'; +require dirname(__DIR__) . '/vendor/autoload.php'; -$markdown = file_get_contents(dirname(__DIR__).'/readme.md'); +$markdown = file_get_contents(dirname(__DIR__) . '/readme.md'); /* You can use any of the three usage methods below */ -# usage 1 +// usage 1 // $h = new HtmlUp($markdown); -// echo $h->parse(); +// echo $h->parse(); -# usage 2 +// usage 2 // $h = new HtmlUp($markdown); -// echo $h; +// echo $h; -# usage 3 +// usage 3 echo new HtmlUp($markdown); diff --git a/src/HtmlUp.php b/src/HtmlUp.php index f62bb98..758205e 100644 --- a/src/HtmlUp.php +++ b/src/HtmlUp.php @@ -23,10 +23,10 @@ public function __construct($markdown) { // some normalisations $this->Lines = - explode("\n", # the lines ! - trim( # trim trailing \n - str_replace(array("\r\n", "\r"), "\n", # use standard newline - str_replace("\t", ' ', $markdown) # use 4 spaces for tab + explode("\n", // the lines ! + trim( // trim trailing \n + str_replace(["\r\n", "\r"], "\n", // use standard newline + str_replace("\t", ' ', $markdown) // use 4 spaces for tab ), "\n" ) ); @@ -51,14 +51,14 @@ public function parse() return ''; } - $markup = ''; - $nestLevel = $quoteLevel = 0; - $indent = $nextIndent = 0; - $stackList = $stackBlock = $stackTable = array(); + $markup = ''; + $nestLevel = $quoteLevel = 0; + $indent = $nextIndent = 0; + $stackList = $stackBlock = $stackTable = []; $lastPointer = count($this->Lines) - 1; while (isset($this->Lines[++$this->Pointer])) { - $line = $this->Lines[$this->Pointer]; + $line = $this->Lines[$this->Pointer]; $trimmedLine = trim($line); // flush stacks at the end of block @@ -75,7 +75,7 @@ public function parse() $markup .= "\n"; - $inList = $inQuote = $inPara = $inHtml = null; + $inList = $inQuote = $inPara = $inHtml = null; $nestLevel = $quoteLevel = 0; continue; } @@ -86,7 +86,7 @@ public function parse() ) { $markup .= "\n$line"; if (empty($inHtml) and - empty($this->Lines[$this->Pointer-1]) + empty($this->Lines[$this->Pointer - 1]) ) { $inHtml = true; } @@ -98,15 +98,15 @@ public function parse() : null; $trimmedNextLine = $nextLine ? trim($nextLine) : null; - $indent = strlen($line) - strlen(ltrim($line)); + $indent = strlen($line) - strlen(ltrim($line)); $nextIndent = $nextLine ? strlen($nextLine) - strlen(ltrim($nextLine)) : 0; - $nextMark1 = isset($trimmedNextLine[0]) ? $trimmedNextLine[0] : null; + $nextMark1 = isset($trimmedNextLine[0]) ? $trimmedNextLine[0] : null; $nextMark12 = $trimmedNextLine ? substr($trimmedNextLine, 0, 2) : null; // blockquote if (preg_match('~^\s*(>+)\s+~', $line, $quoteMatch)) { - $line = substr($line, strlen($quoteMatch[0])); + $line = substr($line, strlen($quoteMatch[0])); $trimmedLine = trim($line); if (empty($inQuote) or $quoteLevel < strlen($quoteMatch[1])) { $markup .= "\n
"; @@ -116,14 +116,14 @@ public function parse() $inQuote = true; } - $mark1 = $trimmedLine[0]; + $mark1 = $trimmedLine[0]; $mark12 = substr($trimmedLine, 0, 2); // atx if ($mark1 === '#') { $level = strlen($trimmedLine) - strlen(ltrim($trimmedLine, '#')); if ($level < 7) { - $markup .= "\n".ltrim($trimmedLine, '# ').""; + $markup .= "\n" . ltrim($trimmedLine, '# ') . ""; continue; } } @@ -152,7 +152,7 @@ public function parse() (($line = htmlspecialchars($this->Lines[$this->Pointer + 1])) or true) and (($codeBlock and substr(ltrim($line), 0, 3) !== '```') or substr($line, 0, 4) === ' ') ) { - $markup .= "\n"; # @todo: donot use \n for first line + $markup .= "\n"; // @todo: donot use \n for first line $markup .= $codeBlock ? $line : substr($line, 4); ++$this->Pointer; } @@ -171,7 +171,7 @@ public function parse() } // list - if ($ul = in_array($mark12, array('- ', '* ', '+ ')) or + if ($ul = in_array($mark12, ['- ', '* ', '+ ']) or preg_match('/^\d+\. /', $trimmedLine) ) { $wrapper = $ul ? 'ul' : 'ol'; @@ -182,9 +182,9 @@ public function parse() ++$nestLevel; } - $markup .= '
  • '.ltrim($trimmedLine, '-*0123456789. '); + $markup .= '
  • ' . ltrim($trimmedLine, '-*0123456789. '); - if ($ul = in_array($nextMark12, array('- ', '* ', '+ ')) or + if ($ul = in_array($nextMark12, ['- ', '* ', '+ ']) or preg_match('/^\d+\. /', $trimmedNextLine) ) { $wrapper = $ul ? 'ul' : 'ol'; @@ -249,7 +249,7 @@ public function parse() if (empty($trimmedNextLine) or !substr_count(trim($trimmedNextLine, '|'), '|') ) { - $inTable = null; + $inTable = null; $stackTable[] = "\n"; } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 9a5a849..5244c37 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,14 +2,14 @@ error_reporting(E_ALL); -foreach (array( - dirname(__DIR__).'/vendor/autoload.php', - dirname(dirname(dirname(__DIR__))).'/autoload.php', -) as $loader) { +foreach ([ + dirname(__DIR__) . '/vendor/autoload.php', + dirname(dirname(dirname(__DIR__))) . '/autoload.php', +] as $loader) { if (is_file($loader)) { return require $loader; } } // As a last resort -require dirname(__DIR__).'/src/HtmlUp.php'; +require dirname(__DIR__) . '/src/HtmlUp.php'; diff --git a/tests/src/HtmlUpTest.php b/tests/src/HtmlUpTest.php index fe40d29..ac41a43 100644 --- a/tests/src/HtmlUpTest.php +++ b/tests/src/HtmlUpTest.php @@ -6,12 +6,11 @@ class HtmlUpTest extends PHPUnit_Framework_TestCase { /** * @dataProvider dataSrc - * */ public function testAll() { list($testName, $markdown, $expectedMarkup) = func_get_args(); - $actualMarkup = (string) new HtmlUp($markdown); + $actualMarkup = (string) new HtmlUp($markdown); $this->assertion($testName, $expectedMarkup, $actualMarkup); } @@ -24,37 +23,37 @@ public function testAll() * 'markdown text', * 'expected markup text' * ) - * + * . */ public function dataSrc() { - return array( - array( + return [ + [ 'Atx Header', $this->assemble('# HelloH1', '## HelloH2'), - '

    HelloH1

    HelloH2

    ' - ), - array( + '

    HelloH1

    HelloH2

    ', + ], + [ 'Unordered List', $this->assemble('- Hello', '* HelloAgain'), - '
    • Hello
    • HelloAgain
    ' - ), - array( + '
    • Hello
    • HelloAgain
    ', + ], + [ 'Ordered List', $this->assemble('1. Hello', '2. HelloAgain'), - '
    1. Hello
    2. HelloAgain
    ' - ), - array( + '
    1. Hello
    2. HelloAgain
    ', + ], + [ 'H8 is Paragraph', '######## NoHeader', - '

    ######## NoHeader

    ' - ), - array( + '

    ######## NoHeader

    ', + ], + [ 'Horizontal Rule', $this->assemble('', '***', '', '___'), - '

    ' - ), - array( + '

    ', + ], + [ 'Table', $this->assemble('a | b', '---|---', '1 | 2', '4 | 5'), ' @@ -74,9 +73,9 @@ public function dataSrc() -
    5
    ' - ), - ); +', + ], + ]; } protected function assertion($testName, $expected, $actual) @@ -91,8 +90,8 @@ protected function assertion($testName, $expected, $actual) protected function normalizeMarkup($markup) { $markup = preg_replace( - array('/\>[^\S ]+/s', '/[^\S ]+\', '<', ), + ['/\>[^\S ]+/s', '/[^\S ]+\', '<'], $markup ); From ce24a4acf2582c15056236a83eef27f1ff3069fe Mon Sep 17 00:00:00 2001 From: Jitendra Adhikari Date: Wed, 25 Oct 2017 00:52:27 +0700 Subject: [PATCH 2/2] build(Travis): this better --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index fb7cdcf..16ef547 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,5 +3,5 @@ php: - 5.4 - 5.5 - 5.6 - - hhvm - - nightly \ No newline at end of file + - 7.0 + - 7.1