From f04ed9672c2039c4e5a8e1f9cc5ccc97fa757048 Mon Sep 17 00:00:00 2001 From: Damien Alexandre Date: Sun, 2 Apr 2017 19:22:10 +0200 Subject: [PATCH] Deprecate the Numeric class, ref #30 (#34) * Deprecate the Numeric class, ref #30 * Remove useless BC layer and use real DEPRECATED error code --- CHANGELOG.md | 5 +++- README.md | 12 ++++---- src/JoliTypo/Fixer/Numeric.php | 17 ++++------- src/JoliTypo/Fixer/Unit.php | 28 +++++++++++++++++++ tests/JoliTypo/Tests/EnglishTest.php | 2 +- .../Fixer/{NumericTest.php => UnitTest.php} | 6 ++-- tests/JoliTypo/Tests/FrenchTest.php | 2 +- tests/JoliTypo/Tests/JoliTypoTest.php | 8 ++++++ 8 files changed, 57 insertions(+), 23 deletions(-) create mode 100644 src/JoliTypo/Fixer/Unit.php rename tests/JoliTypo/Tests/Fixer/{NumericTest.php => UnitTest.php} (91%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f99431..8d8d16e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ CHANGELOG ========= -### Unreleased ### +### 1.0.2 (2017-03-31) ### + +* fix PHP CS Fixer configuration and version +* fix #30 deprecate the PHP 7 reserved word Numeric class in favor of Unit ### 1.0.1 (2015-12-13) ### diff --git a/README.md b/README.md index 4ba0ea8..5880611 100644 --- a/README.md +++ b/README.md @@ -145,10 +145,10 @@ Trademark Handle trade­mark symbol `™`, a reg­is­tered trade­mark symbol `®`, and a copy­right symbol `©`. This fixer replace commonly used approximations: `(r)`, `(c)` and `(TM)`. A non-breaking space is put between numbers and copyright symbol too. -Numeric +Unit (formerly Numeric) --------- -Add a non-breaking space between a numeric and it's unit. Like this: `12_h`, `42_฿` or `88_%`. +Add a non-breaking space between a numeric and it's unit. Like this: `12_h`, `42_฿` or `88_%`. It was named `Numeric` before release 1.0.2, but BC is kept for now. **It is really easy to make your own Fixers, feel free to extend the provided ones if they do not fit your typographic rules.** @@ -159,7 +159,7 @@ en_GB ----- ```php -$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Numeric', 'Dash', 'SmartQuotes', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark')); +$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Unit', 'Dash', 'SmartQuotes', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark')); $fixer->setLocale('en_GB'); ``` @@ -169,7 +169,7 @@ fr_FR Those rules apply most of the recommendations of "Abrégé du code typographique à l'usage de la presse", ISBN: 9782351130667. ```php -$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Numeric', 'Dash', 'SmartQuotes', 'FrenchNoBreakSpace', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark')); +$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Unit', 'Dash', 'SmartQuotes', 'FrenchNoBreakSpace', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark')); $fixer->setLocale('fr_FR'); ``` @@ -179,7 +179,7 @@ fr_CA Mostly the same as fr_FR, but the space before punctuation points is not mandatory. ```php -$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Numeric', 'Dash', 'SmartQuotes', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark')); +$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Unit', 'Dash', 'SmartQuotes', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark')); $fixer->setLocale('fr_CA'); ``` @@ -189,7 +189,7 @@ de_DE Mostly the same as en_GB, according to [Typefacts](http://typefacts.com/) and [Wikipedia](http://de.wikipedia.org/wiki/Typografie_f%C3%BCr_digitale_Texte). ```php -$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Numeric', 'Dash', 'SmartQuotes', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark')); +$fixer = new Fixer(array('Ellipsis', 'Dimension', 'Unit', 'Dash', 'SmartQuotes', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark')); $fixer->setLocale('de_DE'); ``` diff --git a/src/JoliTypo/Fixer/Numeric.php b/src/JoliTypo/Fixer/Numeric.php index b9bdec4..c58962a 100644 --- a/src/JoliTypo/Fixer/Numeric.php +++ b/src/JoliTypo/Fixer/Numeric.php @@ -9,20 +9,15 @@ namespace JoliTypo\Fixer; -use JoliTypo\Fixer; -use JoliTypo\FixerInterface; -use JoliTypo\StateBag; - /** - * Add nbsp between numeric and units. + * {@inheritdoc} + * + * @deprecated Numeric should not be used (reserved keyword in PHP7) */ -class Numeric implements FixerInterface +class Numeric extends Unit { - public function fix($content, StateBag $stateBag = null) + public function __construct() { - // Support a wide range of currencies - $content = preg_replace('@([\dº])('.Fixer::ALL_SPACES.')+([º°%Ω฿₵¢₡$₫֏€ƒ₲₴₭£₤₺₦₨₱៛₹$₪৳₸₮₩¥\w]{1})@', '$1'.Fixer::NO_BREAK_SPACE.'$3', $content); - - return $content; + @trigger_error('Numeric fixer is deprecated, use Unit instead. To be removed in 2.0.', E_USER_DEPRECATED); } } diff --git a/src/JoliTypo/Fixer/Unit.php b/src/JoliTypo/Fixer/Unit.php new file mode 100644 index 0000000..05adb55 --- /dev/null +++ b/src/JoliTypo/Fixer/Unit.php @@ -0,0 +1,28 @@ + diff --git a/tests/JoliTypo/Tests/Fixer/NumericTest.php b/tests/JoliTypo/Tests/Fixer/UnitTest.php similarity index 91% rename from tests/JoliTypo/Tests/Fixer/NumericTest.php rename to tests/JoliTypo/Tests/Fixer/UnitTest.php index e4029e0..c233576 100644 --- a/tests/JoliTypo/Tests/Fixer/NumericTest.php +++ b/tests/JoliTypo/Tests/Fixer/UnitTest.php @@ -11,12 +11,12 @@ use JoliTypo\Fixer; -class NumericTest extends \PHPUnit_Framework_TestCase +class UnitTest extends \PHPUnit_Framework_TestCase { public function testNumericUnits() { - $fixer = new Fixer\Numeric(); - $this->assertInstanceOf('JoliTypo\Fixer\Numeric', $fixer); + $fixer = new Fixer\Unit(); + $this->assertInstanceOf('JoliTypo\Fixer\Unit', $fixer); $this->assertEquals('Test', $fixer->fix('Test')); $this->assertEquals('1'.Fixer::NO_BREAK_SPACE.'h', $fixer->fix('1 h')); diff --git a/tests/JoliTypo/Tests/FrenchTest.php b/tests/JoliTypo/Tests/FrenchTest.php index 766385f..7157467 100644 --- a/tests/JoliTypo/Tests/FrenchTest.php +++ b/tests/JoliTypo/Tests/FrenchTest.php @@ -13,7 +13,7 @@ class FrenchTest extends \PHPUnit_Framework_TestCase { - private $fr_fixers = array('Numeric', 'Ellipsis', 'Dimension', 'Dash', 'SmartQuotes', 'FrenchNoBreakSpace', 'CurlyQuote', 'Hyphen', 'Trademark'); + private $fr_fixers = array('Unit', 'Ellipsis', 'Dimension', 'Dash', 'SmartQuotes', 'FrenchNoBreakSpace', 'CurlyQuote', 'Hyphen', 'Trademark'); const TOFIX = <<Ceci est à remplacer par une fâble :p

diff --git a/tests/JoliTypo/Tests/JoliTypoTest.php b/tests/JoliTypo/Tests/JoliTypoTest.php index 60f77bc..e2f70f2 100644 --- a/tests/JoliTypo/Tests/JoliTypoTest.php +++ b/tests/JoliTypo/Tests/JoliTypoTest.php @@ -180,6 +180,14 @@ public function testNonHTMLContent() $this->assertEquals(html_entity_decode($fixed, null, 'UTF-8'), $fixer->fixString($toFix)); $this->assertEquals('Here is a “protip©”!', $fixer->fixString('Here is a "protip(c)"!')); } + + public function testDeprecatedFixer() + { + $fixer = new Fixer(array('Numeric')); + $this->assertInstanceOf('JoliTypo\Fixer', $fixer); + + $this->assertEquals('3'.Fixer::NO_BREAK_SPACE.'€', $fixer->fixString('3 €')); + } } class FakeFixer