Skip to content

Refactoring code #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.PHONY: helpers
helpers:
php artisan ide-helper:generate
php artisan ide-helper:models -F helpers/ModelHelper.php -M
php artisan ide-helper:meta

.PHONY: stan
stan:
composer stan
2 changes: 2 additions & 0 deletions app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Actions\Fortify;

use App\Models\User;
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Fortify/PasswordValidationRules.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Actions\Fortify;

use Illuminate\Validation\Rules;
Expand Down
4 changes: 3 additions & 1 deletion app/Actions/Fortify/ResetUserPassword.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Actions\Fortify;

use Illuminate\Support\Facades\Hash;
Expand All @@ -19,7 +21,7 @@ class ResetUserPassword implements ResetsUserPasswords
*
* @throws \Illuminate\Validation\ValidationException
*/
public function reset($user, array $input)
public function reset($user, array $input): void
{
Validator::make($input, [
'password' => $this->passwordRules(),
Expand Down
13 changes: 6 additions & 7 deletions app/Actions/Fortify/UpdateUserPassword.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

declare(strict_types=1);

namespace App\Actions\Fortify;

use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Laravel\Fortify\Contracts\UpdatesUserPasswords;
Expand All @@ -11,15 +14,11 @@ class UpdateUserPassword implements UpdatesUserPasswords
use PasswordValidationRules;

/**
* Validate and update the user's password.
*
* @param mixed $user
* @param array $input
* @return void
*
* @throws \Illuminate\Validation\ValidationException
* @param User $user
* @param string[] $input
*/
public function update($user, array $input)
public function update(User $user, array $input): void
{
Validator::make($input, [
'current_password' => ['required', 'string'],
Expand Down
25 changes: 9 additions & 16 deletions app/Actions/Fortify/UpdateUserProfileInformation.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Actions\Fortify;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Models\User;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;

class UpdateUserProfileInformation implements UpdatesUserProfileInformation
{
/**
* Validate and update the given user's profile information.
*
* @param mixed $user
* @param array $input<string, string>
* @return void
*
* @throws \Illuminate\Validation\ValidationException
* @param User $user
* @param string[] $input
*/
public function update($user, array $input)
public function update(User $user, array $input): void
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
Expand All @@ -32,8 +29,7 @@ public function update($user, array $input)
],
])->validateWithBag('updateProfileInformation');

if ($input['email'] !== $user->email &&
$user instanceof MustVerifyEmail) {
if ($input['email'] !== $user->email) {
$this->updateVerifiedUser($user, $input);
} else {
$user->forceFill([
Expand All @@ -44,13 +40,10 @@ public function update($user, array $input)
}

/**
* Update the given verified user's profile information.
*
* @param mixed $user
* @param array $input
* @return void
* @param string[] $input
*/
protected function updateVerifiedUser($user, array $input)
protected function updateVerifiedUser(User $user, array $input): void
{
$user->forceFill([
'name' => $input['name'],
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Replies/CreateReply.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Actions\Replies;

use App\Events\CommentWasAdded;
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Replies/LikeReply.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Actions\Replies;

use App\Models\Reaction;
Expand Down
2 changes: 2 additions & 0 deletions app/Console/Commands/AssignUserRole.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Models\User;
Expand Down
2 changes: 2 additions & 0 deletions app/Console/Commands/Cleanup/DeleteOldUnverifiedUsers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands\Cleanup;

use App\Models\User;
Expand Down
2 changes: 2 additions & 0 deletions app/Console/Commands/CreateAdminUser.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Models\User;
Expand Down
5 changes: 5 additions & 0 deletions app/Console/Commands/GenerateSitemap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use Illuminate\Console\Command;
Expand All @@ -14,6 +16,9 @@ class GenerateSitemap extends Command

protected $description = 'Crawl the site to generate a sitemap.xml file';

/**
* @var array|string[]
*/
private array $noIndexPaths = [
'',
'/forum/*',
Expand Down
2 changes: 2 additions & 0 deletions app/Console/Commands/PostArticleToTelegram.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Models\Article;
Expand Down
2 changes: 2 additions & 0 deletions app/Console/Commands/PostArticleToTwitter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Models\Article;
Expand Down
2 changes: 2 additions & 0 deletions app/Console/Commands/PublishArticles.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Models\Article;
Expand Down
2 changes: 2 additions & 0 deletions app/Console/Commands/SendUnVerifiedMails.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Mail\SendMailToUnVerifiedUsers;
Expand Down
2 changes: 2 additions & 0 deletions app/Console/Commands/SendWelcomeMailToUsers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Models\User;
Expand Down
6 changes: 4 additions & 2 deletions app/Console/Commands/UpdateUserBestRepliesPoints.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Gamify\Points\BestReply;
Expand All @@ -12,11 +14,11 @@ class UpdateUserBestRepliesPoints extends Command

protected $description = 'Updating users bests replies reputation points';

public function handle()
public function handle(): void
{
$this->info('Updating users bests replies reputations...');

$resolvedThread = Thread::with('solutionReply')->resolved()->get();
$resolvedThread = Thread::resolved()->with('solutionReply')->get();

foreach ($resolvedThread as $thread) {
givePoint(new BestReply($thread->solutionReply));
Expand Down
4 changes: 3 additions & 1 deletion app/Console/Commands/UpdateUserDiscussionsPoints.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Gamify\Points\DiscussionCreated;
Expand All @@ -12,7 +14,7 @@ class UpdateUserDiscussionsPoints extends Command

protected $description = 'Update users discussions reputation points';

public function handle()
public function handle(): void
{
$this->info('Updating users discussions reputations...');

Expand Down
4 changes: 3 additions & 1 deletion app/Console/Commands/UpdateUserPostsPoints.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Gamify\Points\PostCreated;
Expand All @@ -12,7 +14,7 @@ class UpdateUserPostsPoints extends Command

protected $description = 'Update users posts reputation points';

public function handle()
public function handle(): void
{
$this->info('Updating users posts reputations...');

Expand Down
4 changes: 3 additions & 1 deletion app/Console/Commands/UpdateUserRepliesPoints.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Gamify\Points\ReplyCreated;
Expand All @@ -12,7 +14,7 @@ class UpdateUserRepliesPoints extends Command

protected $description = 'Updating users replies reputation points';

public function handle()
public function handle(): void
{
$this->info('Updating users bests replies reputations...');

Expand Down
4 changes: 3 additions & 1 deletion app/Console/Commands/UpdateUserThreadsPoints.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Gamify\Points\ThreadCreated;
Expand All @@ -12,7 +14,7 @@ class UpdateUserThreadsPoints extends Command

protected $description = 'Update users threads reputation points';

public function handle()
public function handle(): void
{
$this->info('Updating users threads reputations...');

Expand Down
5 changes: 3 additions & 2 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
Expand All @@ -10,7 +12,7 @@ class Kernel extends ConsoleKernel
/**
* The Artisan commands provided by your application.
*
* @var array
* @var string[]
*/
protected $commands = [
\App\Console\Commands\Cleanup\DeleteOldUnverifiedUsers::class,
Expand All @@ -26,7 +28,6 @@ protected function schedule(Schedule $schedule): void
$schedule->command('lcm:post-article-to-telegram')->everyFourHours();
$schedule->command('lcm:send-unverified-mails')->weeklyOn(1, '8:00');
$schedule->command('sitemap:generate')->daily();
$schedule->command(\Spatie\Health\Commands\RunHealthChecksCommand::class)->everyMinute();
}
}

Expand Down
9 changes: 7 additions & 2 deletions app/Contracts/ReactableInterface.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Contracts;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\MorphToMany;

interface ReactableInterface
{
/**
* Returns an Eloquent collection of reactions to the current item.
*/
public function reactions();
public function reactions(): MorphToMany;

/**
* Returns a collection of objects. Every object has a name and a count.
Expand All @@ -23,5 +28,5 @@ public function reactions();
* $reaction->count
* }
*/
public function getReactionsSummary();
public function getReactionsSummary(): Collection;
}
2 changes: 2 additions & 0 deletions app/Contracts/ReplyInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Contracts;

use Illuminate\Database\Eloquent\Collection;
Expand Down
2 changes: 2 additions & 0 deletions app/Contracts/SubscribeInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Contracts;

use App\Models\User;
Expand Down
Loading