Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
PHPでのリーダブルコード/Readable code in PHP
Search
Y-KANOH
March 24, 2022
Technology
1
220
PHPでのリーダブルコード/Readable code in PHP
Y-KANOH
March 24, 2022
Tweet
Share
More Decks by Y-KANOH
See All by Y-KANOH
PHPカンファレンス関西2024 オープニング/php kansai 2024 opening
ykanoh
2
150
PHP略語クイズ/PHP Abbreviation Quiz
ykanoh
1
2.2k
PHPカンファレンス関西2024スタッフ希望者向け説明会
ykanoh
0
260
PHPマジックメソッドクイズ!/PHP Magic Method Quiz
ykanoh
0
1.1k
PHPerが再利用可能な情報提供でオフショア先とコード品質向上に取り組む / PHPer try improve the code quality
ykanoh
0
970
どんとこい、PhpStorm 〜Why don't you do IDE's best!〜 / Don't KOI PhpStorm!! Why don't you do IDE's best!!
ykanoh
0
6.5k
技術コミュニティ運営戦線〜継続して勉強会を運営するために〜/how to operate community continuously
ykanoh
0
1.5k
めざせOSSコントリビュート/LetsContributeOSS
ykanoh
2
130
コミュニティ活動で差別化をめざすエンジニアの一手/Distinguish by community for engineers career
ykanoh
2
990
Other Decks in Technology
See All in Technology
フロントエンド・オブザーバビリティを支える要素技術を学ぼう
sadnessojisan
2
180
サプライチェーン攻撃に備える
ryunen344
0
270
Fediverse Discovery Providers overview
andypiper
0
160
AWS SAW を広めたい @四国クラウドお遍路
kazzpapa3
0
230
2024年のナビゲーション・フォーカス対応:Composeでキーボード・ナビゲーションをサポートしよう
tahia910
0
110
ロリポップ! for Gamersを支えるインフラ/lolipop for gamers infrastructure
takumakume
0
130
たった1人からはじめる【Agile Community of Practice】~ソース原理とFearless Changeを添えて~
ktc_corporate_it
1
440
四国のあのイベントの〇〇システムを45日間で構築した話 / cloudohenro2024_tachibana
biatunky
0
330
どこよりも遅めなWinActor Ver.7.5.0 新機能紹介
tamai_63
0
200
「自動テストのプラクティスを効果的に学ぶためのカードゲーム」 ( #sqip2024 )
teyamagu
PRO
2
180
サーバレスでモバイルアプリ開発! NTTコム「ビジネスdアプリ」のアーキテクチャ / The architecture of business d app
nttcom
12
240
サーバー管理しないサーバーサービスManaged DevOps Pool
kkamegawa
0
130
Featured
See All Featured
The Power of CSS Pseudo Elements
geoffreycrofte
71
5.3k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
248
20k
The Pragmatic Product Professional
lauravandoore
31
6.2k
Facilitating Awesome Meetings
lara
49
5.9k
Mobile First: as difficult as doing things right
swwweet
221
8.8k
Why Our Code Smells
bkeepers
PRO
334
56k
GitHub's CSS Performance
jonrohan
1029
450k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Docker and Python
trallard
39
3k
GraphQLとの向き合い方2022年版
quramy
43
13k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
41
6.5k
Intergalactic Javascript Robots from Outer Space
tanoku
268
26k
Transcript
PHPでの リーダブルコード
加納 悠史 カノウユウジ PHPer @Ykanoh65 株式会社 ラクス
PHP使っている人
PHP使っていない人
PHPは変な言語? メリット ▰ すぐ使える ▰ 曖昧な書き方でもすぐ動く 5
PHPは変な言語? デメリット ▰ 曖昧なままなのでバグが起きやすい ▰ 変な記述でもとりあえず動く 6
デメリット回避のために
テクニックが必要
PHPで バグを減らす 記述方 9
1. PHPDoc ▰ 関数やクラスに記載するコメント ▰ PHPでは "型を指定する" ために使用 10
None
1. PHPDoc ▰ 関数やクラスに記載するコメント ▰ PHPでは "型を指定する" ために使用 ▰ 言語仕様以外で型が指定できる貴重なツール
12
2. 名前付き引数 ▰ PHP8.0 の新機能 ▰ 現在の最新は PHP8.1 ▰ 引数の初期値指定の煩雑さを回避
13
function hoge($startIndex=0, $num=0, $max=10, $min=1) { // ... } hoge(3,
12, 11); // min にはデフォルト値の 1 が入る hoge(0, 0, 10, 5); // min だけデフォルト値でないものを入れる場合に煩雑 hoge(min:5); // PHP 8.0 ではこのように書ける hoge(startIndex:3, num:12, max:11, min:1); // デフォルト値以外でも引数の意味がわかりやすくなる
2. 名前付き引数 ▰ PHP8.0 の新機能 ▰ 引数の初期値指定の煩雑さを回避 ▰ ぱっと見で引数の意味を理解できる IDE使ってたら不要かもしれないが...
15
PhpStorm の場合
3. PSR ▰ PHPの規約集 ▰ 複数のルールが存在 ▰ プロジェクトで採用ルールを選んで利用 17
https://www.php-fig.org/psr/
まとめ ▰ PHPDoc ▰ 名前付き引数 ▰ PSR 19