zaherkhirullah /
laravel-visits
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Hayrullah\LaravelVisits\Traits; |
||||
| 4 | |||||
| 5 | use Hayrullah\LaravelVisits\Models\Like; |
||||
|
0 ignored issues
–
show
|
|||||
| 6 | use Illuminate\Database\Eloquent\Collection; |
||||
| 7 | use Illuminate\Database\Eloquent\Relations\HasMany; |
||||
| 8 | |||||
| 9 | /** |
||||
| 10 | * This file is part of Laravel visits,. |
||||
| 11 | * |
||||
| 12 | * @license MIT |
||||
| 13 | */ |
||||
| 14 | trait Visitability |
||||
| 15 | { |
||||
| 16 | /** |
||||
| 17 | * Define a one-to-many relationship. |
||||
| 18 | * |
||||
| 19 | * @return HasMany |
||||
| 20 | */ |
||||
| 21 | public function visits() |
||||
| 22 | { |
||||
| 23 | return $this->hasMany(Like::class, 'user_id'); |
||||
|
0 ignored issues
–
show
It seems like
hasMany() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 24 | } |
||||
| 25 | |||||
| 26 | /** |
||||
| 27 | * Return a collection with the User visitsd Model. |
||||
| 28 | * The Model needs to have the visitsable trait. |
||||
| 29 | * |
||||
| 30 | * @param $class *** Accepts for example: Post::class or 'App\Post' **** |
||||
| 31 | * |
||||
| 32 | * @return Collection |
||||
| 33 | */ |
||||
| 34 | public function visitors($class) |
||||
| 35 | { |
||||
| 36 | return $this->visits()->where('visitable_type', $class)->with('visitable')->get()->mapWithKeys(function ($item) { |
||||
| 37 | if (isset($item['visitable'])) { |
||||
| 38 | return [$item['visitable']->id => $item['visitable']]; |
||||
| 39 | } |
||||
| 40 | |||||
| 41 | return []; |
||||
| 42 | }); |
||||
| 43 | } |
||||
| 44 | |||||
| 45 | /** |
||||
| 46 | * Add the object to the User visits. |
||||
| 47 | * The Model needs to have the visitsable trai. |
||||
| 48 | * |
||||
| 49 | * @param object $object |
||||
| 50 | */ |
||||
| 51 | public function addVisit($object) |
||||
| 52 | { |
||||
| 53 | $object->addVisit($this->id); |
||||
| 54 | } |
||||
| 55 | |||||
| 56 | /** |
||||
| 57 | * Remove the Object from the user visits. |
||||
| 58 | * The Model needs to have the visitable trai. |
||||
| 59 | * |
||||
| 60 | * @param object $object |
||||
| 61 | */ |
||||
| 62 | public function removeVisit($object) |
||||
| 63 | { |
||||
| 64 | $object->removeVisit($this->id); |
||||
| 65 | } |
||||
| 66 | |||||
| 67 | /** |
||||
| 68 | * Toggle the visits status from this Object from the user visits. |
||||
| 69 | * The Model needs to have the visitable trai. |
||||
| 70 | * |
||||
| 71 | * @param object $object |
||||
| 72 | */ |
||||
| 73 | public function toggleVisit($object) |
||||
| 74 | { |
||||
| 75 | $object->toggleVisits($this->id); |
||||
| 76 | } |
||||
| 77 | |||||
| 78 | /** |
||||
| 79 | * Check if the user has visits this Object |
||||
| 80 | * The Model needs to have the visitable trai. |
||||
| 81 | * |
||||
| 82 | * @param object $object |
||||
| 83 | * |
||||
| 84 | * @return bool |
||||
| 85 | */ |
||||
| 86 | public function isVisited($object) |
||||
| 87 | { |
||||
| 88 | return $object->isVisited($this->id); |
||||
| 89 | } |
||||
| 90 | |||||
| 91 | /** |
||||
| 92 | * Check if the user has visited this Object |
||||
| 93 | * The Model needs to have the visitable trai. |
||||
| 94 | * |
||||
| 95 | * @param object $object |
||||
| 96 | * |
||||
| 97 | * @return bool |
||||
| 98 | */ |
||||
| 99 | public function hasVisit($object) |
||||
| 100 | { |
||||
| 101 | return $object->isvisitsd($this->id); |
||||
| 102 | } |
||||
| 103 | } |
||||
| 104 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths