とあるコード規約(。- .•)
もくじ
インデント
スペース4つ
型宣言
class Sample()
{
public function hoge(int $id): Collection
{
//
}
public function hoge(Request $resuest): ?int
{
//
}
}
- 引数、戻り値にきちんと型宣言
- nullが返る可能性のあるものは: ?型
比較
if ($hoge === 'hoge') {
//
}
- ===で厳密に比較する。
- ifの後、if () の後にスペース1つ分あける
命名規則
public fucntion getJob()
{
//
}
動詞+大文字目的語
演算子
$result = $num + 1;
演算子はスペースを1つだけあける
引数が複数の場合
<?php
namespace App\Services;
use Illuminate\Support\Collection;
use App\Jobs\SendPush;
use App\Models\User;
use App\Repositories\AgeRepository;
use App\Repositories\SageRepository;
use App\Repositories\HogeRepository;
use App\Repositories\MogeRepository;
public class SampleService() extends Service
{
protected $ageRepository;
protected $sageRepository;
protected $hogeRepository;
protected $mogeRepository;
public function __construct(
AgeRepository $ageRepository,
SageRepository $sageRepository,
HogeRepository $hogeRepository,
MogeRepository $mogeRepository
) {
$this->ageRepository = $ageRepository;
$this->sageRepository = $sageRepository;
$this->hogeRepository = $hogeRepository;
$this->mogeRepository = $mogeRepository;
}
//
}
縦に並べる
データベース
- テーブル名は複数形
例) masters - 主キー制約の命名規則は単数形_id
例) master_id - 外部キー制約は利用しない
// 案件によると思う。
[amazon_link asins=’4873115655′ template=’ProductCarousel’ store=’izayoi55-22′ marketplace=’JP’ link_id=’167d9e7e-9783-4fce-9798-dcc21ee0e5a1′]
[amazon_link asins=’479813547X’ template=’ProductCarousel’ store=’izayoi55-22′ marketplace=’JP’ link_id=’4e49feb8-c1a1-4c80-a3ce-5d1d55d19d97′]

![PHP Adapterパターン [PHPによるデザインパターン入門]](https://www.yuulinux.tokyo/contents/wp-content/uploads/2017/09/phpDP_20190407_1-150x150.jpg)



![[DDD] Value Object 値オブジェクト](https://www.yuulinux.tokyo/contents/wp-content/uploads/2020/01/PHP-logo_2-150x150.jpeg)