Upgrade to Pro — share decks privately, control downloads, hide ads and more …

モテるコードの書き方

 モテるコードの書き方

Growfit TechLT会の発表資料です。
https://growfit01.connpass.com/event/251492/

ゆうきゃん

July 30, 2022
Tweet

More Decks by ゆうきゃん

Other Decks in Programming

Transcript

  1. class Hoge { public function foo($arg): string { if ($arg

    === 'bar') { return 'bar'; } return 'piyo'; } } ඇϞςίʔυ💩
  2. class Hoge { public function foo($arg): string { if ($arg

    === 'bar') { return 'bar'; } return 'piyo'; } } Ϟςίʔυ🏄
  3. public function isActiveUser(User $user): bool { if ($user !== null)

    { if ($user->email_verified_at !== null) { if ($user->last_logined_at > new DateTime('-1 year')) { return true; } else { return false; } } else { return false; } } else { return false; } } ඇϞςίʔυ💩
  4. public function isActiveUser(User $user): bool { if ($user !== null)

    { return false; } if ($user->email_verified_at === null) { return false; } if ($user->last_logined_at <= new DateTime('-1 year')) { return false; } return true; } Ϟςίʔυ🏄
  5. final class HogeService { public function execute() { $slackNotification =

    new SlackNotification(); if ($isProduction) { $slackNotification->send('Success!'); } } } ඇϞςίʔυ💩
  6. interface SlackNotificationInterface { public function send(string $message): void; } final

    class SlackNotification implemetns SlackNotificationInterface { public function send(string $message): void { // Slack通知の実装を書く } } final class MockSlackNotification implemetns SlackNotificationInterface { public function send(string $message): void { // 何もしない } } final class HogeService { public function __construct(private SlackNotificationInterface $slackNotification) { } public function execute() { $this->slackNotification->send('Success!'); } } Ϟςίʔυ🏄