Skip to content

Commit

Permalink
Merge branch 'master' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
cmgmyr committed Jan 21, 2022
2 parents 8320099 + b7f205b commit 4ba8e3a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 48 deletions.
12 changes: 6 additions & 6 deletions src/MessengerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MessengerServiceProvider extends ServiceProvider
* @return void
* @throws BindingResolutionException
*/
public function boot(): void
public function boot()
{
$this->offerPublishing();
$this->setMessengerModels();
Expand All @@ -29,7 +29,7 @@ public function boot(): void
*
* @return void
*/
public function register(): void
public function register()
{
$this->configure();
}
Expand All @@ -39,7 +39,7 @@ public function register(): void
*
* @return void
*/
protected function configure(): void
protected function configure()
{
$this->mergeConfigFrom(
__DIR__ . '/../config/config.php',
Expand All @@ -52,7 +52,7 @@ protected function configure(): void
*
* @return void
*/
protected function offerPublishing(): void
protected function offerPublishing()
{
if ($this->app->runningInConsole()) {
$this->publishes([
Expand All @@ -71,7 +71,7 @@ protected function offerPublishing(): void
* @return void
* @throws BindingResolutionException
*/
protected function setMessengerModels(): void
protected function setMessengerModels()
{
$config = $this->app->make('config');

Expand All @@ -92,7 +92,7 @@ protected function setMessengerModels(): void
* @return void
* @throws BindingResolutionException
*/
protected function setUserModel(): void
protected function setUserModel()
{
$config = $this->app->make('config');

Expand Down
10 changes: 5 additions & 5 deletions src/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(array $attributes = [])
*
* @codeCoverageIgnore
*/
public function thread(): BelongsTo
public function thread()
{
return $this->belongsTo(Models::classname(Thread::class), 'thread_id', 'id');
}
Expand All @@ -72,7 +72,7 @@ public function thread(): BelongsTo
*
* @codeCoverageIgnore
*/
public function user(): BelongsTo
public function user()
{
return $this->belongsTo(Models::user(), 'user_id');
}
Expand All @@ -84,7 +84,7 @@ public function user(): BelongsTo
*
* @codeCoverageIgnore
*/
public function participants(): HasMany
public function participants()
{
return $this->hasMany(Models::classname(Participant::class), 'thread_id', 'thread_id');
}
Expand All @@ -94,7 +94,7 @@ public function participants(): HasMany
*
* @return HasMany
*/
public function recipients(): HasMany
public function recipients()
{
return $this->participants()->where('user_id', '!=', $this->user_id);
}
Expand All @@ -106,7 +106,7 @@ public function recipients(): HasMany
* @param mixed $userId
* @return Builder
*/
public function scopeUnreadForUser(Builder $query, $userId): Builder
public function scopeUnreadForUser(Builder $query, $userId)
{
return $query->has('thread')
->where('user_id', '!=', $userId)
Expand Down
18 changes: 9 additions & 9 deletions src/Models/Models.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Models
*
* @param string $model
*/
public static function setMessageModel(string $model): void
public static function setMessageModel($model)
{
static::$models[Message::class] = $model;
}
Expand All @@ -42,7 +42,7 @@ public static function setMessageModel(string $model): void
*
* @param string $model
*/
public static function setParticipantModel(string $model): void
public static function setParticipantModel($model)
{
static::$models[Participant::class] = $model;
}
Expand All @@ -52,7 +52,7 @@ public static function setParticipantModel(string $model): void
*
* @param string $model
*/
public static function setThreadModel(string $model): void
public static function setThreadModel($model)
{
static::$models[Thread::class] = $model;
}
Expand All @@ -62,7 +62,7 @@ public static function setThreadModel(string $model): void
*
* @param string $model
*/
public static function setUserModel(string $model): void
public static function setUserModel($model)
{
static::$models[self::$userModelLookupKey] = $model;
}
Expand All @@ -72,7 +72,7 @@ public static function setUserModel(string $model): void
*
* @param array $map
*/
public static function setTables(array $map): void
public static function setTables(array $map)
{
static::$tables = array_merge(static::$tables, $map);
}
Expand All @@ -83,7 +83,7 @@ public static function setTables(array $map): void
* @param string $table
* @return string
*/
public static function table(string $table): string
public static function table($table)
{
return static::$tables[$table] ?? $table;
}
Expand All @@ -94,7 +94,7 @@ public static function table(string $table): string
* @param string $model
* @return string
*/
public static function classname(string $model): string
public static function classname($model)
{
return static::$models[$model] ?? $model;
}
Expand Down Expand Up @@ -138,7 +138,7 @@ public static function thread(array $attributes = [])
* @param array $attributes
* @return Model
*/
public static function user(array $attributes = []): Model
public static function user(array $attributes = [])
{
return static::make(self::$userModelLookupKey, $attributes);
}
Expand All @@ -150,7 +150,7 @@ public static function user(array $attributes = []): Model
* @param array $attributes
* @return Model
*/
protected static function make(string $model, array $attributes = []): Model
protected static function make($model, array $attributes = [])
{
$model = static::classname($model);

Expand Down
4 changes: 2 additions & 2 deletions src/Models/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(array $attributes = [])
*
* @codeCoverageIgnore
*/
public function thread(): BelongsTo
public function thread()
{
return $this->belongsTo(Models::classname(Thread::class), 'thread_id', 'id');
}
Expand All @@ -60,7 +60,7 @@ public function thread(): BelongsTo
*
* @codeCoverageIgnore
*/
public function user(): BelongsTo
public function user()
{
return $this->belongsTo(Models::user(), 'user_id');
}
Expand Down
40 changes: 20 additions & 20 deletions src/Models/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __construct(array $attributes = [])
*
* @codeCoverageIgnore
*/
public function messages(): HasMany
public function messages()
{
return $this->hasMany(Models::classname(Message::class), 'thread_id', 'id');
}
Expand All @@ -88,7 +88,7 @@ public function getLatestMessageAttribute()
*
* @codeCoverageIgnore
*/
public function participants(): HasMany
public function participants()
{
return $this->hasMany(Models::classname(Participant::class), 'thread_id', 'id');
}
Expand All @@ -100,7 +100,7 @@ public function participants(): HasMany
*
* @codeCoverageIgnore
*/
public function users(): BelongsToMany
public function users()
{
return $this->belongsToMany(Models::classname('User'), Models::table('participants'), 'thread_id', 'user_id');
}
Expand All @@ -110,7 +110,7 @@ public function users(): BelongsToMany
*
* @return null|Models::user()|\Illuminate\Database\Eloquent\Model
*/
public function creator(): ?Eloquent
public function creator()
{
if ($this->creatorCache === null) {
$firstMessage = $this->messages()->withTrashed()->oldest()->first();
Expand All @@ -137,7 +137,7 @@ public static function getAllLatest()
*
* @return Collection|static[]
*/
public static function getBySubject(string $subject)
public static function getBySubject($subject)
{
return static::where('subject', 'like', $subject)->get();
}
Expand All @@ -149,7 +149,7 @@ public static function getBySubject(string $subject)
*
* @return array
*/
public function participantsUserIds($userId = null): array
public function participantsUserIds($userId = null)
{
$users = $this->participants()->withTrashed()->select('user_id')->get()->map(function ($participant) {
return $participant->user_id;
Expand All @@ -170,7 +170,7 @@ public function participantsUserIds($userId = null): array
*
* @return Builder
*/
public function scopeForUser(Builder $query, $userId): Builder
public function scopeForUser(Builder $query, $userId)
{
$participantsTable = Models::table('participants');
$threadsTable = Models::table('threads');
Expand All @@ -189,7 +189,7 @@ public function scopeForUser(Builder $query, $userId): Builder
*
* @return Builder
*/
public function scopeForUserWithNewMessages(Builder $query, $userId): Builder
public function scopeForUserWithNewMessages(Builder $query, $userId)
{
$participantTable = Models::table('participants');
$threadsTable = Models::table('threads');
Expand All @@ -212,7 +212,7 @@ public function scopeForUserWithNewMessages(Builder $query, $userId): Builder
*
* @return Builder
*/
public function scopeBetweenOnly(Builder $query, array $participants): Builder
public function scopeBetweenOnly(Builder $query, array $participants)
{
return $query->whereHas('participants', function (Builder $builder) use ($participants) {
return $builder->whereIn('user_id', $participants)
Expand All @@ -230,7 +230,7 @@ public function scopeBetweenOnly(Builder $query, array $participants): Builder
*
* @return Builder
*/
public function scopeBetween(Builder $query, array $participants): Builder
public function scopeBetween(Builder $query, array $participants)
{
return $query->whereHas('participants', function (Builder $q) use ($participants) {
$q->whereIn('user_id', $participants)
Expand All @@ -247,7 +247,7 @@ public function scopeBetween(Builder $query, array $participants): Builder
*
* @return void
*/
public function addParticipant($userId): void
public function addParticipant($userId)
{
$userIds = is_array($userId) ? $userId : func_get_args();

Expand All @@ -266,7 +266,7 @@ public function addParticipant($userId): void
*
* @return void
*/
public function removeParticipant($userId): void
public function removeParticipant($userId)
{
$userIds = is_array($userId) ? $userId : func_get_args();

Expand All @@ -280,7 +280,7 @@ public function removeParticipant($userId): void
*
* @return void
*/
public function markAsRead($userId): void
public function markAsRead($userId)
{
try {
$participant = $this->getParticipantFromUser($userId);
Expand All @@ -298,7 +298,7 @@ public function markAsRead($userId): void
*
* @return bool
*/
public function isUnread($userId): bool
public function isUnread($userId)
{
try {
$participant = $this->getParticipantFromUser($userId);
Expand Down Expand Up @@ -333,7 +333,7 @@ public function getParticipantFromUser($userId)
*
* @return void
*/
public function activateAllParticipants(): void
public function activateAllParticipants()
{
$participants = $this->participants()->onlyTrashed()->get();
foreach ($participants as $participant) {
Expand All @@ -349,7 +349,7 @@ public function activateAllParticipants(): void
*
* @return string
*/
public function participantsString($userId = null, array $columns = ['name']): string
public function participantsString($userId = null, $columns = ['name'])
{
$participantsTable = Models::table('participants');
$usersTable = Models::table('users');
Expand All @@ -376,7 +376,7 @@ public function participantsString($userId = null, array $columns = ['name']): s
*
* @return bool
*/
public function hasParticipant($userId): bool
public function hasParticipant($userId)
{
$participants = $this->participants()->where('user_id', '=', $userId);

Expand All @@ -390,7 +390,7 @@ public function hasParticipant($userId): bool
*
* @return string
*/
protected function createSelectString(array $columns): string
protected function createSelectString($columns)
{
$dbDriver = $this->getConnection()->getDriverName();
$tablePrefix = $this->getConnection()->getTablePrefix();
Expand Down Expand Up @@ -423,7 +423,7 @@ protected function createSelectString(array $columns): string
*
* @return Collection
*/
public function userUnreadMessages($userId): Collection
public function userUnreadMessages($userId)
{
$messages = $this->messages()->where('user_id', '!=', $userId)->get();

Expand All @@ -449,7 +449,7 @@ public function userUnreadMessages($userId): Collection
*
* @return int
*/
public function userUnreadMessagesCount($userId): int
public function userUnreadMessagesCount($userId)
{
return $this->userUnreadMessages($userId)->count();
}
Expand Down
Loading

0 comments on commit 4ba8e3a

Please sign in to comment.