From 9682cb058c468329a3273607d2fcb172fdfd9835 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 15 Jul 2020 16:54:44 +0400 Subject: Added string parser Signed-off-by: Valentin Popov --- src/Parsers/StringParser.php | 40 ++++++++++++++++++++++++++++++++++++++ tests/Parsers/StringParserTest.php | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 src/Parsers/StringParser.php create mode 100644 tests/Parsers/StringParserTest.php diff --git a/src/Parsers/StringParser.php b/src/Parsers/StringParser.php new file mode 100644 index 0000000..1bc7a60 --- /dev/null +++ b/src/Parsers/StringParser.php @@ -0,0 +1,40 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package EPGService\Parsers + */ +final class StringParser { + /** + * @param $value + * + * @return string|null + */ + public static function get($value): ?string { + $result = filter_var($value, FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE); + + return is_string($result) ? trim($result) : null; + } +} diff --git a/tests/Parsers/StringParserTest.php b/tests/Parsers/StringParserTest.php new file mode 100644 index 0000000..518defb --- /dev/null +++ b/tests/Parsers/StringParserTest.php @@ -0,0 +1,35 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package Tests\Parsers + */ +final class StringParserTest extends TestCase { + public function testValid(): void { + $string = '

Hello WorldÆØÅ!

'; + self::assertEquals('Hello World!', StringParser::get($string)); + } +} -- cgit v1.2.3