PHPStanで始める継続的静的解析 #phperkaigi /php-static-analysis

PHPStanで始める継続的静的解析 #phperkaigi /php-static-analysis

PHPerKaigi 2018のトーク内容です。

2295fec4d38f59366f983d38628e6ca0?s=128

Hiraku NAKANO

March 10, 2018
Tweet

Transcript

  1. 2.

    ࣗݾ঺հ • த໺ ୓ (@Hiraku) • https://github.com/hirak • גࣜձࣾϝϧΧϦ →

    ϝϧϖΠ • PHPྺ10೥͙Β͍ • Composerؔ࿈ͷൃදΛΑ͍ͯ͘͠·͢
  2. 24.

    PHPStanͱ͸ • https://github.com/phpstan/phpstan • PHP Static Analysis Tool ͷུ •

    ಈ࡞ʹ͸PHP 7.1Ҏ্͕ඞཁ • PHP5ͷίʔυ΋ղੳͯ͘͠ΕΔ • nikic/php-parserϕʔεͰͷղੳΛߦ͏ (ͷͰׂͱݡ͍)
  3. 28.
  4. 30.

    Install • composer require --dev phpstan/phpstan • phar൛΋͋Δ͠ɺglobal requireͯ͠΋୯ಠಈ ࡞͢Δ

    • docker hubʹ΋Πϝʔδ͕͋Δ • https://hub.docker.com/r/phpstan/phpstan/
  5. 31.

    ※όʔδϣϯҧ͍ʹ஫ҙ • 2018೥3݄࣌఺ͷstable (0.9ܥ) ͱɺdev (1.0ܥ)͸ ͔ͳΓΦϓγϣϯʹҧ͍͕͋Γ·͢ • githubͷREADME.mdΛಡΉͱ͖͸஫ҙ •

    ͜͜Ͱ͸dev൛(1.0ܥ)Λϕʔεʹ࿩͠·͢ • composer global require "phpstan/phpstan:@dev" ͳͲͰೖΓ·͢
  6. 33.

    ࣮ߦͨ͠ͱ͖ͷΠϝʔδ $ phpstan analyse Note: Using configuration file /Users/hiraku/src/github.com/hirak/ prestissimo/phpstan.neon.dist.

    12/12 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% ------ ------------------------------------------------------------------- Line src/BaseRequest.php ------ ------------------------------------------------------------------- 23 PHPDoc tag @var has invalid value ([string => string]): Unexpected token "[", expected TOKEN_IDENTIFIER at offset 9 120 PHPDoc tag @param has invalid value ($io): Unexpected token "$io", expected TOKEN_IDENTIFIER at offset 18 120 PHPDoc tag @param has invalid value ($githubDomains): Unexpected token "$githubDomains", expected TOKEN_IDENTIFIER at offset 70 120 PHPDoc tag @param has invalid value ($gitlabDomains): Unexpected token "$gitlabDomains", expected TOKEN_IDENTIFIER at offset 99 ------ -------------------------------------------------------------------
  7. 34.
  8. 42.
  9. 58.

    PHP7ͷܕએݴ • int, float, bool, string, array, Ϋϥε/Πϯλʔϑ Σʔε໊, callable,

    iterable • ?Λઌ಄ʹ͚ͭΔ/σϑΥϧτҾ਺Λnullʹ͢Δ ͱnullable