Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ValidationService | |
0.00% |
0 / 25 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| validate | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
6 | |||
| validateByKeywords | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Services\Article; |
| 4 | |
| 5 | use App\Models\Article; |
| 6 | |
| 7 | class ValidationService |
| 8 | { |
| 9 | public static function validate(Article $article): Article |
| 10 | { |
| 11 | logger('Checking keywords for article: ' . $article->id); |
| 12 | |
| 13 | $articleData = ArticleFetcher::fetchArticleData($article); |
| 14 | |
| 15 | if (!isset($articleData['full_article'])) { |
| 16 | logger()->warning('Article data missing full_article key', [ |
| 17 | 'article_id' => $article->id, |
| 18 | 'url' => $article->url |
| 19 | ]); |
| 20 | |
| 21 | $article->update([ |
| 22 | 'is_valid' => false, |
| 23 | 'validated_at' => now(), |
| 24 | ]); |
| 25 | |
| 26 | return $article->refresh(); |
| 27 | } |
| 28 | |
| 29 | $validationResult = self::validateByKeywords($articleData['full_article']); |
| 30 | |
| 31 | $article->update([ |
| 32 | 'is_valid' => $validationResult, |
| 33 | 'validated_at' => now(), |
| 34 | ]); |
| 35 | |
| 36 | return $article->refresh(); |
| 37 | } |
| 38 | |
| 39 | private static function validateByKeywords(string $full_article): bool |
| 40 | { |
| 41 | $keywords = [ |
| 42 | 'N-VA', 'Bart De Wever', 'Frank Vandenbroucke', |
| 43 | ]; |
| 44 | |
| 45 | foreach ($keywords as $keyword) { |
| 46 | if (stripos($full_article, $keyword) !== false) { |
| 47 | return true; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | return false; |
| 52 | } |
| 53 | } |