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
型があると嬉しい〜って本当??
Search
hideki kinjyo
PRO
July 31, 2023
Programming
0
380
型があると嬉しい〜って本当??
hideki kinjyo
PRO
July 31, 2023
Tweet
Share
More Decks by hideki kinjyo
See All by hideki kinjyo
色んなオートローダーを覗き見る #phpcon_okinawa
o0h
PRO
5
460
ヒューマンエラーの本を読んだ ~報告会~
o0h
PRO
3
240
みんなでワイワイ「テスト駆動開発」の話をやる会 #techramen24conf
o0h
PRO
3
460
SPLから始める「データ構造」入門
o0h
PRO
7
1.7k
PHPUnit11の新しい仲間たち
o0h
PRO
3
330
単体テストを書かない技術 #phpcon_odawara
o0h
PRO
60
20k
パンフ記事 「初めてのリファクタリング!」 の裏側 #phperkaigi
o0h
PRO
2
140
phpunit/php-code-coverageって何をしてるんだ #phperkaigi
o0h
PRO
3
1.2k
Composerを便利に使うために私がやっていること #phperkaigi
o0h
PRO
1
2.4k
Other Decks in Programming
See All in Programming
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
CSC509 Lecture 09
javiergs
PRO
0
140
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.5k
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
CSC509 Lecture 12
javiergs
PRO
0
160
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.1k
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
役立つログに取り組もう
irof
28
9.6k
C++でシェーダを書く
fadis
6
4.1k
Click-free releases & the making of a CLI app
oheyadam
2
120
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
The Invisible Side of Design
smashingmag
298
50k
Side Projects
sachag
452
42k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
How STYLIGHT went responsive
nonsquared
95
5.2k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Why Our Code Smells
bkeepers
PRO
334
57k
Transcript
が ͳʹ͔ͷษڧձͱ͔͕͋Δ༁Ͱͳ͍ Hideki Kinjyo GitHub: o0h / Twitter: @o0h_
ࣗݾհ / GitHub: @o0h / Twitter: @o0h_ FW CakePHP
Πϯτϩ PHP PHP
( ) https://fortee.jp/phpcon-2021/proposal/6cd22f6c-9caa-432f-930c-9e62f512d59d
None
https://www.php.net/manual/ja/language.types.intro.php
https://www.php.net/manual/ja/language.types.intro.php PHP ( ) PHP
https://www.php.net/manual/ja/language.types.intro.php 10000 3
https://www.php.net/manual/ja/language.types.intro.php =
https://www.php.net/manual/ja/language.types.intro.php ( ) Web
shin1x1͞Μͷൃදʮ੍ͷྗʯ https://speakerdeck.com/shin1x1/restricting-states
shin1x1͞Μͷൃදʮ੍ͷྗʯ https://speakerdeck.com/shin1x1/restricting-states
shin1x1͞Μͷൃදʮ੍ͷྗʯ https://speakerdeck.com/shin1x1/restricting-states
shin1x1͞Μͷൃදʮ੍ͷྗʯ https://speakerdeck.com/shin1x1/restricting-states
t-wada͞Μͷൃදʮ༧ʹউΔޚͳ͠ʯ https://speakerdeck.com/twada/growing-reliable-code-phperkaigi-2022
t-wada͞Μͷൃදʮ༧ʹউΔޚͳ͠ʯ https://speakerdeck.com/twada/growing-reliable-code-phperkaigi-2022
ܕΛ͚ͭΔͧʂʂͷϞνϕʔγϣϯ ( )
:
PHPͷܕએݴ PHP php.net https://www.php.net/manual/ja/language.types.declarations.php
( )
int $l, $r int int NULL DB (= )
int int int int ( )
PHP7 ( ) ࢀߟ ݫີͳܕ͚ IUUQTXXXQIQOFUNBOVBMKBMBOHVBHFUZQFTEFDMBSBUJPOTQIQMBOHVBHFUZQFTEFDMBSBUJPOTTUSJDU
خ͍͠Ͱ͔͢ʁ int t-wada
خ͍͠Ͱ͔͢ʁ = (DB HTTP ) etc ( ) = int
=>
int / $response->getBody() $body- >eof() string, bool, Response, Stream
ࢀߟ IUUQTHJUIVCDPNTMJNQIQ4MJNCMPC4MJN 3FTQPOTF&NJUUFSQIQ
Interface ࢀߟ IUUQTHJUIVCDPNTMJNQIQ4MJNCMPC4MJN 3FTQPOTF&NJUUFSQIQ StreamInterface bool int: 0
(Content-Length ) int int string bool
ܕͱͷ͖߹͍ํ ( ) Interface strict_types=1 private public
:
ΨϯΨϯܕએݴΛ͢Δ͜ͱͷऑͱ͔ PHPDoc PHP PHP
੩తղੳπʔϧΛ͓͏ / PHPStan https://phpstan.org/ PHPStan scans your whole codebase and
looks for both obvious & tricky bugs. Even in those rarely executed if statements that certainly aren't covered by tests. ( )
੩తղੳπʔϧΛ͓͏ / Psalm https://psalm.dev/ Psalm is a static analysis tool
that attempts to dig into your program and fi nd as many type-related bugs as possible. PHPStan
੩తղੳπʔϧΛ͓͏ / PhpStorm PHP PHPStan Psalm lint ( )
PHPStan
= CI ࢀߟ IUUQTQIQTUBOPSHSGDGBDGCDCEGC
PHPDoc @param / @return ࢀߟ IUUQTQIQTUBOPSHSGFFECEEEDG
: `key-of- <***>` `value-of-<***>` ( ) ࢀߟ IUUQTQIQTUBOPSHSCDGDFCBCCBBEE
: int<min, max> `int` ࢀߟ IUUQTQIQTUBOPSHSEFFGDDCCBEEFE
: (key, value ) iterable array mixed ࢀߟ
IUUQTQIQTUBOPSHSEG ff EDFBBBFD
: DTO ࢀߟ IUUQTQIQTUBOPSHSDCFGGCGGGFE
৭ʑͳܕͷදݱ : https://phpstan.org/writing-php- code/phpdoc-types
PHPStan
Πϯετʔϧ͢Δ
ઃఆϑΝΠϧΛઃஔ͢Δ https://phpstan.org/con fi g-reference
࣮ߦ͢Δ
( OK)
ಋೖ࣌ʹ͓֮͑ͯ͘ͱྑͦ͞͏ͳ֓೦ Error Rule/RuleSet Rule RuleSet Rule Rule level PHPStan Ruleset
0 9(max) level
Rule Levelͷྫ https://github.com/phpstan/phpstan-src/blob/1.10.25/conf/con fi g.level6.neon
ಋೖ࣌ʹ͓֮͑ͯ͘ͱྑͦ͞͏ͳ֓೦ Baseline ( ) Error `phpstan analyze generate-baseline` Error ignoreErrors
con fi g 1 ( )Error Baseline ignoreErrors
Baselineͷྫ(CakePHP) https://github.com/cakephp/cakephp/blob/4.4.15/phpstan-baseline.neon
PHPStanͷ͍͞͠ಋೖʹ͚ͯ PJ Level OK Baseline PHPStan ignoreErrors( Baseline ) Error
(cf: https://phpstan.org/user-guide/ignoring-errors#reporting-unused- ignores)
PHPStanͷ͍͞͠ಋೖʹ͚ͯ PJ Level CI 5 6
PHPStanͷ͍͞͠ಋೖʹ͚ͯ 連 Error etc
ͬͱڧྗͳ׆༻ʹ͚ͯ PHPStan https://phpstan.org/writing-php-code/phpdoc-types https://phpstan.org/con fi g-reference https://phpstan.org/user-guide/extension-library OSS
ͱͯࢀߟʹͳΔࢿྉͨͪ PHPStan #phpcon_okinawa pixivFANBOX https://tadsan.fanbox.cc/posts/4348669 #phpcon_okinawa pixivFANBOX https://tadsan.fanbox.cc/posts/2558149
level=0 PHPStan(Larastan) - Shin x Blog https://blog.shin1x1.com/entry/getting-stated-with-phpstan CI / Great static analysis with CI - Speaker Deck https://speakerdeck.com/oogfranz/great-static-analysis-with-ci