Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
自分が信じられないから静的解析が好きです
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Satoshi Kaneyasu
September 28, 2023
Programming
280
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
自分が信じられないから静的解析が好きです
Satoshi Kaneyasu
September 28, 2023
More Decks by Satoshi Kaneyasu
See All by Satoshi Kaneyasu
Amazon Managed Grafana で Amazon DynamoDB のデータを可視化する Infinity Plugin + プライベート API 構成
satoshi256kbyte
1
22
AI駆動開発にグラフDBを重ねてみた
satoshi256kbyte
2
800
AWS Transform Customによる Spring Boot 2.xから4.xへのVerUp
satoshi256kbyte
2
160
運用ダッシュボードの設計を誰も教えてくれないのだけどみなさんどうしてるんですか? - チームに監視するという文化を根付かせるための第一歩を踏みたい -
satoshi256kbyte
1
200
AWS CDK ExpressモードとCI/CDの組み合わせ
satoshi256kbyte
1
63
AWS re:Invent 2025の少し振り返り + DevOps AgentとBacklogを連携させてみた
satoshi256kbyte
3
250
Amazon_Cognito_で構築する_スケーラブルな_Web_アプリケーション__シングルページ_Web_アプリケーションに認証を組み込む
satoshi256kbyte
0
55
人間とAI、どちらが書いたコードもCI/CDでチェックしてみよう
satoshi256kbyte
0
63
今こそ押さえておきたい アマゾンウェブサービス(AWS)の データベースの基礎 おもクラ #6版
satoshi256kbyte
1
320
Other Decks in Programming
See All in Programming
iOSDC2026登壇資料.pdf
riofujimon
0
170
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
4.6k
すこし踏み込む CancellationToken
htkym
0
260
AHC070解法紹介
eijirou
0
120
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
7
2k
LL言語やWebフレームワークのPostgreSQL対応 〜DBの機能がユーザーに届くまで〜
kentaroutakeda
1
150
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
270
AI活用は、個人から組織へ|マルチプレイヤーエージェントハーネス「QM」の社内活用事例 / AI use is moving from individuals to orgs
rkaga
1
110
TiDB Cloudのカスタムコントローラーによるオートスケール対応
takaidohigasi
0
120
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
0
1.4k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
400
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
2.3k
Featured
See All Featured
Designing for humans not robots
tammielis
254
26k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
530
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
850
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
500
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
330
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
440
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
510
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
65k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
700
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.8k
Transcript
⾃分が信じられないから 静的解析が好きです 2023.09.27 SATOSHI KANEYASU
⾃⼰紹介 ⽒名︓兼安 聡 所属︓株式会社サーバーワークス 最近のお仕事︓DevOpsの推進 趣味︓サックス、筋トレ、CS ゲーム 資格︓ X(Twitter)︓@satoshi256kbyte など
購入しました 明日、受け取りに 行きます
アジェンダ • [エピソード]システムのVerupにおける静的解析の活⽤ • 廃⽌された関数・変数の置換チェック • 独⾃ルールのソースの静的解析、その課題と対策 • 静的解析の⾃動化 •
⾃動化できなかったこと • pre-commitでコミット差分だけ静的解析 • まとめ
システムのVerupにおける静的解析の活⽤ • ⾔語はPHP • フレームワークバージョンアップ • フレームワークのVerupは破壊的変更、廃⽌された関数・変数は多数 • バージョンアップ前・後、両⽅のFWの知識があるのは極少数 •
品質担保の⼀環として、静的解析(PHPStan)を使⽤
廃⽌された関数・変数の抽出に⽤いる • 旧Verのコードは、ほとんどが何らかの修正が必要 • 正規表現&⼿作業で⼀通り修正 • レビュー&⼿動テストでは改修成否のチェックは不可と判断し、 静的解析を採⽤ • 静的解析の準備は(個⼈的には)まあまあ⼤変というレベル
• 効果は「特⼤」、これがないとまともな品質にはならなかっただろう
廃⽌された関数・変数の置換チェック • 廃⽌された関数・変数が正しく置換されてるか、静的解析でチェック • 配列に関する警告等、修正のタイパが悪すぎるものは無視リスト • 最終的には、PHPStanのBaselineも活⽤ • 効果があったことから、 新規だけでなく改修PJでも静的解析は⾮常に有効と考えている
ある時点より前のエラーは認識済とみなす ある時点以降新たに出たエラーだけチェック Baseline
独⾃ルールのソースの静的解析、その課題と対策 • 独⾃のビジネスロジック置き場がある • そのままでは静的解析できない • PHPStanのFW⽤の拡張を更に拡張して、 独⾃のビジネスロジック置き場もフォロー • 拡張ライブラリは、独⾃とはいえFWの
ルールを参考にしていたのでスムーズに作 れた src Controller Business Model View /
静的解析の⾃動化 • AWS CodeBuildで静的解析を⾃動実⾏ • CodeBuildはdevelopへのコミットで起動 • マージのタイミングで全体の解析を⾏うので、 思わぬエラーを拾えた •
最終的には静的解析+独⾃のシェルで、 例外の隠蔽やSQLインジェクションも⾃動抽出 AWS CodeBuild AWS CodeCommit AWS CodeDeploy
⾃動化できなかったこと • AWS CodeBuildで⽔際対策はできた • しかし、静的解析NGなコードはコミットして欲しくないのが本⾳ • コミット前にローカルで静的解析するようルール付けしたが、 定着しなかった
pre-commitでコミット差分だけ静的解析 • 前述の経験を踏まえて改善 • Node.jsのhuskyを使⽤すると、 コミット前にタスクを⾃動実⾏可能 • 開発者が個々に設定する必要はない .husky pre-commit
/ src phpstan-commit.sh
コミット差分だけ静的解析するシェル #!/bin/bash FILES=$(git diff --cached --name-only --diff-filter=ACM | grep "^src/.*¥.php$")
if [ "$FILES" != "" ]; then vendor/bin/phpstan analyse --level=max $FILES if [ $? -ne 0 ]; then echo "PHPStan failed" exit 1 fi fi phpstan-commit.sh
pre-commitで静的解析を実⾏ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" ./phpstan-commit.sh .husky/pre-commit
コミット時の出⼒サンプル > git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
Note: Using configuration file /home/ec2-user/husky-phpstan/phpstan.neon. 0/1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0% [1G [2K 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% ------ ------------------------------------------------------------ Line sample1.php ------ ------------------------------------------------------------ 6 Parameter #1 $a of function add expects int, string given. 6 Parameter #2 $b of function add expects int, string given. ------ ------------------------------------------------------------ [ERROR] Found 2 errors PHPStan failed husky - pre-commit hook exited with code 1 (error)
まとめ • 静的解析は改修案件でも有効 • pre-commitを使えば、静的解析のルール化も可能 コードレビューの前準備︕ • pre-commitで静的解析した上で、 CI/CDパイプラインに繋げて更なる改善に繋げたい 私はもう静的解析は⼿放せない
以上、ありがとうございました。