2.0 #1

Merged
mathiaspalmqvist merged 10 commits from 2.0 into main 2025-07-04 19:22:40 +00:00
4 changed files with 11 additions and 10 deletions
Showing only changes of commit aee28b3450 - Show all commits

No files matched your search

+2 -3
View File
@@ -1,8 +1,7 @@
<?php <?php
use Mattitja\Cision\Cision;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str; use Mattitja\Cision\Cision;
it('can fetch press releases from the RSS feed', function () { it('can fetch press releases from the RSS feed', function () {
Http::fake([ Http::fake([
@@ -25,7 +24,7 @@ it('can fetch and parse full article content', function () {
'news.cision.com/*' => Http::response(file_get_contents(__DIR__.'/Fixtures/article.html')), 'news.cision.com/*' => Http::response(file_get_contents(__DIR__.'/Fixtures/article.html')),
]); ]);
$cision = new Cision(); $cision = new Cision;
$content = $cision->fetchContent('https://news.cision.com/se/example/r/test,c123456'); $content = $cision->fetchContent('https://news.cision.com/se/example/r/test,c123456');
expect($content)->toHaveKeys(['header', 'published_at', 'content']); expect($content)->toHaveKeys(['header', 'published_at', 'content']);
+4 -4
View File
@@ -3,10 +3,10 @@
namespace Mattitja\Cision; namespace Mattitja\Cision;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Support\Facades\Http;
use Illuminate\Http\Client\Response; use Illuminate\Http\Client\Response;
use Symfony\Component\DomCrawler\Crawler; use Illuminate\Support\Facades\Http;
use Mattitja\Cision\Support\HtmlCleaner; use Mattitja\Cision\Support\HtmlCleaner;
use Symfony\Component\DomCrawler\Crawler;
class Cision class Cision
{ {
@@ -15,7 +15,7 @@ class Cision
/** /**
* Constructor that accepts a slug identifier for the feed. * Constructor that accepts a slug identifier for the feed.
*/ */
public function __construct(string $slug = null) public function __construct(?string $slug = null)
{ {
$this->slug = $slug ?? env('LARAVEL_CISION_FEED_SLUG', ''); $this->slug = $slug ?? env('LARAVEL_CISION_FEED_SLUG', '');
} }
@@ -116,7 +116,7 @@ class Cision
// Suppress XML parsing warnings // Suppress XML parsing warnings
libxml_use_internal_errors(true); libxml_use_internal_errors(true);
$xml = simplexml_load_string($data, "SimpleXMLElement", LIBXML_NOCDATA); $xml = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
libxml_clear_errors(); libxml_clear_errors();
if ($xml === false) { if ($xml === false) {
-1
View File
@@ -4,7 +4,6 @@ namespace Mattitja\Cision;
use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider; use Spatie\LaravelPackageTools\PackageServiceProvider;
use Mattitja\Cision\Commands\CisionCommand;
class CisionServiceProvider extends PackageServiceProvider class CisionServiceProvider extends PackageServiceProvider
{ {
+5 -2
View File
@@ -2,9 +2,9 @@
namespace Mattitja\Cision\Support; namespace Mattitja\Cision\Support;
use DOMElement;
use DOMNode; use DOMNode;
use DOMText; use DOMText;
use DOMElement;
class HtmlCleaner class HtmlCleaner
{ {
@@ -35,6 +35,7 @@ class HtmlCleaner
return '<br>'; return '<br>';
} }
} }
return null; return null;
} }
@@ -52,8 +53,10 @@ class HtmlCleaner
$html = $node->C14N(); $html = $node->C14N();
$isItalic = str_starts_with(trim($html), '<em') || str_starts_with(trim($html), '<i'); $isItalic = str_starts_with(trim($html), '<em') || str_starts_with(trim($html), '<i');
$class = $isItalic ? ' class="italic"' : ''; $class = $isItalic ? ' class="italic"' : '';
return "<p{$class}>" . trim($inner) . "</p>";
return "<p{$class}>".trim($inner).'</p>';
} }
return "<{$tag}>".trim($inner)."</{$tag}>"; return "<{$tag}>".trim($inner)."</{$tag}>";
} }