PhpStormで重複コードを一瞬で見つける

 PhpStormで重複コードを一瞬で見つける

第144回PHP勉強会の発表内容です

F075c5dfe92334b5031d4da5dc0c9251?s=128

Yuichi Sugiyama

November 27, 2019
Tweet

Transcript

  1. PhpStormͰ ॏෳίʔυΛ ҰॠͰݟ͚ͭΔ Cybozu ਿࢁ༞Ұ @oogFranz

  2. Who am I • ਿࢁ ༞Ұ @oogFranz • αΠϘ΢ζ5೥໨ΤϯδχΞ •

    େاۀ޲͚άϧʔϓ΢ΣΞGaroon࡞ͬͯΔʢPHP 7) • ෳۀδϟζϛϡʔδγϟϯ@MASHݭָஂ
  3. PHP ConferenceͰ·͢ʂ

  4. ॏෳίʔυ͋Γ·ͤΜ͔ʁ • ಈ͘ίʔυ͕ίϐϖ͞Ε͍ͯΔ • ෆ۩߹͕͋ͬͨΒॏෳίʔυશͯमਖ਼͕ඞཁ • ػೳ௥Ճ͕͋ͬͨΒॏෳίʔυશͯରԠ͕ඞཁ • ίϐϖίʔυΛݟ͚ͭͯॏෳΛऔΓআ͖͍ͨ

  5. ॏෳίʔυ͋Γ·ͤΜ͔ʁ • ಈ͘ίʔυ͕ίϐϖ͞Ε͍ͯΔ • ෆ۩߹͕͋ͬͨΒॏෳίʔυશͯमਖ਼͕ඞཁ • ػೳ௥Ճ͕͋ͬͨΒॏෳίʔυશͯରԠ͕ඞཁ • ίϐϖίʔυΛݟ͚ͭͯॏෳΛऔΓআ͖͍ͨ PhpStormͰ؆୯ʹݟ͚ͭΑ͏ʂ

  6. ΍Γ͔ͨ 1. ·ͣPhpStorm 2019.2ΛΠϯετʔϧ͠·͢

  7. ΍Γ͔ͨ 1. ·ͣPhpStorm 2019.2ΛΠϯετʔϧ͠·͢
 
 Ҏ্Ͱ͢

  8. DEMO https://github.com/oogFranz/duplicate-code-test

  9. ॏෳ͕Weak WarningͰ

  10. Diff viewerͰॏෳ۩߹Λ֬ೝ

  11. ม਺໊ͷҧ͍΋ݕग़

  12. ؔ਺໊΍Ϧςϥϧ஋ͷҧ͍΋ݕग़ • Editor > Duplicates ͔Βཁઃఆมߋ

  13. ΑΓෳࡶͳॏෳɺ୯७ͳॏෳΛݟ͚ͭΔ • unit ͱ͍͏୯ҐΛಈ͔͢͜ͱͰॏෳͷݟ͔ͭΔ۩߹Λมߋ • units = 2 * number

    of statements + number of expressions • σϑΥϧτ஋͸45ɻׂͱద౰ͳ஋ͳͷͰ߹Θͳ͔ͬͨΒมߋ͢Δɻ • ݴޠ͝ͱʹઃఆՄೳ
  14. ॏෳίʔυΛશ෦ݟ͚ͭΔ • Run Inspection By NameΛ࣮ߦ • Mac ͳΒ ”⌃⌥⇧I”

    ɺWinͳΒ ”Ctrl+Shift+Alt+I” • “Duplicated code fragment” Λೖྗ࣮ͯ͠ߦ