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

自分が信じられないから静的解析が好きです

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.

 自分が信じられないから静的解析が好きです

Avatar for Satoshi Kaneyasu

Satoshi Kaneyasu

September 28, 2023
Tweet

More Decks by Satoshi Kaneyasu

Other Decks in Programming

Transcript

  1. 静的解析の⾃動化 • AWS CodeBuildで静的解析を⾃動実⾏ • CodeBuildはdevelopへのコミットで起動 • マージのタイミングで全体の解析を⾏うので、 思わぬエラーを拾えた •

    最終的には静的解析+独⾃のシェルで、 例外の隠蔽やSQLインジェクションも⾃動抽出 AWS CodeBuild AWS CodeCommit AWS CodeDeploy
  2. コミット差分だけ静的解析するシェル #!/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
  3. コミット時の出⼒サンプル > 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)