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

やさしいコーディング規約の導入

F4d37a67ce86b2f962c79d73a9127d3c?s=47 fortkle
January 13, 2016

 やさしいコーディング規約の導入

F4d37a67ce86b2f962c79d73a9127d3c?s=128

fortkle

January 13, 2016
Tweet

Transcript

  1. ΍͍͞͠ ίʔσΟϯάن໿ͷಋೖ ߴ໺ ෱ߊ @fortkle - PHP BLT #2

  2. ࣗݾ঺հ • @fortkle • Connehito גࣜձࣾʢϚϚ޲͚αʔϏε mamariʣ • ୲౰ྖҬ͸ϑϩϯτʙαʔόʔαΠυ •

    ࠷ۙͷझຯ͸ɺvimʹlintܥϓϥάΠϯΛೖΕ· ͬͯ͘ϓϥάΠϯʹౖΒΕ·͘Δ͜ͱ
  3. None
  4. ޚࣾͷίʔσΟϯάن໿ɺ ػೳͯ͠·͔͢ʁ 143 143 ΦϨΦϨ ;FOE $BLF1)1 4ZNGPOZ

  5. None
  6. ίʔσΟϯάن໿͕ͳ͍ͱਏ͍ • ίʔυϨϏϡʔͷࡍʹࠣࡉͳ΍ΓऔΓ͕ൃੜ
 (εϖʔεɺΠϯσϯτɺվߦҐஔ౳) • ίʔυελΠϧ͕౷Ұ͞Εͳ͘ͳΓอकੑͷ ௿Լ • ଞਓ͕ॻ͍ͨίʔυͷՄಡੑ͕Լ͕Δ

  7. ͳΜͱ͔͠ͳ͍ͱ…!

  8. 3STEPͰίʔσΟϯάن໿Λ खʹೖΕΔ

  9. ͨͱ͑͹…͜ΜͳPJT • طʹ։ൃ͕͔ͳΓਐΜͰ͍ΔPJT • ίʔσΟϯάن໿͸ࠓͷͱ͜Ζͳ͍ • ނʹphpcsͳͲΛී௨ʹ࢖͏ͱΤϥʔ͕େྔ ʹग़ͯਏ͍ => Ͳ͏΍ͬͯίʔσΟϯάن໿Λ࡞Δ͔ʁ

  10. STEP1. ࠾༻͢Δن໿ΛܾΊΔ • ࠓ͔Β৽͘͠ίʔσΟϯάن໿Λ࠾༻͢Δͱ ͨ͠ΒPSR-2 • ࣍఺Ͱ࢖༻͍ͯ͠ΔFWಠࣗͷن໿(ex. Cake)

  11. STEP2. νΣοΫπʔϧΛ༻ҙ • StyleCI΍ScrutinizerͳͲͷSaas΋͋Δ͕
 ͓ೃછΈ phpcs (PHP CodeSniffer) ͕͓͢͢Ί •

    ΧελϚΠζੑͷߴ͞ɺແྉɺ(ރΕͯΔ) • ͨͩ͠ී௨ʹ΍ͬͯ΋্ख͘ߦ͔ͳ͍
  12. ී௨ʹ΍Δͱ͜͏ͳΔ Τϥʔग़ྗߦ਺ 65,000…….. ࣮ߦ࣌ؒ 27ඵ… ※ Vender/ ΍ Plugin/ ഑Լ΋ؚΜͰ͍ΔͷͰ࣮ࡍ͸΋ͬͱগͳ͘ͳΓ·͢ʢ੝ͬͨʣ

  13. None
  14. ͏·͍͘͘phpcs

  15. STEP2. νΣοΫπʔϧΛ༻ҙ • pearͰ͸ͳ͘composerͰΠϯετʔϧ // Πϯετʔϧ $ composer require “squizlabs/php_codesniffer=*"

    --dev 
 // ֬ೝʢར༻Ͱ͖Δن໿Λදࣔʣ $ vendor/bin/phpcs -i
  16. STEP2. νΣοΫπʔϧΛ༻ҙ • phpcs͸xmlͰن໿ΛΧελϚΠζͰ͖Δ • STEP1ͰܾΊͨن໿Λܧঝ͚ͨͩ͠ͷϑΝΠ ϧ phpcs.xmlΛͭ͘Δ // phpcs.xml

    <?xml version="1.0"?> <ruleset name="Owl_PSR2"> <description>Owl standard Based on PSR2</description> <rule ref="PSR2" /> </ruleset>
  17. STEP2. νΣοΫπʔϧΛ༻ҙ • ͓΋ΉΖʹɺԼهίϚϯυΛΞϓϦέʔγϣϯ શମ (./app) ʹର࣮ͯ͠ߦ $ vendor/bin/phpcs -s

    --report=source --standard=./ phpcs.xml ./app
  18. STEP2. νΣοΫπʔϧΛ༻ҙ • Τϥʔͱͯ͠ݕग़͞Εͨن໿ͱΤϥʔ݅਺͕ ιʔτ͞Εͯදࣔ͞ΕΔʢ௒ศར..!ʣ

  19. STEP2. νΣοΫπʔϧΛ༻ҙ • Τϥʔʹͳͬͨن໿ΛҰ౓શͯআ֎ (phpcs.xmlʹ௥ه) <?xml version="1.0"?> <ruleset name="Owl_PSR2"> <description>Owl

    standard Based on PSR2</description> <rule ref="PSR2"> <exclude name="Generic.WhiteSpace.DisallowTabIndent.TabsUsed"/> <!-- 145 --> <exclude name="Squiz.WhiteSpace.SuperfluousWhitespace.EndLine"/> <!-- 21 --> <exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine"/> <!-- 18 --> <exclude name="Generic.Files.LineLength.TooLong"/> <!-- 17 --> <exclude name="PSR2.Classes.ClassDeclaration.CloseBraceAfterBody"/> <!-- 16 --> <exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword"/> <!-- 9 --> <exclude name="Squiz.Functions.MultiLineFunctionDeclaration"/> <!-- 1 --> <exclude name="Generic.WhiteSpace.ScopeIndent.Incorrect"/> <!-- 1 --> </rule> </ruleset>
  20. STEP2. νΣοΫπʔϧΛ༻ҙ • ࠶౓phpcsΛ࣮ߦ͢ΔͱΤϥʔ͕ग़ͳ͘ͳΔɻ
 ˠ ʮ؇͍CodeSnifferʯͷ׬੒ $ vendor/bin/phpcs -s --report=source

    --standard=./ phpcs.xml ./app $ // Τϥʔ͕ͳ͍ͷͰ࣮ߦͯ͠΋Կ΋දࣔ͞Εͳ͍
  21. STEP2. νΣοΫπʔϧΛ༻ҙ • ࡉ͔͘ϑΣʔζΛ෼͚ͯ1ͭ1ͭআ֎ϧʔϧΛফ ͍ͯ͘͠ => ͍͔ͭࣗવͱ໨ඪͷن໿ʹͳΔʂ <?xml version="1.0"?> <ruleset

    name="Owl_PSR2"> <description>Owl standard Based on PSR2</description> <rule ref="PSR2"> <!-- Կ΋ͳ͘ͳΔͱPSR-2ͱಉ༷ͷϧʔϧͱͳΔʂ --> </rule> </ruleset>
  22. STEP2. νΣοΫπʔϧΛ༻ҙ • STEP2·ͱΊ 1. ໨ඪ(͜͜Ͱ͸PSR2)ΛϕʔεʹΤϥʔͱͳ͍ͬͯΔ
 ϧʔϧΛআ֎͠ɺʮ؇͍ن໿ʯΛ࡞Δ 2. ϑΣʔζຖʹϧʔϧͷআ֎Λ΍Ί͍͖ͯɺ
 গͣͭ͠໨ඪʹ͚͍ۙͮͯ͘

    3. શͯͷϧʔϧͷআ֎Λ΍Ίͨ࣌ɺ໨ඪͱಉ͡ن໿ͱͳΔ
  23. STEP3. CIʹ૊ΈࠐΈࣗಈ࣮ߦ • TravisCIΛ࢖͍ͬͯͨ৔߹ • .travis.ymlʹॲཧΛ௥Ճࣗ͠ಈͰ࣮ߦ͞ΕΔΑ ͏ʹ͢Δ • νΣοΫର৅Λίϛοτ͞ΕͨϑΝΠϧͷ͏ͪ phpϑΝΠϧͷΈʹݶఆ͢Δ


    (shʹ·ͱΊͯ΋ྑ͍)
  24. STEP3. CIʹ૊ΈࠐΈࣗಈ࣮ߦ // .travis.yml ~ུ~ before_script: # full clone -

    git fetch --unshallow - git fetch origin master:refs/remotes/origin/ master # setup application - sh ./setup_app.sh # exec codeSniffer - git diff --name-only --diff-filter=ACMR origin/master...HEAD | grep ".php" | xargs vendor/bin/phpcs --standard=./phpcs.xml PSJHJONBTUFSͱ )&"%Λൺֱͯࠩ͠෼͚ͩ νΣοΫ
  25. STEP3. CIʹ૊ΈࠐΈࣗಈ࣮ߦ shͰ·ͱΊɺϝοηʔδΛදࣔ͢Ε͹ΑΓ਌੾ɻ Τϥʔ͕͋ͬͨ৔߹͸Ϗϧυ͕ࣦഊ͢Δɻ

  26. ·ͱΊ • ؇͍ϧʔϧ͔Β࢝Ίͯ໨ඪ(PSR-2)ʹ͍͍ۙͮͯ͘ Ξϓϩʔν͕Φεεϝ • ίϛοτͨ͠ϑΝΠϧͷΈΛphpcsͷݕࠪର৅ͱ ͠ɺTravisͰࣗಈ࣮ߦ͢Δͱָ • ࠓ·ͰίʔσΟϯάن໿ΛఘΊ͍ͯͨ͋ͷPJT΋
 ͍͔ͭPSR-2ʹ४ڌͰ͖Δ͔΋ʁ

  27. ͓͠·͍