2.0 #1

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

No files matched your search

+1 -1
View File
@@ -2,4 +2,4 @@
arch('it will not use debugging functions') arch('it will not use debugging functions')
->expect(['dd', 'dump', 'ray']) ->expect(['dd', 'dump', 'ray'])
->each->not->toBeUsed(); ->each->not->toBeUsed();
+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']);
+1 -1
View File
@@ -2,4 +2,4 @@
use Mattitja\Cision\Tests\TestCase; use Mattitja\Cision\Tests\TestCase;
uses(TestCase::class)->in(__DIR__); uses(TestCase::class)->in(__DIR__);
+1 -1
View File
@@ -34,4 +34,4 @@ class TestCase extends Orchestra
} }
*/ */
} }
} }
+6 -6
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', '');
} }
@@ -105,7 +105,7 @@ class Cision
$query['m'] = $type; $query['m'] = $type;
} }
return Http::get('https://news.cision.com/se/ListItems?' . http_build_query($query)); return Http::get('https://news.cision.com/se/ListItems?'.http_build_query($query));
} }
protected function parseResponse(string $data, int $page): array|false protected function parseResponse(string $data, int $page): array|false
@@ -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) {
@@ -128,7 +128,7 @@ class Cision
$rows = json_decode($json, true); $rows = json_decode($json, true);
// Validate structure // Validate structure
if (!isset($rows['channel']['item'])) { if (! isset($rows['channel']['item'])) {
return false; return 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
{ {
+7 -4
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
{ {
@@ -17,7 +17,7 @@ class HtmlCleaner
return $node->wholeText; return $node->wholeText;
} }
if (!($node instanceof DOMElement)) { if (! ($node instanceof DOMElement)) {
return null; return null;
} }
@@ -35,6 +35,7 @@ class HtmlCleaner
return '<br>'; return '<br>';
} }
} }
return null; return null;
} }
@@ -52,9 +53,11 @@ 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}>";
} }
if (in_array($tag, $allowedInline)) { if (in_array($tag, $allowedInline)) {