Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| PlatformChannelPost | |
0.00% |
0 / 21 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
| casts | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| urlExists | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| storePost | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models; |
| 4 | |
| 5 | use App\Enums\PlatformEnum; |
| 6 | use Illuminate\Database\Eloquent\Model; |
| 7 | |
| 8 | /** |
| 9 | * @method static where(string $string, PlatformEnum $platform) |
| 10 | * @method static updateOrCreate(array<string, mixed> $array, array<string, mixed> $array1) |
| 11 | */ |
| 12 | class PlatformChannelPost extends Model |
| 13 | { |
| 14 | protected $fillable = [ |
| 15 | 'platform', |
| 16 | 'channel_id', |
| 17 | 'channel_name', |
| 18 | 'post_id', |
| 19 | 'url', |
| 20 | 'title', |
| 21 | 'posted_at', |
| 22 | ]; |
| 23 | |
| 24 | /** |
| 25 | * @return array<string, string> |
| 26 | */ |
| 27 | protected function casts(): array |
| 28 | { |
| 29 | return [ |
| 30 | 'posted_at' => 'datetime', |
| 31 | 'platform' => PlatformEnum::class, |
| 32 | ]; |
| 33 | } |
| 34 | |
| 35 | public static function urlExists(PlatformEnum $platform, string $channelId, string $url): bool |
| 36 | { |
| 37 | return self::where('platform', $platform) |
| 38 | ->where('channel_id', $channelId) |
| 39 | ->where('url', $url) |
| 40 | ->exists(); |
| 41 | } |
| 42 | |
| 43 | public static function storePost(PlatformEnum $platform, string $channelId, ?string $channelName, string $postId, ?string $url, ?string $title, ?\DateTime $postedAt = null): self |
| 44 | { |
| 45 | return self::updateOrCreate( |
| 46 | [ |
| 47 | 'platform' => $platform, |
| 48 | 'channel_id' => $channelId, |
| 49 | 'post_id' => $postId, |
| 50 | ], |
| 51 | [ |
| 52 | 'channel_name' => $channelName, |
| 53 | 'url' => $url, |
| 54 | 'title' => $title, |
| 55 | 'posted_at' => $postedAt ?? now(), |
| 56 | ] |
| 57 | ); |
| 58 | } |
| 59 | } |