diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..937d029 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,55 @@ +# Contributing + +Contributions are **welcome** and will be fully **credited**. + +Please read and understand the contribution guide before creating an issue or pull request. + +## Etiquette + +This project is open source, and as such, the maintainers give their free time to build and maintain the source code +held within. They make the code freely available in the hope that it will be of use to other developers. It would be +extremely unfair for them to suffer abuse or anger for their hard work. + +Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the +world that developers are civilized and selfless people. + +It's the duty of the maintainer to ensure that all submissions to the project are of sufficient +quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. + +## Viability + +When requesting or submitting new features, first consider whether it might be useful to others. Open +source projects are used by many developers, who may have entirely different needs to your own. Think about +whether or not your feature is likely to be used by other users of the project. + +## Procedure + +Before filing an issue: + +- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. +- Check to make sure your feature suggestion isn't already present within the project. +- Check the pull requests tab to ensure that the bug doesn't have a fix in progress. +- Check the pull requests tab to ensure that the feature isn't already in progress. + +Before submitting a pull request: + +- Check the codebase to ensure that your feature doesn't already exist. +- Check the pull requests to ensure that another person hasn't already submitted the feature or fix. + +## Requirements + +If the project maintainer has any additional requirements, you will find them listed here. + +- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). + +- **Add tests!** - Your patch won't be accepted if it doesn't have tests. + +- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. + +- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. + +- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. + +- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. + +**Happy coding**! \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..f423a56 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,14 @@ +blank_issues_enabled: false +contact_links: + - name: Ask a question + url: https://github.com/cmgmyr/laravel-messenger/discussions/new?category=q-a + about: Ask the community for help + - name: Request a feature + url: https://github.com/cmgmyr/laravel-messenger/discussions/new?category=ideas + about: Share ideas for new features + - name: Report a security issue + url: https://github.com/cmgmyr/laravel-messenger/security/policy + about: Learn how to notify us for sensitive bugs + - name: Report a bug + url: https://github.com/cmgmyr/laravel-messenger/issues/new + about: Report a reproducable bug \ No newline at end of file diff --git a/.github/SECURITY.md b/.github/SECURITY.md new file mode 100644 index 0000000..0078d84 --- /dev/null +++ b/.github/SECURITY.md @@ -0,0 +1,3 @@ +# Security Policy + +If you discover any security related issues, please email cmgmyr@gmail.com instead of using the issue tracker. \ No newline at end of file diff --git a/.github/stale.yml b/.github/stale.yml deleted file mode 100644 index f4ca6fc..0000000 --- a/.github/stale.yml +++ /dev/null @@ -1,26 +0,0 @@ -# Configuration for probot-stale - https://github.com/probot/stale - -# Number of days of inactivity before an Issue or Pull Request becomes stale -daysUntilStale: 60 - -# Number of days of inactivity before an Issue or Pull Request with the stale label is closed. -# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale. -daysUntilClose: 7 - -# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable -exemptLabels: - - bug - - feedback - - "in progress" - -# Label to use when marking as stale -staleLabel: stale - -# Comment to post when marking as stale. Set to `false` to disable -markComment: > - This issue has been automatically marked as stale because it has not had - recent activity. It will be closed if no further activity occurs. Thank you - for your contributions. - -# Limit to only `issues` or `pulls` -only: issues \ No newline at end of file diff --git a/.github/workflows/run-tests-mysql.yml b/.github/workflows/run-tests-mysql.yml index 6a99aa7..40dfefa 100644 --- a/.github/workflows/run-tests-mysql.yml +++ b/.github/workflows/run-tests-mysql.yml @@ -1,14 +1,6 @@ name: Laravel Messenger - MySQL Tests -on: - push: - branches: - - master - - develop - - feature/** - pull_request: - branches: - - master - - develop + +on: [push, pull_request] jobs: laravel-tests: @@ -36,7 +28,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest] - php-versions: [ '8.0' ] + php-versions: [ '8.1','8.0' ] dependency-stability: [ prefer-stable ] laravel: [ '8.*' ] diff --git a/.github/workflows/run-tests-postgres.yml b/.github/workflows/run-tests-postgres.yml index 779f6ce..b9d7a0c 100644 --- a/.github/workflows/run-tests-postgres.yml +++ b/.github/workflows/run-tests-postgres.yml @@ -1,14 +1,6 @@ name: Laravel Messenger - PostgreSQL Tests -on: - push: - branches: - - master - - develop - - feature/** - pull_request: - branches: - - master - - develop + +on: [push, pull_request] jobs: laravel-tests: @@ -37,7 +29,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest] - php-versions: [ '8.0' ] + php-versions: [ '8.1','8.0' ] dependency-stability: [ prefer-stable ] laravel: [ '8.*' ] diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 8149304..9864f84 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,14 +1,6 @@ name: Laravel Messenger - Tests -on: - push: - branches: - - master - - develop - - feature/** - pull_request: - branches: - - master - - develop + +on: [push, pull_request] jobs: laravel-tests: @@ -18,7 +10,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest] - php-versions: [ '8.0','7.4','7.3','7.2' ] + php-versions: [ '8.1','8.0','7.4','7.3','7.2' ] dependency-stability: [ prefer-stable ] laravel: [ '8.*','7.*','6.*' ] @@ -37,8 +29,12 @@ jobs: php-versions: 7.3 - laravel: 8.* php-versions: 7.2 + - laravel: 7.* + php-versions: 8.1 - laravel: 7.* php-versions: 8.0 + - laravel: 6.* + php-versions: 8.1 - laravel: 6.* php-versions: 8.0 diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 6a40a45..fc933eb 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -8,55 +8,109 @@ ->ignoreDotFiles(true) ->ignoreVCS(true); -return (new PhpCsFixer\Config) +return (new PhpCsFixer\Config()) ->setRiskyAllowed(true) ->setRules([ - '@PSR1' => false, - '@PSR2' => true, + '@PSR12' => true, /** - * symfony + * Array Notation. + */ + // PHP arrays should be declared using the configured syntax. + 'array_syntax' => ['syntax' => 'short'], + + /** + * Cast Notation. + */ + // A single space should be between cast and variable. + 'cast_spaces' => true, + + /** + * Class Notation. + */ + // Methods must be separated with one blank line. + 'class_attributes_separation' => true, + + /** + * Control Structure. */ - // Ensure there is no code on the same line as the PHP open tag and it is followed by a blankline. - 'blank_line_after_opening_tag' => true, - // Remove duplicated semicolons. - 'no_empty_statement' => true, // PHP multi-line arrays should have a trailing comma. 'trailing_comma_in_multiline' => true, - // There should be no empty lines after class opening brace. - 'no_blank_lines_after_class_opening' => true, + + /** + * Function Notation. + */ + // In method arguments and method call, there MUST NOT be a space before each comma and there MUST be one space after each comma. Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one argument per line. + 'method_argument_space' => [ + 'on_multiline' => 'ensure_fully_multiline', + 'keep_multiple_spaces_after_comma' => true, + ], + + /** + * Import. + */ + // Unused use statements must be removed. + 'no_unused_imports' => true, + // Ordering use statements. + 'ordered_imports' => ['sort_algorithm' => 'alpha'], + // Transforms imported FQCN parameters and return types in function arguments to short version. + 'fully_qualified_strict_types' => true, + // Imports or fully qualifies global classes/functions/constants. + 'global_namespace_import' => [ + 'import_classes' => true, + 'import_constants' => null, + 'import_functions' => null, + ], + + /** + * Operator. + */ + // Unary operators should be placed adjacent to their operands. + 'unary_operator_spaces' => true, + // Binary operators should be surrounded by at least one space. + 'binary_operator_spaces' => true, + // Concatenation should be used with at least one whitespace around. + 'concat_space' => ['spacing' => 'one'], + // Logical NOT operators `(!)` should have one trailing whitespace. + 'not_operator_with_successor_space' => true, + + /** + * PHPDoc. + */ + // Scalar types should always be written in the same form. int not integer, bool not boolean, float not real or double. + 'phpdoc_scalar' => true, + // Single line @var PHPDoc should have proper spacing. + 'phpdoc_single_line_var_spacing' => true, + // @var and @type annotations of classy properties should not contain the name. + 'phpdoc_var_without_name' => true, // There should not be blank lines between docblock and the documented element. 'no_blank_lines_after_phpdoc' => true, // Phpdocs short descriptions should end in either a full stop, exclamation mark, or question mark. 'phpdoc_summary' => true, // Phpdocs should start and end with content, excluding the very first and last line of the docblocks. 'phpdoc_trim' => true, - // Removes line breaks between use statements. - 'no_extra_blank_lines' => ['tokens' => ['use']], - // An empty line feed should precede a return statement. - 'blank_line_before_statement' => true, - // There should be exactly one blank line before a namespace declaration. - 'single_blank_line_before_namespace' => true, + + /** + * Semicolon. + */ + // Remove duplicated semicolons. + 'no_empty_statement' => true, + + /** + * String Notation. + */ // Convert double quotes to single quotes for simple strings. 'single_quote' => true, - // Unused use statements must be removed. - 'no_unused_imports' => true, - // Methods must be separated with one blank line. - 'class_attributes_separation' => true, - // Binary operators should be surrounded by at least one space. - 'binary_operator_spaces' => ['operators' => ['=>' => 'single_space']], - // A single space should be between cast and variable. - 'cast_spaces' => true, /** - * contrib + * Whitespace. */ - // Concatenation should be used with at least one whitespace around. - 'concat_space' => ['spacing' => 'one'], - // Ordering use statements. - 'ordered_imports' => true, - // PHP arrays should be declared using the configured syntax. - 'array_syntax' => ['syntax' => 'short'] + // An empty line feed should precede a return statement. + 'blank_line_before_statement' => [ + 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], + ], + // Removes line breaks between use statements. + 'no_extra_blank_lines' => ['tokens' => ['use']], ]) ->setFinder($finder) ->setUsingCache(true); diff --git a/examples/MessagesController.php b/examples/MessagesController.php index cad0bc9..95b66aa 100644 --- a/examples/MessagesController.php +++ b/examples/MessagesController.php @@ -97,7 +97,7 @@ public function store() Participant::create([ 'thread_id' => $thread->id, 'user_id' => Auth::id(), - 'last_read' => new Carbon, + 'last_read' => new Carbon(), ]); // Recipients @@ -138,7 +138,7 @@ public function update($id) 'thread_id' => $thread->id, 'user_id' => Auth::id(), ]); - $participant->last_read = new Carbon; + $participant->last_read = new Carbon(); $participant->save(); // Recipients diff --git a/readme.md b/readme.md index c77ec31..adfa10c 100644 --- a/readme.md +++ b/readme.md @@ -119,16 +119,13 @@ class User extends Authenticatable { * [WIP] [Lumen API](https://github.com/cmgmyr/lumen-messenger-api) -## Contributing? -Please format your code before creating a pull-request. This will format all files as specified in `.php_cs`: +## Contributing -``` -vendor/bin/php-cs-fixer fix . -``` +Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details. -## Security +## Security Vulnerabilities -If you discover any security related issues, please email [Chris Gmyr](mailto:cmgmyr@gmail.com) instead of using the issue tracker. +Please review [our security policy](../../security/policy) on how to report security vulnerabilities. ## Credits diff --git a/src/MessengerServiceProvider.php b/src/MessengerServiceProvider.php index 09dc816..199a636 100644 --- a/src/MessengerServiceProvider.php +++ b/src/MessengerServiceProvider.php @@ -6,6 +6,7 @@ use Cmgmyr\Messenger\Models\Models; use Cmgmyr\Messenger\Models\Participant; use Cmgmyr\Messenger\Models\Thread; +use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Support\ServiceProvider; class MessengerServiceProvider extends ServiceProvider @@ -14,6 +15,7 @@ class MessengerServiceProvider extends ServiceProvider * Bootstrap the application services. * * @return void + * @throws BindingResolutionException */ public function boot(): void { @@ -33,7 +35,7 @@ public function register(): void } /** - * Setup the configuration for Messenger. + * Set up the configuration for Messenger. * * @return void */ @@ -46,7 +48,7 @@ protected function configure(): void } /** - * Setup the resource publishing groups for Messenger. + * Set up the resource publishing groups for Messenger. * * @return void */ @@ -67,7 +69,7 @@ protected function offerPublishing(): void * Define Messenger's models in registry. * * @return void - * @throws \Illuminate\Contracts\Container\BindingResolutionException + * @throws BindingResolutionException */ protected function setMessengerModels(): void { @@ -88,7 +90,7 @@ protected function setMessengerModels(): void * Define User model in Messenger's model registry. * * @return void - * @throws \Illuminate\Contracts\Container\BindingResolutionException + * @throws BindingResolutionException */ protected function setUserModel(): void { @@ -101,7 +103,7 @@ protected function setUserModel(): void Models::setUserModel($model); Models::setTables([ - 'users' => (new $model)->getTable(), + 'users' => (new $model())->getTable(), ]); } } diff --git a/src/Models/Message.php b/src/Models/Message.php index e7e079e..be445dd 100644 --- a/src/Models/Message.php +++ b/src/Models/Message.php @@ -9,9 +9,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; /** - * Class Message. - * - * @method static Builder|self unreadForUser(int $userId) + * @method static Builder|self unreadForUser(mixed $userId) */ class Message extends Eloquent { @@ -58,7 +56,7 @@ public function __construct(array $attributes = []) /** * Thread relationship. * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo * * @codeCoverageIgnore */ @@ -70,7 +68,7 @@ public function thread(): BelongsTo /** * User relationship. * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo * * @codeCoverageIgnore */ @@ -82,7 +80,7 @@ public function user(): BelongsTo /** * Participants relationship. * - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany * * @codeCoverageIgnore */ @@ -94,7 +92,7 @@ public function participants(): HasMany /** * Recipients of this message. * - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ public function recipients(): HasMany { @@ -104,11 +102,11 @@ public function recipients(): HasMany /** * Returns unread messages given the userId. * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param int $userId - * @return \Illuminate\Database\Eloquent\Builder + * @param Builder $query + * @param mixed $userId + * @return Builder */ - public function scopeUnreadForUser(Builder $query, int $userId): Builder + public function scopeUnreadForUser(Builder $query, $userId): Builder { return $query->has('thread') ->where('user_id', '!=', $userId) diff --git a/src/Models/Models.php b/src/Models/Models.php index fc93db5..a9cd7e7 100644 --- a/src/Models/Models.php +++ b/src/Models/Models.php @@ -40,7 +40,7 @@ public static function setMessageModel(string $model): void /** * Set the model to be used for participants. * - * @param string $model + * @param string $model */ public static function setParticipantModel(string $model): void { @@ -50,7 +50,7 @@ public static function setParticipantModel(string $model): void /** * Set the model to be used for threads. * - * @param string $model + * @param string $model */ public static function setThreadModel(string $model): void { @@ -60,7 +60,7 @@ public static function setThreadModel(string $model): void /** * Set the model to be used for users. * - * @param string $model + * @param string $model */ public static function setUserModel(string $model): void { @@ -70,7 +70,7 @@ public static function setUserModel(string $model): void /** * Set custom table names. * - * @param array $map + * @param array $map */ public static function setTables(array $map): void { @@ -80,7 +80,7 @@ public static function setTables(array $map): void /** * Get a custom table name mapping for the given table. * - * @param string $table + * @param string $table * @return string */ public static function table(string $table): string @@ -91,7 +91,7 @@ public static function table(string $table): string /** * Get the class name mapping for the given model. * - * @param string $model + * @param string $model * @return string */ public static function classname(string $model): string @@ -103,9 +103,9 @@ public static function classname(string $model): string * Get an instance of the messages model. * * @param array $attributes - * @return \Cmgmyr\Messenger\Models\Message + * @return Message|Model */ - public static function message(array $attributes = []): Message + public static function message(array $attributes = []) { return static::make(Message::class, $attributes); } @@ -114,9 +114,9 @@ public static function message(array $attributes = []): Message * Get an instance of the participants model. * * @param array $attributes - * @return \Cmgmyr\Messenger\Models\Participant + * @return Participant|Model */ - public static function participant(array $attributes = []): Participant + public static function participant(array $attributes = []) { return static::make(Participant::class, $attributes); } @@ -125,9 +125,9 @@ public static function participant(array $attributes = []): Participant * Get an instance of the threads model. * * @param array $attributes - * @return \Cmgmyr\Messenger\Models\Thread + * @return Thread|Model */ - public static function thread(array $attributes = []): Thread + public static function thread(array $attributes = []) { return static::make(Thread::class, $attributes); } @@ -136,7 +136,7 @@ public static function thread(array $attributes = []): Thread * Get an instance of the user model. * * @param array $attributes - * @return \Illuminate\Database\Eloquent\Model + * @return Model */ public static function user(array $attributes = []): Model { @@ -148,7 +148,7 @@ public static function user(array $attributes = []): Model * * @param string $model * @param array $attributes - * @return \Illuminate\Database\Eloquent\Model + * @return Model */ protected static function make(string $model, array $attributes = []): Model { diff --git a/src/Models/Participant.php b/src/Models/Participant.php index 90ade1d..88615d7 100644 --- a/src/Models/Participant.php +++ b/src/Models/Participant.php @@ -44,7 +44,7 @@ public function __construct(array $attributes = []) /** * Thread relationship. * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo * * @codeCoverageIgnore */ @@ -56,7 +56,7 @@ public function thread(): BelongsTo /** * User relationship. * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo * * @codeCoverageIgnore */ diff --git a/src/Models/Thread.php b/src/Models/Thread.php index f5ca4c1..44a0c24 100644 --- a/src/Models/Thread.php +++ b/src/Models/Thread.php @@ -12,12 +12,10 @@ use Illuminate\Support\Collection; /** - * Class Thread. - * * @method static Builder|self between(array $participants) * @method static Builder|self betweenOnly(array $participants) - * @method static Builder|self forUser(int $userId) - * @method static Builder|self forUserWithNewMessages(int $userId) + * @method static Builder|self forUser(mixed $userId) + * @method static Builder|self forUserWithNewMessages(mixed $userId) */ class Thread extends Eloquent { @@ -50,7 +48,7 @@ class Thread extends Eloquent * @var null|Models::user()|\Illuminate\Database\Eloquent\Model */ protected $creatorCache; - + /** * {@inheritDoc} */ @@ -64,7 +62,7 @@ public function __construct(array $attributes = []) /** * Messages relationship. * - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany * * @codeCoverageIgnore */ @@ -76,7 +74,7 @@ public function messages(): HasMany /** * Returns the latest message from a thread. * - * @return null|\Cmgmyr\Messenger\Models\Message + * @return ?Message */ public function getLatestMessageAttribute() { @@ -86,7 +84,7 @@ public function getLatestMessageAttribute() /** * Participants relationship. * - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany * * @codeCoverageIgnore */ @@ -98,7 +96,7 @@ public function participants(): HasMany /** * User's relationship. * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return BelongsToMany * * @codeCoverageIgnore */ @@ -123,9 +121,9 @@ public function creator(): ?Eloquent } /** - * Returns all of the latest threads by updated_at date. + * Returns all the latest threads by updated_at date. * - * @return \Illuminate\Database\Query\Builder|static + * @return Builder|static */ public static function getAllLatest() { @@ -137,7 +135,7 @@ public static function getAllLatest() * * @param string $subject * - * @return \Illuminate\Database\Eloquent\Collection|static[] + * @return Collection|static[] */ public static function getBySubject(string $subject) { @@ -147,11 +145,11 @@ public static function getBySubject(string $subject) /** * Returns an array of user ids that are associated with the thread. * - * @param null|int $userId + * @param mixed $userId * * @return array */ - public function participantsUserIds(?int $userId = null): array + public function participantsUserIds($userId = null): array { $users = $this->participants()->withTrashed()->select('user_id')->get()->map(function ($participant) { return $participant->user_id; @@ -167,12 +165,12 @@ public function participantsUserIds(?int $userId = null): array /** * Returns threads that the user is associated with. * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param int $userId + * @param Builder $query + * @param mixed $userId * - * @return \Illuminate\Database\Eloquent\Builder + * @return Builder */ - public function scopeForUser(Builder $query, int $userId): Builder + public function scopeForUser(Builder $query, $userId): Builder { $participantsTable = Models::table('participants'); $threadsTable = Models::table('threads'); @@ -186,12 +184,12 @@ public function scopeForUser(Builder $query, int $userId): Builder /** * Returns threads with new messages that the user is associated with. * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param int $userId + * @param Builder $query + * @param mixed $userId * - * @return \Illuminate\Database\Eloquent\Builder + * @return Builder */ - public function scopeForUserWithNewMessages(Builder $query, int $userId): Builder + public function scopeForUserWithNewMessages(Builder $query, $userId): Builder { $participantTable = Models::table('participants'); $threadsTable = Models::table('threads'); @@ -209,10 +207,10 @@ public function scopeForUserWithNewMessages(Builder $query, int $userId): Builde /** * Returns threads between given user ids. * - * @param \Illuminate\Database\Eloquent\Builder $query - * @param array $participants + * @param Builder $query + * @param array $participants * - * @return \Illuminate\Database\Eloquent\Builder + * @return Builder */ public function scopeBetweenOnly(Builder $query, array $participants): Builder { @@ -227,10 +225,10 @@ public function scopeBetweenOnly(Builder $query, array $participants): Builder /** * Returns threads between given user ids. * - * @param \Illuminate\Database\Eloquent\Builder $query + * @param Builder $query * @param array $participants * - * @return \Illuminate\Database\Eloquent\Builder + * @return Builder */ public function scopeBetween(Builder $query, array $participants): Builder { @@ -245,13 +243,13 @@ public function scopeBetween(Builder $query, array $participants): Builder /** * Add users to thread as participants. * - * @param array|mixed $userId + * @param mixed $userId * * @return void */ public function addParticipant($userId): void { - $userIds = is_array($userId) ? $userId : (array) func_get_args(); + $userIds = is_array($userId) ? $userId : func_get_args(); collect($userIds)->each(function ($userId) { Models::participant()->firstOrCreate([ @@ -264,13 +262,13 @@ public function addParticipant($userId): void /** * Remove participants from thread. * - * @param array|mixed $userId + * @param mixed $userId * * @return void */ public function removeParticipant($userId): void { - $userIds = is_array($userId) ? $userId : (array) func_get_args(); + $userIds = is_array($userId) ? $userId : func_get_args(); Models::participant()->where('thread_id', $this->id)->whereIn('user_id', $userIds)->delete(); } @@ -278,11 +276,11 @@ public function removeParticipant($userId): void /** * Mark a thread as read for a user. * - * @param int $userId + * @param mixed $userId * * @return void */ - public function markAsRead(int $userId): void + public function markAsRead($userId): void { try { $participant = $this->getParticipantFromUser($userId); @@ -296,11 +294,11 @@ public function markAsRead(int $userId): void /** * See if the current thread is unread by the user. * - * @param int $userId + * @param mixed $userId * * @return bool */ - public function isUnread(int $userId): bool + public function isUnread($userId): bool { try { $participant = $this->getParticipantFromUser($userId); @@ -318,11 +316,11 @@ public function isUnread(int $userId): bool /** * Finds the participant record from a user id. * - * @param $userId + * @param mixed $userId * * @return mixed * - * @throws \Illuminate\Database\Eloquent\ModelNotFoundException + * @throws ModelNotFoundException */ public function getParticipantFromUser($userId) { @@ -331,7 +329,7 @@ public function getParticipantFromUser($userId) /** * Restores only trashed participants within a thread that has a new message. - * Others are already active participiants. + * Others are already active participants. * * @return void */ @@ -346,12 +344,12 @@ public function activateAllParticipants(): void /** * Generates a string of participant information. * - * @param null|int $userId + * @param mixed $userId * @param array $columns * * @return string */ - public function participantsString(?int $userId = null, array $columns = ['name']): string + public function participantsString($userId = null, array $columns = ['name']): string { $participantsTable = Models::table('participants'); $usersTable = Models::table('users'); @@ -374,11 +372,11 @@ public function participantsString(?int $userId = null, array $columns = ['name' /** * Checks to see if a user is a current participant of the thread. * - * @param int $userId + * @param mixed $userId * * @return bool */ - public function hasParticipant(int $userId): bool + public function hasParticipant($userId): bool { $participants = $this->participants()->where('user_id', '=', $userId); @@ -421,11 +419,11 @@ protected function createSelectString(array $columns): string /** * Returns array of unread messages in thread for given user. * - * @param int $userId + * @param mixed $userId * - * @return \Illuminate\Support\Collection + * @return Collection */ - public function userUnreadMessages(int $userId): Collection + public function userUnreadMessages($userId): Collection { $messages = $this->messages()->where('user_id', '!=', $userId)->get(); @@ -435,7 +433,7 @@ public function userUnreadMessages(int $userId): Collection return collect(); } - if (!$participant->last_read) { + if (! $participant->last_read) { return $messages; } @@ -447,11 +445,11 @@ public function userUnreadMessages(int $userId): Collection /** * Returns count of unread messages in thread for given user. * - * @param int $userId + * @param mixed $userId * * @return int */ - public function userUnreadMessagesCount(int $userId): int + public function userUnreadMessagesCount($userId): int { return $this->userUnreadMessages($userId)->count(); } diff --git a/src/Traits/Messagable.php b/src/Traits/Messagable.php index 0936eae..379c05f 100644 --- a/src/Traits/Messagable.php +++ b/src/Traits/Messagable.php @@ -16,7 +16,7 @@ trait Messagable /** * Message relationship. * - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany * * @codeCoverageIgnore */ @@ -28,7 +28,7 @@ public function messages(): HasMany /** * Participants relationship. * - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany * * @codeCoverageIgnore */ @@ -40,7 +40,7 @@ public function participants(): HasMany /** * Thread relationship. * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return BelongsToMany * * @codeCoverageIgnore */ @@ -77,7 +77,7 @@ public function unreadMessagesCount(): int /** * Returns all threads with new messages. * - * @return \Illuminate\Database\Eloquent\Collection + * @return Collection */ public function threadsWithNewMessages(): Collection { diff --git a/tests/TestCase.php b/tests/TestCase.php index cfbb218..233b406 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -13,7 +13,8 @@ class TestCase extends OrchestraTestCase { - use RefreshDatabase, WithFaker; + use RefreshDatabase; + use WithFaker; protected $loadEnvironmentVariables = true;