From 6e711fc0012196df717c15ecbe4eaaf70bc5617f Mon Sep 17 00:00:00 2001 From: JanPetterMG Date: Mon, 4 Apr 2016 18:04:58 +0200 Subject: [PATCH] Code style violation fixes --- composer.json | 3 +-- src/SitemapParser.php | 11 +++++------ tests/ExceptionEncodingTest.php | 2 +- tests/ExceptionMBStringTest.php | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index cfcb66c..348905a 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,6 @@ { "name": "vipnytt/sitemapparser", "description": "XML Sitemap parser class compliant with the Sitemaps.org protocol.", - "version": "1.0.0", "keywords": [ "sitemap", "sitemaps.org", @@ -44,4 +43,4 @@ "vipnytt\\SitemapParser\\Tests\\": "tests/" } } -} \ No newline at end of file +} diff --git a/src/SitemapParser.php b/src/SitemapParser.php index 3f19290..15a6664 100644 --- a/src/SitemapParser.php +++ b/src/SitemapParser.php @@ -146,7 +146,7 @@ public function parse($url, $urlContent = null) $response = gzdecode($response); } $sitemapJson = $this->generateXMLObject($response); - if ($sitemapJson === false) { + if ($sitemapJson instanceof SimpleXMLElement === false) { $this->parseString($response); return; } @@ -239,13 +239,12 @@ protected function addArray($type, $array) */ protected function generateXMLObject($xml) { - libxml_use_internal_errors(true); - $doc = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); - if ($doc === false) { - libxml_clear_errors(); + try { + libxml_use_internal_errors(true); + return new SimpleXMLElement($xml, LIBXML_NOCDATA); + } catch (\Exception $e) { return false; } - return $doc; } /** diff --git a/tests/ExceptionEncodingTest.php b/tests/ExceptionEncodingTest.php index cca2809..bb6acef 100644 --- a/tests/ExceptionEncodingTest.php +++ b/tests/ExceptionEncodingTest.php @@ -6,7 +6,7 @@ class ExceptionEncodingTest extends \PHPUnit_Framework_TestCase { /** - * Test if exception is thrown when extension `simpleXML` is not loaded + * Test if exception is thrown when trying to set encoding to `UTF-8` */ public function testExceptionEncoding() { diff --git a/tests/ExceptionMBStringTest.php b/tests/ExceptionMBStringTest.php index eaa1253..e8dac06 100644 --- a/tests/ExceptionMBStringTest.php +++ b/tests/ExceptionMBStringTest.php @@ -6,7 +6,7 @@ class ExceptionMBStringTest extends \PHPUnit_Framework_TestCase { /** - * Test if exception is thrown when extension `simpleXML` is not loaded + * Test if exception is thrown when extension `mbstring` is not loaded */ public function testExceptionMBString() {