Skip to content

Commit 599d6a9

Browse files
committed
cleanup/optimizations
1 parent b627d71 commit 599d6a9

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

src/Models/Models.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ public static function setTables(array $map)
8383
*/
8484
public static function table($table)
8585
{
86-
if (isset(static::$tables[$table])) {
87-
return static::$tables[$table];
88-
}
89-
90-
return $table;
86+
return static::$tables[$table] ?? $table;
9187
}
9288

9389
/**
@@ -98,11 +94,7 @@ public static function table($table)
9894
*/
9995
public static function classname($model)
10096
{
101-
if (isset(static::$models[$model])) {
102-
return static::$models[$model];
103-
}
104-
105-
return $model;
97+
return static::$models[$model] ?? $model;
10698
}
10799

108100
/**

src/Models/Thread.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class Thread extends Eloquent
3636
/**
3737
* Internal cache for creator.
3838
*
39-
* @var null|Models::user()
39+
* @var null|Models::user()|\Illuminate\Database\Eloquent\Model
4040
*/
41-
protected $creatorCache = null;
41+
protected $creatorCache;
4242

4343
/**
4444
* {@inheritDoc}
@@ -99,11 +99,11 @@ public function users()
9999
/**
100100
* Returns the user object that created the thread.
101101
*
102-
* @return Models::user()
102+
* @return null|Models::user()|\Illuminate\Database\Eloquent\Model
103103
*/
104104
public function creator()
105105
{
106-
if (is_null($this->creatorCache)) {
106+
if ($this->creatorCache === null) {
107107
$firstMessage = $this->messages()->withTrashed()->oldest()->first();
108108
$this->creatorCache = $firstMessage ? $firstMessage->user : Models::user();
109109
}
@@ -136,12 +136,13 @@ public static function getBySubject($subject)
136136
/**
137137
* Returns an array of user ids that are associated with the thread.
138138
*
139-
* @param null $userId
139+
* @param null|int $userId
140140
*
141141
* @return array
142142
*/
143143
public function participantsUserIds($userId = null)
144144
{
145+
/** @var \Illuminate\Support\Collection $users */
145146
$users = $this->participants()->withTrashed()->select('user_id')->get()->map(function ($participant) {
146147
return $participant->user_id;
147148
});
@@ -351,11 +352,8 @@ public function participantsString($userId = null, $columns = ['name'])
351352
public function hasParticipant($userId)
352353
{
353354
$participants = $this->participants()->where('user_id', '=', $userId);
354-
if ($participants->count() > 0) {
355-
return true;
356-
}
357355

358-
return false;
356+
return $participants->count() > 0;
359357
}
360358

361359
/**

0 commit comments

Comments
 (0)