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

防衛的 PHP: 多様性を生き抜くための PHP 入門 / Defensive PHP

防衛的 PHP: 多様性を生き抜くための PHP 入門 / Defensive PHP

Naoki Ikeguchi

March 24, 2023
Tweet

Other Decks in Programming

Transcript

  1. XIPBNJ • αʔόαΠυΤϯδχΞ !ΏΊΈ • ࡾ౓ͷ൧ΑΓ੩తܕ෇͚͕޷͖ • 1)1 3VTU (P

    $ FUD • -BSBWFMΑΓ 4ZNGPOZ೿ • +FU#SBJOT৴ऀ • 3VTU Ͱ 1)1ͷ 4"1*Λ࣮૷͢Δ ͷ͕झຯ 2 @s6n_jp
  2. 'PSNBUUFS ౳Ձͳίʔυͷ··εϖʔγϯά΍ΠϯσϯτɼෆཁͳτʔΫϯ ͳͲΛ੔͑Δ 4 $foo = (function ($a, $b, $c)

    {})(); $bar = array(“a”, “b”,); $foo= ( function($a,$b, $c ){ }, )(); $bar = [ ‘a’, ‘b’, ];
  3. ͭͷ๷Ӵ • ࣗ෼ͷϛε͔Βͷ๷Ӵ • ࣗ෼Ͱॻ͍ͨίʔυͷจ຺Λ׬શʹ͍֮͑ͯΒΕΔΘ͚Ͱ͸ͳ͍ • ແବͳࢥߟ͔Βͷ๷Ӵ • ίʔυͷॻ͖ํ͸ຊ࣭Ͱ͸ͳ͍ •

    ॻ͖ํΛࣗಈͰ౷Ұ͢Δ͜ͱͰίʔυ্ͷຊ࣭ʹूதͰ͖Δ • ଞਓͷॻ͘ίʔυ͔Βͷ๷Ӵ • ίʔυϕʔεதͷίʔυͷ࣭͸ҰఆʹอͨΕΔ΂͖Ͱ͋Δ • ҉໧ͷ ίʔσΟϯάن໿͸कΒΕͳ͍ 15
  4. ॻ͘ਓͷ਺͚ͩҧ͏ίʔυ͕ੜ·ΕΔ • Πϯσϯτ͸εϖʔε λϒ • ԋࢉࢠͷपΓʹεϖʔεΛೖΕΔ ೖΕͳ͍ • BSSBZ@NBQBSSBZ@GJMUFSΛ࢖͏ GPSFBDIΛ࢖͏

    • ͜ͷॻ͖ํ͸ݹ͍ ৽͍͠ ˠίʔυͷຊ࣭͸ͦ͜Ͱ͸ͳ͍ ˠ੩తղੳʹΑͬͯຊ࣭ʹूதͰ͖ΔΑ͏ʹ͢Δ 17
  5. 143ͱ͸ • 1)1'*( 'SBNFXPSL*OUFSPQFSBCJMJUZ(SPVQ ʹΑͬͯ ࡦఆ͞ΕͨϑϨʔϜϫʔΫؒͷ૬ޓӡ༻ੑΛ֬อ͢ΔͨΊͷ ඪ४΍ "CTUSBDUJPO • ͨͱ͑͹ʜʜ

    • 143143ΦʔτϩʔσΟϯά • 143143143ίʔσΟϯάελΠϧ • 143)551ϝοηʔδΠϯλʔϑΣʔε • 143$MPDLˡ/&8 19
  6. 143 • 143Λݩʹͨ͠ίʔσΟϯάελΠϧඪ४ • ͨͱ͑͹ʜʜ • 1)1ϑΝΠϧ͸ -'ͷΈΛ࢖͏ .645 •

    FYUFOET΍ JNQMFNFOUT͸Ϋϥε໊ͱಉ͡ߦʹॻ͘ .645 • 5SBJUͷ VTFจ͸ DMBTTͷ։͔࢝ͬ͜ͷ͙͢ޙ .645 • ͢΂ͯͷϝιουʹ͸ 7JTJCJMJUZΛॻ͘ .645 • BCTUSBDU GJOBM TUBUJD͸ 7JTJCJMJUZͷલʹॻ͘ .645 • FMTFJGͰ͸ͳ͘ FMTFJGΛ࢖͏ 4)06-% FUDʜ 20
  7. 23

  8. 1)1$4'JYFS 24 • ϧʔϧηοτ • !4ZNGPOZ !4ZNGPOZSJTLZ  ͜Ε͸ !143Λܧঝ͢Δ

    • !1IQ$T'JYFS !1IQ$T'JYFSSJTLZ • !1)1.JHSBUJPO !1)1.JHSBUJPOSJTLZ • !1)16OJU.JHSBUJPOSJTLZ
  9. 25

  10. 27

  11. 1)14UBOฤ • ϨϕϧΛ d͔Β͑ΒͿ ͕͓͢͢Ί • 4ZNGPOZͰ࢖͏৔߹͸ &YUFOTJPOΛೖΕΔ • ΄΅

    0VUPG#PYͰ࢖͑Δ • ࠷ॳ͸ෆཁͳϧʔϧΛҰ୴ແޮԽ͍͍ͯ͠ͱࢥ͏ 28
  12. 29

  13. 31

  14. 32

  15. 36

  16. 37

  17. 1IQ4UPSN͸ $* Ͱಈ͖·͢ brew install jetbrains/utils/qodana qodana scan –-show-report •

    +BWB ,PUMJO 1)1 1ZUIPO +BWB4DSJQU 5ZQF4DSJQU (P  $ ' 7#/&5 BOENPSF • 4"3*'ܗࣜͰͷग़ྗ΋Մೳ • ࠓͳΒແྉͰ࢖͑·͢ 40
  18. ࠓ೔঺հͨ͠πʔϧΛ·ͱΊͯಋೖͰ͖·͢ composer require --dev \ quartetcom/static-analysis-kit:~8.1 • 1)1$4'JYFS 1)14UBO 3FDUPSΛҰ౓ʹಋೖͰ͖·͢

    • 0VUPG#PYͰ࢖͑ΔͷͰ໘౗ͳઃఆ΋ෆཁ • ݫ͠Ίͷઃఆʹͯ͋͠ΔͷͰݫ͠Ί͕޷͖ͳํʹ͓͢͢Ί 42