註解
常聽人說好的程式碼不用註解,但我看所有 contributors 很多的開源專案都有註解
<?php
use App\Models\PhoneBill;
use App\Enums\SendDriver;
use App\Services\Sender\SenderFactory;
function sendPhoneBills(array $ids, SendDriver $driver): void
{
$bills = PhoneBill::whereIntegerInRaw('id', $ids)
->where('is_send', false)
->get();
$sender = SenderFactory::create($driver);
foreach($bills as $bill) {
$sender->send([
'name' => $bill->name,
'price' => $bill->price,
'phone' => $bill->phone,
'expired_at' => $bill->expired_at->toDateTimeString(),
'created_date' => $bill->created_at->toDateTimeString(),
]);
}
PhoneBill::whereIntegerInRaw('id', $ids)
->where('is_send', false)
->update(['is_send' => true]);
}
在你覺得需要空一行的時候註解
在你覺得程式碼有點多的時候註解
在你需要看文件的時候註解
可以用,但少用的註解
註解應該用什麼語言?
Last updated