Skip to content
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

Laravel9へのアップデート #236

Merged
merged 19 commits into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ jobs:
- attach_workspace:
at: koyolympus/
- run:
name: check PHP code style (PSR12)
name: check PHP code style
working_directory: koyolympus
command: vendor/bin/phpcs --standard=phpcs.xml -p ./
command: vendor/bin/pint --test

larastan:
executor:
Expand Down
19 changes: 12 additions & 7 deletions koyolympus/app/Console/Commands/CheckConsistencyBetweenDBAndS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace App\Console\Commands;

use App\Services\PhotoService;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Services\PhotoService;

class CheckConsistencyBetweenDBAndS3 extends Command
{
Expand All @@ -30,7 +30,7 @@ class CheckConsistencyBetweenDBAndS3 extends Command
/**
* Create a new command instance.
*
* @param PhotoService $photoService
* @param PhotoService $photoService
*/
public function __construct(PhotoService $photoService)
{
Expand All @@ -43,35 +43,38 @@ public function __construct(PhotoService $photoService)
* Execute the console command.
*
* @return int
*
* @throws Exception
*/
public function handle()
{
$fileName = $this->argument('fileName');
$fileName = $this->argument('fileName');
$shouldSearchAll = $this->option('all');

if (isset($fileName) && $shouldSearchAll) {
$this->error("You cannot select specific file name when you put '--all' option.");

return 1;
}

if (!isset($fileName) && !$shouldSearchAll) {
if (! isset($fileName) && ! $shouldSearchAll) {
$this->error("You have to choose either putting 'fileName' or '--all' option in the command.");

return 1;
}

DB::beginTransaction();
try {
if (is_string($fileName) && !$shouldSearchAll) {
if (is_string($fileName) && ! $shouldSearchAll) {
$deletedFileInfo = $this->photoService->deletePhotoIfDuplicate($fileName);
$this->info(
"The duplicate file '$deletedFileInfo[deleteFile]' is successfully deleted.\n" .
"The number of deleted files is $deletedFileInfo[count]."
);
}

if (!isset($fileName) && $shouldSearchAll) {
$deletedFile = $this->photoService->deleteMultiplePhotosIfDuplicate();
if (! isset($fileName) && $shouldSearchAll) {
$deletedFile = $this->photoService->deleteMultiplePhotosIfDuplicate();
$deletedFileNum = $deletedFile->count();
$this->info("The $deletedFileNum files are completely deleted from S3 and DB because of duplication.");
foreach ($deletedFile as $photoInfo) {
Expand All @@ -80,10 +83,12 @@ public function handle()
}

DB::commit();

return 0;
} catch (Exception $e) {
DB::rollBack();
$this->error($e->getMessage());

return 1;
}
}
Expand Down
10 changes: 5 additions & 5 deletions koyolympus/app/Console/Commands/LikeAggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace App\Console\Commands;

use Carbon\CarbonImmutable;
use Illuminate\Console\Command;
use App\Services\LikeService;
use App\Jobs\AggregateDailyLikeJob;
use App\Jobs\AggregateWeeklyLikeJob;
use App\Jobs\AggregateMonthlyLikeJob;
use App\Jobs\AggregateWeeklyLikeJob;
use App\Services\LikeService;
use Carbon\CarbonImmutable;
use Illuminate\Console\Command;

class LikeAggregation extends Command
{
Expand Down Expand Up @@ -43,7 +43,7 @@ public function __construct(LikeService $likeService)
parent::__construct();

$this->likeService = $likeService;
$this->startAt = CarbonImmutable::now();
$this->startAt = CarbonImmutable::now();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace App\Console\Commands;

use Throwable;
use App\Services\ReplaceUuid\BaseService;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Services\ReplaceUuid\BaseService;
use Throwable;

class ReplaceAllPhotoInfoToIncludeUuid extends Command
{
Expand Down Expand Up @@ -43,6 +43,7 @@ public function __construct(BaseService $baseService)
* Execute the console command.
*
* @return void
*
* @throws Exception
*/
public function handle()
Expand All @@ -53,12 +54,14 @@ public function handle()
DB::beginTransaction();
$this->replaceUuIdService->includeUuidInRecord();
DB::commit();

return;
} catch (Throwable $e) {
DB::rollBack();
report($e);
$this->error(get_class($e) . ':' . $e->getMessage());
$this->error('例外発生');

return;
} finally {
$this->replaceUuIdService->deleteAllLocalPhoto();
Expand Down
8 changes: 4 additions & 4 deletions koyolympus/app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace App\Console;

use App\Console\Commands\CheckConsistencyBetweenDBAndS3;
use App\Console\Commands\CheckDatabase;
use App\Console\Commands\LikeAggregation;
use App\Console\Commands\ReplaceAllPhotoInfoToIncludeUuid;
use Illuminate\Console\Scheduling\Schedule;
use App\Console\Commands\CheckConsistencyBetweenDBAndS3;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use App\Console\Commands\ReplaceAllPhotoInfoToIncludeUuid;

class Kernel extends ConsoleKernel
{
Expand All @@ -20,13 +20,13 @@ class Kernel extends ConsoleKernel
CheckDatabase::class,
CheckConsistencyBetweenDBAndS3::class,
ReplaceAllPhotoInfoToIncludeUuid::class,
LikeAggregation::class
LikeAggregation::class,
];

/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
Expand Down
12 changes: 7 additions & 5 deletions koyolympus/app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace App\Exceptions;

use Exception;
use Throwable;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
Expand All @@ -32,8 +32,9 @@ class Handler extends ExceptionHandler
/**
* Report or log an exception.
*
* @param Exception $exception
* @param Exception $exception
* @return void
*
* @throws Exception
*/
public function report(Throwable $exception)
Expand All @@ -44,9 +45,10 @@ public function report(Throwable $exception)
/**
* Render an exception into an HTTP response.
*
* @param Request $request
* @param Exception $exception
* @param Request $request
* @param Exception $exception
* @return Response
*
* @throws Exception
*/
public function render($request, Throwable $exception): Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ModelUpdateFailedException extends Exception
{
private Model $model;

public function __construct(Model $model, string $message = "")
public function __construct(Model $model, string $message = '')
{
parent::__construct($message);
$this->model = $model;
Expand Down
5 changes: 3 additions & 2 deletions koyolympus/app/Exceptions/S3/S3MoveFailedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
class S3MoveFailedException extends Exception
{
private string $s3Path;

private string $newS3Path;

public function __construct(string $s3Path, string $newS3Path, string $message = "")
public function __construct(string $s3Path, string $newS3Path, string $message = '')
{
parent::__construct($message);
$this->s3Path = $s3Path;
$this->s3Path = $s3Path;
$this->newS3Path = $newS3Path;
}

Expand Down
12 changes: 6 additions & 6 deletions koyolympus/app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace App\Http\Controllers\Auth;

use App\User;
use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;

class RegisterController extends Controller
{
Expand Down Expand Up @@ -49,8 +49,8 @@ public function __construct()
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
Expand All @@ -64,8 +64,8 @@ protected function validator(array $data)
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
Expand Down
4 changes: 2 additions & 2 deletions koyolympus/app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
Expand Down
2 changes: 0 additions & 2 deletions koyolympus/app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
/**
Expand Down
10 changes: 5 additions & 5 deletions koyolympus/app/Http/Controllers/v1/BizInquiriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace App\Http\Controllers\v1;

use App\Mails\BizInquiriesMail;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Mail;
use App\Http\Requests\BizInquiriesRequest;
use App\Mails\BizInquiriesMail;
use Illuminate\Support\Facades\Mail;

class BizInquiriesController extends Controller
{
Expand All @@ -18,13 +18,13 @@ public function __construct()
/**
* お問い合わせメール送信処理
*
* @param BizInquiriesRequest $request
* @param BizInquiriesRequest $request
*/
public function sendBizInquiries(BizInquiriesRequest $request): void
{
$params = [
'name' => $request->input('name'),
'email' => $request->input('email'),
'name' => $request->input('name'),
'email' => $request->input('email'),
'opinion' => $request->input('opinion'),
];

Expand Down
Loading