Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
5 / 6
80.00% covered (warning)
80.00%
4 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
PromptLengthOfPostRepository
83.33% covered (warning)
83.33%
5 / 6
80.00% covered (warning)
80.00%
4 / 5
5.12
0.00% covered (danger)
0.00%
0 / 1
 getAll
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 findById
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 create
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 update
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 delete
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Http\Repositories;
4
5use App\Http\Models\PromptLengthOfPost;
6use App\Http\Repositories\interfaces\IPromptLengthOfPostRepository;
7use Illuminate\Support\Collection;
8
9/**
10 * Repository for prompt length of post data access operations.
11 *
12 * Handles all database queries related to prompt length of posts,
13 * keeping data access logic separate from business logic.
14 */
15class PromptLengthOfPostRepository implements IPromptLengthOfPostRepository
16{
17    /**
18     * Get all prompt length of posts ordered by newest first.
19     *
20     * @return Collection<int, PromptLengthOfPost> Collection of lengths
21     */
22    public function getAll(): Collection
23    {
24        return PromptLengthOfPost::query()->orderBy('created_at', 'desc')->get();
25    }
26
27    /**
28     * Find a prompt length of post by its ID.
29     *
30     * @param  string  $id  The length ID
31     * @return PromptLengthOfPost|null The length or null if not found
32     */
33    public function findById(string $id): ?PromptLengthOfPost
34    {
35        return PromptLengthOfPost::find($id);
36    }
37
38    /**
39     * Create a new prompt length of post.
40     *
41     * @param  array  $data  The length data
42     * @return PromptLengthOfPost The created length
43     */
44    public function create(array $data): PromptLengthOfPost
45    {
46        return PromptLengthOfPost::create($data);
47    }
48
49    /**
50     * Update an existing prompt length of post.
51     *
52     * @param  PromptLengthOfPost  $promptLengthOfPost  The length to update
53     * @param  array  $data  The update data
54     * @return PromptLengthOfPost The updated length
55     */
56    public function update(PromptLengthOfPost $promptLengthOfPost, array $data): PromptLengthOfPost
57    {
58        $promptLengthOfPost->update($data);
59
60        return $promptLengthOfPost->fresh();
61    }
62
63    /**
64     * Delete a prompt length of post.
65     *
66     * @param  PromptLengthOfPost  $promptLengthOfPost  The length to delete
67     * @return bool True if deleted successfully
68     */
69    public function delete(PromptLengthOfPost $promptLengthOfPost): bool
70    {
71        return $promptLengthOfPost->delete();
72    }
73}