fedi-feed-router/app/Services/Article/ValidationService.php
2025-07-03 21:16:57 +02:00

53 lines
1.3 KiB
PHP

<?php
namespace App\Services\Article;
use App\Models\Article;
class ValidationService
{
public static function validate(Article $article): Article
{
logger('Checking keywords for article: ' . $article->id);
$articleData = ArticleFetcher::fetchArticleData($article);
if (!isset($articleData['full_article'])) {
logger()->warning('Article data missing full_article key', [
'article_id' => $article->id,
'url' => $article->url
]);
$article->update([
'is_valid' => false,
'validated_at' => now(),
]);
return $article->refresh();
}
$validationResult = self::validateByKeywords($articleData['full_article']);
$article->update([
'is_valid' => $validationResult,
'validated_at' => now(),
]);
return $article->refresh();
}
private static function validateByKeywords(string $full_article): bool
{
$keywords = [
'N-VA', 'Bart De Wever', 'Frank Vandenbroucke',
];
foreach ($keywords as $keyword) {
if (stripos($full_article, $keyword) !== false) {
return true;
}
}
return false;
}
}