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

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

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

PHPerKaigi 2018のトーク内容です。

Hiraku NAKANO

March 10, 2018
Tweet

More Decks by Hiraku NAKANO

Other Decks in Technology

Transcript

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

    ϝϧϖΠ • PHPྺ10೥͙Β͍ • Composerؔ࿈ͷൃදΛΑ͍ͯ͘͠·͢
  2. PHPStanͱ͸ • https://github.com/phpstan/phpstan • PHP Static Analysis Tool ͷུ •

    ಈ࡞ʹ͸PHP 7.1Ҏ্͕ඞཁ • PHP5ͷίʔυ΋ղੳͯ͘͠ΕΔ • nikic/php-parserϕʔεͰͷղੳΛߦ͏ (ͷͰׂͱݡ͍)
  3. Install • composer require --dev phpstan/phpstan • phar൛΋͋Δ͠ɺglobal requireͯ͠΋୯ಠಈ ࡞͢Δ

    • docker hubʹ΋Πϝʔδ͕͋Δ • https://hub.docker.com/r/phpstan/phpstan/
  4. ※όʔδϣϯҧ͍ʹ஫ҙ • 2018೥3݄࣌఺ͷstable (0.9ܥ) ͱɺdev (1.0ܥ)͸ ͔ͳΓΦϓγϣϯʹҧ͍͕͋Γ·͢ • githubͷREADME.mdΛಡΉͱ͖͸஫ҙ •

    ͜͜Ͱ͸dev൛(1.0ܥ)Λϕʔεʹ࿩͠·͢ • composer global require "phpstan/phpstan:@dev" ͳͲͰೖΓ·͢
  5. ࣮ߦͨ͠ͱ͖ͷΠϝʔδ $ 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 ------ -------------------------------------------------------------------
  6. PHP7ͷܕએݴ • int, float, bool, string, array, Ϋϥε/Πϯλʔϑ Σʔε໊, callable,

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