From 54b0d723f325f630d425a7c83b4d9b97477df2e9 Mon Sep 17 00:00:00 2001
From: Damien ALEXANDRE
Date: Fri, 31 Mar 2017 20:13:26 +0200
Subject: [PATCH 1/2] Deprecate the Numeric class, ref #30
---
CHANGELOG.md | 5 +++-
README.md | 12 ++++----
src/JoliTypo/Fixer.php | 5 ++++
src/JoliTypo/Fixer/Numeric.php | 15 ++++------
src/JoliTypo/Fixer/Unit.php | 28 +++++++++++++++++++
tests/JoliTypo/Tests/EnglishTest.php | 2 +-
.../Fixer/{NumericTest.php => UnitTest.php} | 6 ++--
tests/JoliTypo/Tests/FrenchTest.php | 2 +-
8 files changed, 54 insertions(+), 21 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..6ca2976 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 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 trademark symbol `™`, a registered trademark symbol `®`, and a copyright 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.php b/src/JoliTypo/Fixer.php
index 907a875..1dd3baa 100644
--- a/src/JoliTypo/Fixer.php
+++ b/src/JoliTypo/Fixer.php
@@ -135,6 +135,11 @@ private function compileRules($rules)
$fixer = $rule;
$className = get_class($rule);
} else {
+ /* BC Layer: the Numeric class is deprecated */
+ if (mb_strtolower($rule) === 'numeric') {
+ $rule = 'Unit';
+ }
+
$className = class_exists($rule) ? $rule : (class_exists('JoliTypo\\Fixer\\'.$rule) ? 'JoliTypo\\Fixer\\'.$rule : false);
if (!$className) {
throw new BadRuleSetException(sprintf('Fixer %s not found', $rule));
diff --git a/src/JoliTypo/Fixer/Numeric.php b/src/JoliTypo/Fixer/Numeric.php
index b9bdec4..4fe46ab 100644
--- a/src/JoliTypo/Fixer/Numeric.php
+++ b/src/JoliTypo/Fixer/Numeric.php
@@ -10,19 +10,16 @@
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.', E_USER_NOTICE);
}
}
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
From 7132faba4bf8c754a45729fcec60ad372da08416 Mon Sep 17 00:00:00 2001
From: Damien ALEXANDRE
Date: Sun, 2 Apr 2017 19:16:33 +0200
Subject: [PATCH 2/2] Remove useless BC layer and use real DEPRECATED error
code
---
CHANGELOG.md | 2 +-
src/JoliTypo/Fixer.php | 5 -----
src/JoliTypo/Fixer/Numeric.php | 4 +---
tests/JoliTypo/Tests/JoliTypoTest.php | 8 ++++++++
4 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6ca2976..8d8d16e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,7 @@ CHANGELOG
### 1.0.2 (2017-03-31) ###
* fix PHP CS Fixer configuration and version
-* fix #30 deprecate the Numeric class in favor of Unit
+* fix #30 deprecate the PHP 7 reserved word Numeric class in favor of Unit
### 1.0.1 (2015-12-13) ###
diff --git a/src/JoliTypo/Fixer.php b/src/JoliTypo/Fixer.php
index 1dd3baa..907a875 100644
--- a/src/JoliTypo/Fixer.php
+++ b/src/JoliTypo/Fixer.php
@@ -135,11 +135,6 @@ private function compileRules($rules)
$fixer = $rule;
$className = get_class($rule);
} else {
- /* BC Layer: the Numeric class is deprecated */
- if (mb_strtolower($rule) === 'numeric') {
- $rule = 'Unit';
- }
-
$className = class_exists($rule) ? $rule : (class_exists('JoliTypo\\Fixer\\'.$rule) ? 'JoliTypo\\Fixer\\'.$rule : false);
if (!$className) {
throw new BadRuleSetException(sprintf('Fixer %s not found', $rule));
diff --git a/src/JoliTypo/Fixer/Numeric.php b/src/JoliTypo/Fixer/Numeric.php
index 4fe46ab..c58962a 100644
--- a/src/JoliTypo/Fixer/Numeric.php
+++ b/src/JoliTypo/Fixer/Numeric.php
@@ -9,8 +9,6 @@
namespace JoliTypo\Fixer;
-use JoliTypo\Fixer;
-
/**
* {@inheritdoc}
*
@@ -20,6 +18,6 @@ class Numeric extends Unit
{
public function __construct()
{
- trigger_error('Numeric fixer is deprecated, use Unit instead.', E_USER_NOTICE);
+ @trigger_error('Numeric fixer is deprecated, use Unit instead. To be removed in 2.0.', E_USER_DEPRECATED);
}
}
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