Skip to content

Commit

Permalink
Fix coding standard and TravisCi build (#33)
Browse files Browse the repository at this point in the history
* Update PHP CS Fixer to latests and fix phpunit version

* Fix the documentation

* Fix typo the website
  • Loading branch information
damienalexandre authored Mar 31, 2017
1 parent bacf2dd commit 762b773
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 47 deletions.
26 changes: 12 additions & 14 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ This software consists of voluntary contributions made by many individuals
and is licensed under the MIT license.
EOF;

Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header);

$finder = Symfony\CS\Finder\DefaultFinder::create()
$finder = PhpCsFixer\Finder::create()
->in(array(__DIR__.'/src', __DIR__.'/tests'))
;

return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->fixers(array(
'header_comment',
'-unalign_double_arrow',
'-unalign_equals',
'align_double_arrow',
'newline_after_open_tag',
'ordered_use',
return PhpCsFixer\Config::create()
->setRules(array(
'@Symfony' => true,
'header_comment' => array('header' => $header),
'binary_operator_spaces' => array(
'align_double_arrow' => true,
'align_equals' => true,
),
'array_syntax' => array('syntax' => 'long'),
'ordered_imports' => true
))
->setUsingCache(true)
->finder($finder)
->setFinder($finder)
;
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ matrix:
before_script:
- composer install

script: vendor/bin/phpunit --coverage-text
script: composer testci
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ Add your own Fixer / Contribute a Fixer
### Contribution guidelines

- You MUST write code in english;
- you MUST follow PSR2 and Symfony coding standard (run `./vendor/bin/php-cs-fixer -vvv fix` on your branch);
- you MUST run the tests (run `./vendor/bin/phpunit`);
- you MUST follow PSR2 and Symfony coding standard (run `composer cs` on your branch);
- you MUST run the tests (run `composer test`);
- you MUST comply to the MIT license;
- you SHOULD write documentation.

Expand Down
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
"name": "Damien Alexandre",
"email": "dalexandre@jolicode.com",
"homepage": "http://damienalexandre.fr/"
"homepage": "https://damienalexandre.fr/"
}
],
"require": {
Expand All @@ -27,7 +27,12 @@
}
},
"require-dev": {
"fabpot/php-cs-fixer": "^1.11",
"phpunit/phpunit": "~5.7"
"friendsofphp/php-cs-fixer": "~2.2.0",
"phpunit/phpunit": "~4.5"
},
"scripts": {
"test": "vendor/bin/phpunit -c phpunit.xml.dist",
"testci": "vendor/bin/phpunit -c phpunit.xml.dist --coverage-text",
"cs": "vendor/bin/php-cs-fixer fix"
}
}
16 changes: 8 additions & 8 deletions src/JoliTypo/Fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private function compileRules($rules)
$this->_rules = array();
foreach ($rules as $rule) {
if (is_object($rule)) {
$fixer = $rule;
$fixer = $rule;
$className = get_class($rule);
} else {
$className = class_exists($rule) ? $rule : (class_exists('JoliTypo\\Fixer\\'.$rule) ? 'JoliTypo\\Fixer\\'.$rule : false);
Expand Down Expand Up @@ -198,8 +198,8 @@ private function processDOM(\DOMNode $node, \DOMDocument $dom)
*/
private function doFix(\DOMText $childNode, \DOMNode $node, \DOMDocument $dom)
{
$content = $childNode->wholeText;
$current_node = new StateNode($childNode, $node, $dom);
$content = $childNode->wholeText;
$current_node = new StateNode($childNode, $node, $dom);

$this->stateBag->setCurrentNode($current_node);

Expand Down Expand Up @@ -227,15 +227,15 @@ private function doFix(\DOMText $childNode, \DOMNode $node, \DOMDocument $dom)
*/
private function loadDOMDocument($content)
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->encoding = 'UTF-8';

$dom->strictErrorChecking = false;
$dom->substituteEntities = false;
$dom->formatOutput = false;
$dom->strictErrorChecking = false;
$dom->substituteEntities = false;
$dom->formatOutput = false;

// Change mb and libxml config
$libxmlCurrent = libxml_use_internal_errors(true);
$libxmlCurrent = libxml_use_internal_errors(true);
$mbDetectCurrent = mb_detect_order();
mb_detect_order('ASCII,UTF-8,ISO-8859-1,windows-1252,iso-8859-15');

Expand Down
24 changes: 12 additions & 12 deletions src/JoliTypo/Fixer/SmartQuotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public function setLocale($locale)
switch (strtolower($locale)) {
// “…”
case 'pt-br':
$this->opening = Fixer::LDQUO;
$this->opening = Fixer::LDQUO;
$this->openingSuffix = '';
$this->closing = Fixer::RDQUO;
$this->closing = Fixer::RDQUO;
$this->closingPrefix = '';

return;
Expand All @@ -73,9 +73,9 @@ public function setLocale($locale)
switch ($short) {
// « … »
case 'fr':
$this->opening = Fixer::LAQUO;
$this->opening = Fixer::LAQUO;
$this->openingSuffix = Fixer::NO_BREAK_SPACE;
$this->closing = Fixer::RAQUO;
$this->closing = Fixer::RAQUO;
$this->closingPrefix = Fixer::NO_BREAK_SPACE;
break;
// «…»
Expand All @@ -94,9 +94,9 @@ public function setLocale($locale)
case 'ru':
case 'es':
case 'uk':
$this->opening = Fixer::LAQUO;
$this->opening = Fixer::LAQUO;
$this->openingSuffix = '';
$this->closing = Fixer::RAQUO;
$this->closing = Fixer::RAQUO;
$this->closingPrefix = '';
break;
// „…“
Expand All @@ -111,9 +111,9 @@ public function setLocale($locale)
case 'sk':
case 'sl':
case 'wen':
$this->opening = Fixer::BDQUO;
$this->opening = Fixer::BDQUO;
$this->openingSuffix = '';
$this->closing = Fixer::LDQUO;
$this->closing = Fixer::LDQUO;
$this->closingPrefix = '';
break;
// “…”
Expand All @@ -130,18 +130,18 @@ public function setLocale($locale)
case 'th':
case 'tr':
case 'vi':
$this->opening = Fixer::LDQUO;
$this->opening = Fixer::LDQUO;
$this->openingSuffix = '';
$this->closing = Fixer::RDQUO;
$this->closing = Fixer::RDQUO;
$this->closingPrefix = '';
break;
// ”…”
case 'fi':
case 'sv':
case 'bs':
$this->opening = Fixer::RDQUO;
$this->opening = Fixer::RDQUO;
$this->openingSuffix = '';
$this->closing = Fixer::RDQUO;
$this->closing = Fixer::RDQUO;
$this->closingPrefix = '';
break;
}
Expand Down
6 changes: 2 additions & 4 deletions tests/JoliTypo/Tests/Fixer/NoSpaceBeforeCommaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

use JoliTypo\Fixer;

/**
*/
class NoSpaceBeforeCommaTest extends \PHPUnit_Framework_TestCase
{
public function testSimpleString()
Expand All @@ -23,7 +21,7 @@ public function testSimpleString()
$this->assertEquals("Superman, you're my hero", $fixer->fix("Superman,you're my hero"));
$this->assertEquals("Superman, you're my hero", $fixer->fix("Superman ,you're my hero"));
$this->assertEquals("Superman, you're my hero", $fixer->fix("Superman , you're my hero"));
$this->assertEquals("F, bar", $fixer->fix("F,bar"));
$this->assertEquals("Seule 1,7 million de personnes", $fixer->fix("Seule 1,7 million de personnes"));
$this->assertEquals('F, bar', $fixer->fix('F,bar'));
$this->assertEquals('Seule 1,7 million de personnes', $fixer->fix('Seule 1,7 million de personnes'));
}
}
2 changes: 1 addition & 1 deletion tests/JoliTypo/Tests/Fixer/SmartQuotesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public function testSimpleString()
public function testBadConfig()
{
$fixer = new Fixer\SmartQuotes('unknown');
$fixer->fix("nope");
$fixer->fix('nope');
}
}
4 changes: 2 additions & 2 deletions tests/JoliTypo/Tests/JoliTypoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public function testOkFixer()

public function testProtectedTags()
{
$fixer = new Fixer(array('Ellipsis'));
$fixer = new Fixer(array('Ellipsis'));
$fixer->setProtectedTags(array('pre', 'a'));
$fixed_content = $fixer->fix('<p>Fixed...</p> <pre>Not fixed...</pre> <p>Fixed... <a>Not Fixed...</a>.</p>');
$fixed_content = $fixer->fix('<p>Fixed...</p> <pre>Not fixed...</pre> <p>Fixed... <a>Not Fixed...</a>.</p>');

$this->assertEquals('<p>Fixed&hellip;</p> <pre>Not fixed...</pre> <p>Fixed&hellip; <a>Not Fixed...</a>.</p>', $fixed_content);
}
Expand Down

0 comments on commit 762b773

Please sign in to comment.