-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move NumberUtility into NumberHelper
- Loading branch information
Showing
3 changed files
with
107 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the smsmode-library package. | ||
* | ||
* (c) 2017 WEBEWEB | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace WBW\Library\SMSMode\Helper; | ||
|
||
/** | ||
* Number helper. | ||
* | ||
* @author webeweb <https://github.com/webeweb/> | ||
* @package WBW\Library\SMSMode\Helper | ||
*/ | ||
class NumberHelper { | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
private function __construct() { | ||
// NOTHING TO DO. | ||
} | ||
|
||
/** | ||
* Decode a number. | ||
* | ||
* @param string $number The number. | ||
* @return string Returns the decoded number. | ||
*/ | ||
public static function decodeNumber($number) { | ||
$output = preg_replace("/^336/", "06", $number, 1); | ||
$result = preg_replace("/^337/", "07", $output, 1); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Encode a number. | ||
* | ||
* @param string $number The number. | ||
* @return string Returns the encoded number. | ||
*/ | ||
public static function encodeNumber($number) { | ||
$output = preg_replace("/^06/", "336", $number, 1); | ||
$result = preg_replace("/^07/", "337", $output, 1); | ||
return $result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the smsmode-library package. | ||
* | ||
* (c) 2017 WEBEWEB | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace WBW\Library\SMSMode\Tests\Helper; | ||
|
||
use PHPUnit_Framework_TestCase; | ||
use WBW\Library\SMSMode\Helper\NumberHelper; | ||
|
||
/** | ||
* Number helper test. | ||
* | ||
* @author webeweb <https://github.com/webeweb/> | ||
* @package WBW\Library\SMSMode\Helper | ||
* @final | ||
*/ | ||
final class NumberHelperTest extends PHPUnit_Framework_TestCase { | ||
|
||
/** | ||
* Tests the decodeNumber() method. | ||
* | ||
* @return void | ||
*/ | ||
public function testDecodeNumber() { | ||
|
||
$this->assertEquals("0612345678", NumberHelper::decodeNumber("33612345678")); | ||
$this->assertEquals("0712345678", NumberHelper::decodeNumber("33712345678")); | ||
$this->assertEquals("0612345678", NumberHelper::decodeNumber("0612345678")); | ||
$this->assertEquals("0712345678", NumberHelper::decodeNumber("0712345678")); | ||
} | ||
|
||
/** | ||
* Tests the encodeNumber() method. | ||
* | ||
* @return void | ||
*/ | ||
public function testEncodeNumber() { | ||
|
||
$this->assertEquals("33612345678", NumberHelper::encodeNumber("0612345678")); | ||
$this->assertEquals("33712345678", NumberHelper::encodeNumber("0712345678")); | ||
$this->assertEquals("33612345678", NumberHelper::encodeNumber("33612345678")); | ||
$this->assertEquals("33712345678", NumberHelper::encodeNumber("33712345678")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters