Standardise formatting

This commit is contained in:
Aidan Woods 2018-12-04 17:24:25 +01:00
parent 267256cbb8
commit 8512e65a18
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
11 changed files with 583 additions and 736 deletions

34
.php_cs.dist Normal file
View File

@ -0,0 +1,34 @@
<?php
use PhpCsFixer\Config;
use PhpCsFixer\Finder;
$finder = Finder::create()
->in(__DIR__ . '/src/')
->in(__DIR__ . '/tests/')
;
$rules = [
'@PSR2' => true,
'array_syntax' => [
'syntax' => 'short',
],
'braces' => [
'allow_single_line_closure' => true,
],
'native_constant_invocation' => [
'fix_built_in' => true,
],
'native_function_invocation' => [
'include' => ['@all'],
],
'no_unused_imports' => true,
'ordered_imports' => [
'sort_algorithm' => 'alpha',
],
'strict_comparison' => true,
'strict_param' => true,
];
return Config::create()
->setRules($rules)
->setFinder($finder)
->setUsingCache(false)
->setRiskyAllowed(true)
;

View File

@ -17,7 +17,8 @@
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35"
"phpunit/phpunit": "^4.8.35",
"friendsofphp/php-cs-fixer": "^2.13"
},
"autoload": {
"psr-4": {"Erusev\\Parsedown\\": "src/"}

View File

@ -1,4 +1,4 @@
<?php declare(strict_types=1);
<?php
namespace Erusev\Parsedown\Html;

View File

@ -1,4 +1,4 @@
<?php declare(strict_types=1);
<?php
namespace Erusev\Parsedown\Html\Renderables;

View File

@ -1,9 +1,8 @@
<?php declare(strict_types=1);
<?php
namespace Erusev\Parsedown\Html\Renderables;
use Erusev\Parsedown\Html\Renderable;
use Erusev\Parsedown\Html\Sanitisation\CharacterFilter;
use Erusev\Parsedown\Html\Sanitisation\Escaper;
final class Text implements Renderable

View File

@ -1,4 +1,4 @@
<?php declare(strict_types=1);
<?php
namespace Erusev\Parsedown\Html\Sanitisation;

View File

@ -1,4 +1,4 @@
<?php declare(strict_types=1);
<?php
namespace Erusev\Parsedown\Html\Sanitisation;

File diff suppressed because it is too large Load Diff

View File

@ -37,18 +37,18 @@ class CommonMarkTestStrict extends PHPUnit_Framework_TestCase
*/
public function data()
{
$spec = file_get_contents(self::SPEC_URL);
$spec = \file_get_contents(self::SPEC_URL);
if ($spec === false) {
$this->fail('Unable to load CommonMark spec from ' . self::SPEC_URL);
}
$spec = str_replace("\r\n", "\n", $spec);
$spec = strstr($spec, '<!-- END TESTS -->', true);
$spec = \str_replace("\r\n", "\n", $spec);
$spec = \strstr($spec, '<!-- END TESTS -->', true);
$matches = array();
preg_match_all('/^`{32} example\n((?s).*?)\n\.\n(?:|((?s).*?)\n)`{32}$|^#{1,6} *(.*?)$/m', $spec, $matches, PREG_SET_ORDER);
$matches = [];
\preg_match_all('/^`{32} example\n((?s).*?)\n\.\n(?:|((?s).*?)\n)`{32}$|^#{1,6} *(.*?)$/m', $spec, $matches, \PREG_SET_ORDER);
$data = array();
$data = [];
$currentId = 0;
$currentSection = '';
foreach ($matches as $match) {
@ -56,15 +56,15 @@ class CommonMarkTestStrict extends PHPUnit_Framework_TestCase
$currentSection = $match[3];
} else {
$currentId++;
$markdown = str_replace('→', "\t", $match[1]);
$expectedHtml = isset($match[2]) ? str_replace('→', "\t", $match[2]) : '';
$markdown = \str_replace('→', "\t", $match[1]);
$expectedHtml = isset($match[2]) ? \str_replace('→', "\t", $match[2]) : '';
$data[$currentId] = array(
$data[$currentId] = [
'id' => $currentId,
'section' => $currentSection,
'markdown' => $markdown,
'expectedHtml' => $expectedHtml
);
];
}
}

View File

@ -23,10 +23,10 @@ class CommonMarkTestWeak extends CommonMarkTestStrict
parent::setUp();
$textLevelElements = $this->parsedown->getTextLevelElements();
array_walk($textLevelElements, function (&$element) {
$element = preg_quote($element, '/');
\array_walk($textLevelElements, function (&$element) {
$element = \preg_quote($element, '/');
});
$this->textLevelElementRegex = '\b(?:' . implode('|', $textLevelElements) . ')\b';
$this->textLevelElementRegex = '\b(?:' . \implode('|', $textLevelElements) . ')\b';
}
/**
@ -50,11 +50,11 @@ class CommonMarkTestWeak extends CommonMarkTestStrict
{
// invisible whitespaces at the beginning and end of block elements
// however, whitespaces at the beginning of <pre> elements do matter
$markup = preg_replace(
array(
$markup = \preg_replace(
[
'/(<(?!(?:' . $this->textLevelElementRegex . '|\bpre\b))\w+\b[^>]*>(?:<' . $this->textLevelElementRegex . '[^>]*>)*)\s+/s',
'/\s+((?:<\/' . $this->textLevelElementRegex . '>)*<\/(?!' . $this->textLevelElementRegex . ')\w+\b>)/s'
),
],
'$1',
$markup
);

View File

@ -2,12 +2,12 @@
namespace Erusev\Parsedown\Tests;
use PHPUnit\Framework\TestCase;
use Erusev\Parsedown\Parsedown;
use PHPUnit\Framework\TestCase;
class ParsedownTest extends TestCase
{
final function __construct($name = null, array $data = array(), $dataName = '')
final public function __construct($name = null, array $data = [], $dataName = '')
{
$this->dirs = $this->initDirs();
$this->Parsedown = $this->initParsedown();
@ -23,7 +23,7 @@ class ParsedownTest extends TestCase
*/
protected function initDirs()
{
$dirs []= dirname(__FILE__).'/data/';
$dirs []= \dirname(__FILE__).'/data/';
return $dirs;
}
@ -43,24 +43,24 @@ class ParsedownTest extends TestCase
* @param $test
* @param $dir
*/
function test_($test, $dir)
public function test_($test, $dir)
{
$markdown = file_get_contents($dir . $test . '.md');
$markdown = \file_get_contents($dir . $test . '.md');
$expectedMarkup = file_get_contents($dir . $test . '.html');
$expectedMarkup = \file_get_contents($dir . $test . '.html');
$expectedMarkup = str_replace("\r\n", "\n", $expectedMarkup);
$expectedMarkup = str_replace("\r", "\n", $expectedMarkup);
$expectedMarkup = \str_replace("\r\n", "\n", $expectedMarkup);
$expectedMarkup = \str_replace("\r", "\n", $expectedMarkup);
$this->Parsedown->setSafeMode(substr($test, 0, 3) === 'xss');
$this->Parsedown->setStrictMode(substr($test, 0, 6) === 'strict');
$this->Parsedown->setSafeMode(\substr($test, 0, 3) === 'xss');
$this->Parsedown->setStrictMode(\substr($test, 0, 6) === 'strict');
$actualMarkup = $this->Parsedown->text($markdown);
$this->assertEquals($expectedMarkup, $actualMarkup);
}
function testRawHtml()
public function testRawHtml()
{
$markdown = "```php\nfoobar\n```";
$expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
@ -77,7 +77,7 @@ class ParsedownTest extends TestCase
$this->assertEquals($expectedSafeMarkup, $actualSafeMarkup);
}
function testTrustDelegatedRawHtml()
public function testTrustDelegatedRawHtml()
{
$markdown = "```php\nfoobar\n```";
$expectedMarkup = '<pre><code class="language-php"><p>foobar</p></code></pre>';
@ -94,37 +94,32 @@ class ParsedownTest extends TestCase
$this->assertEquals($expectedSafeMarkup, $actualSafeMarkup);
}
function data()
public function data()
{
$data = array();
$data = [];
foreach ($this->dirs as $dir)
{
foreach ($this->dirs as $dir) {
$Folder = new \DirectoryIterator($dir);
foreach ($Folder as $File)
{
foreach ($Folder as $File) {
/** @var $File DirectoryIterator */
if ( ! $File->isFile())
{
if (! $File->isFile()) {
continue;
}
$filename = $File->getFilename();
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$extension = \pathinfo($filename, \PATHINFO_EXTENSION);
if ($extension !== 'md')
{
if ($extension !== 'md') {
continue;
}
$basename = $File->getBasename('.md');
if (file_exists($dir . $basename . '.html'))
{
$data []= array($basename, $dir);
if (\file_exists($dir . $basename . '.html')) {
$data []= [$basename, $dir];
}
}
}