Successfully reported this slideshow.
Your SlideShare is downloading. ×

PHPMD, PHP_CodeSniffer x SideCIによる継続的コードチェック

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
PHPの今とこれから2017
PHPの今とこれから2017
Loading in …3
×

Check these out next

1 of 31 Ad

PHPMD, PHP_CodeSniffer x SideCIによる継続的コードチェック

Download to read offline

PHPMD, PHP_CodeSnifferの簡単な使い方、実行例、SideCIによる継続的コードレビューに関する資料です。「第90回 PHP勉強会@東京」のLTにて使用致しました。 #phpstudy

PHPMD, PHP_CodeSnifferの簡単な使い方、実行例、SideCIによる継続的コードレビューに関する資料です。「第90回 PHP勉強会@東京」のLTにて使用致しました。 #phpstudy

Advertisement
Advertisement

More Related Content

Similar to PHPMD, PHP_CodeSniffer x SideCIによる継続的コードチェック (20)

More from Koichiro Sumi (20)

Advertisement

Recently uploaded (20)

PHPMD, PHP_CodeSniffer x SideCIによる継続的コードチェック

  1. 1. [Confidential] © 2013 Actcat, Inc. 1 PHPMD, PHP_CodeSnifferを CIしてみた β
  2. 2. [Confidential] © 2013 Actcat, Inc. PHPMDってなに? 知ってる人ー?   (´・ω・`)ノシ 2
  3. 3. [Confidential] © 2013 Actcat, Inc. PHPMDとは n PHP  Mess  Detector   l PHP  ちらかった 検出器   l JavaのPMDにスピンオフプロジェクト   l http://phpmd.org/   n 例えばこんなのを発見   l =>  エラーに繋がりそうなコード、可読性 の低いコード、使っていないローカル変 数、巨大化したメソッド・クラス 3
  4. 4. [Confidential] © 2013 Actcat, Inc. 使い方 1.  Phar  or  ComposerでInstall   l  Pearではメンテされていません   2.  phpmd  [filename|directory]  [report  format]   [ruleset  file]  で実行   l  DirectoryにCakePHPのFrameworkなどで構築 されたアプリを指定すると実行に5分以上は かかるかも   3.  結果が出るよ 4
  5. 5. [Confidential] © 2013 Actcat, Inc. 実行例 / 結果例 ubuntu@6a727363ad6f:~$  phpmd  sideci_php_sandbox/app/ Controller/PagesController.php  text  cleancode,  codesize,   controversial,  design,  naming,  unusedcode   /home/ubuntu/sideci_php_sandbox/app/Controller/ PagesController.php:63  Avoid  using  static  access  to  class   'Inflector'  in  method  'display'.   /home/ubuntu/sideci_php_sandbox/app/Controller/ PagesController.php:70  Avoid  using  static  access  to  class   'Configure'  in  method  'display'.   PagesController.php:63  Avoid  using  static   access  to  class  'Inflector'  in  method  'display   5
  6. 6. [Confidential] © 2013 Actcat, Inc. コマンドラインだと見づらいよね…     ⇒ Editor連携しよう   or   ⇒ SideCIで使ってみよう   <=  今回はこっち 6
  7. 7. [Confidential] © 2013 Actcat, Inc. PHPMD on SideCI メソッドの複雑度が高い 7
  8. 8. [Confidential] © 2013 Actcat, Inc. 使われていないローカル変数、 短すぎて分かりづらい変数名 8
  9. 9. [Confidential] © 2013 Actcat, Inc. PHP_CodeSnifferってなに? 知ってる人ー?   (´・ω・`)ノシ 9
  10. 10. [Confidential] © 2013 Actcat, Inc. PHP_CodeSnifferとは n PHP_CodeSniffer   l コーディング規約チェックツール   l PHP,  CSS,  JavaScriptがコーディング規約を 順守しているかをチェック、違反を指摘 する   l https://github.com/squizlabs/ PHP_CodeSniffer   n 対応規約   l PSR2,  CodeIgniter  Style  Guide,  and  more…   10
  11. 11. [Confidential] © 2013 Actcat, Inc. 使い方 1.  Phar  or  Composer  or  PearでInstall   2.  phpcs  [filename|directory]  で実行   3.  結果が出るよ   4.  phpcbf  で自動修正も出来るよ   11
  12. 12. [Confidential] © 2013 Actcat, Inc. 実行例 / 結果例 ubuntu@f29257b092a4:~$  phpcs  sideci_php_sandbox/app/Controller/ PagesController.php       FILE:  ...ome/ubuntu/sideci_php_sandbox/app/Controller/ PagesController.php   -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐   FOUND  79  ERRORS  AND  3  WARNINGS  AFFECTING  41  LINES   -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐    14  |  ERROR      |  [  ]  The  tag  in  position  1  should  be  the  @package  tag    14  |  ERROR      |  [  ]  @copyright  tag  must  contain  a  year  and  the  name          |                  |          of  the  copyright  holder    14  |  ERROR      |  [x]  Tag  value  indented  incorrectly;  expected  1  spaces          |                  |          but  found  5    14  |  WARNING  |  [  ]  Line  exceeds  85  characters;  contains  90          |                  |          characters   12
  13. 13. [Confidential] © 2013 Actcat, Inc. コマンドラインだと見づらいよね…     ⇒ Editor連携しよう   or   ⇒ SideCIで使ってみよう   <=  今回はこっち 13
  14. 14. [Confidential] © 2013 Actcat, Inc. インデントはタブじゃなくてスペース! 14
  15. 15. [Confidential] © 2013 Actcat, Inc. メソッドには「@return」tagを含んだ コメント書いてよね! 15
  16. 16. [Confidential] © 2013 Actcat, Inc. PHPMD / PHP_CodeSniffer n PHPMD     l とりあえず入れておけば、あとで1メソッ ドが数百行になったりする確率は下がる   なるべくネストを浅く、変数名を readableに書くようになったりする   n PHP_CodeSniffer   l コーディング規約準拠にしたい場合に   l 規約を意識したコーディングが出来る   l phpcbfで一括修正してから運用しよう 16
  17. 17. [Confidential] © 2013 Actcat, Inc. 17 SIDECIの仕組み
  18. 18. [Confidential] © 2013 Actcat, Inc. How does it works? 18 hook PHP_CodeSniffer
  19. 19. [Confidential] © 2013 Actcat, Inc. 19 コードを共有のファイル置き場、   GitHub に保存すると  
  20. 20. [Confidential] © 2013 Actcat, Inc. 20 ソース   コード 解析 SideCIが自動でテストやコード解析を開始   今回の変更により発生した問題点を検出  
  21. 21. [Confidential] © 2013 Actcat, Inc. 21 GitHub上 のPullRequestにSideCIがコメント   プログラムとコラボした開発が出来る  
  22. 22. [Confidential] © 2013 Actcat, Inc. 22 SIDECI上で使えるアプリ
  23. 23. [Confidential] © 2013 Actcat, Inc. PHP_CodeSniffer, PHPMD コーディング規約 + スメル系 23
  24. 24. [Confidential] © 2013 Actcat, Inc. JSHint, CoffeeLint 24
  25. 25. [Confidential] © 2013 Actcat, Inc. 25 GitHub連携、Public/Privateの権限設定、   プロジェクト選択、アプリ選択で設定完了。   所要時間はおおよそ30秒  
  26. 26. [Confidential] © 2013 Actcat, Inc. 26 SideCI管理画面上で解析結果を確認。   新たに発生した問題や、継続中の問題を確認可能  
  27. 27. [Confidential] © 2013 Actcat, Inc. 27 SIDECIのご利用実績
  28. 28. [Confidential] © 2013 Actcat, Inc. Our Customers GitHub  +  Railsな開発体制のプロジェクトで   ご利用頂いております     n Weekly  Over  50  Projects  /  Companies   n Weekly  Over  1000  Comments   28 1名∼10名ほどのチームでご利用頂いています。   テレビCMなどで話題のベンチャーでも。  
  29. 29. [Confidential] © 2013 Actcat, Inc. 1クリックで ソフトウェア開発を より早くより良い品質に 29
  30. 30. [Confidential] © 2013 Actcat, Inc. 30 https://www.sideci.com/  
  31. 31. [Confidential] © 2013 Actcat, Inc. 31 設定は30秒で終わるヨ!   Just  nowでSign  Upして貰えると嬉しいです   https://www.sideci.com/  

×