Skip to content

Commit

Permalink
Remove try-block
Browse files Browse the repository at this point in the history
  • Loading branch information
ben221199 committed Oct 1, 2024
1 parent 5edcae6 commit 025a7f1
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/OEmbed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use DOMDocument;
use DOMElement;
use DOMException;
use InvalidArgumentException;

class OEmbed{
Expand Down Expand Up @@ -72,15 +71,12 @@ public static function encodeJSON(array $data): ?string{
public static function encodeXML(array $data): ?string{
self::ensureValidData($data);
$doc = new DOMDocument;
try{
$doc->append($doc->createElement('oembed'));
$arr = (array) $data;
foreach($arr as $key=>$val){
$elem = $doc->createElement($key);
$elem->appendChild($doc->createTextNode($val));
$doc->documentElement->append($elem);
}
}catch(DOMException $e){
$doc->append($doc->createElement('oembed'));
$arr = (array) $data;
foreach($arr as $key=>$val){
$elem = $doc->createElement($key);
$elem->appendChild($doc->createTextNode($val));
$doc->documentElement->append($elem);
}
return $doc->saveXML() ?? null;
}
Expand Down

0 comments on commit 025a7f1

Please sign in to comment.