phpmd, php_codesniffer x sideciによる継続的コードチェック

Post on 22-Jul-2015

343 Views

Category:

Engineering

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

[Confidential] © 2013 Actcat, Inc. 1

PHPMD, PHP_CodeSnifferを CIしてみた

β

[Confidential] © 2013 Actcat, Inc.

PHPMDってなに?

知ってる人ー?  (´・ω・`)ノシ

2

[Confidential] © 2013 Actcat, Inc.

PHPMDとは

n PHP  Mess  Detector  l PHP  ちらかった 検出器  l JavaのPMDにスピンオフプロジェクト  l http://phpmd.org/  

n 例えばこんなのを発見  l =>  エラーに繋がりそうなコード、可読性の低いコード、使っていないローカル変数、巨大化したメソッド・クラス

3

[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

[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

[Confidential] © 2013 Actcat, Inc.

コマンドラインだと見づらいよね…    

⇒ Editor連携しよう  or  

⇒ SideCIで使ってみよう  <=  今回はこっち

6

[Confidential] © 2013 Actcat, Inc.

PHPMD on SideCI メソッドの複雑度が高い

7

[Confidential] © 2013 Actcat, Inc.

使われていないローカル変数、 短すぎて分かりづらい変数名

8

[Confidential] © 2013 Actcat, Inc.

PHP_CodeSnifferってなに?

知ってる人ー?  (´・ω・`)ノシ

9

[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

[Confidential] © 2013 Actcat, Inc.

使い方

1.  Phar  or  Composer  or  PearでInstall  

2.  phpcs  [filename|directory]  で実行  

3.  結果が出るよ  

4.  phpcbf  で自動修正も出来るよ  

11

[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

[Confidential] © 2013 Actcat, Inc.

コマンドラインだと見づらいよね…    

⇒ Editor連携しよう  or  

⇒ SideCIで使ってみよう  <=  今回はこっち

13

[Confidential] © 2013 Actcat, Inc.

インデントはタブじゃなくてスペース!

14

[Confidential] © 2013 Actcat, Inc.

メソッドには「@return」tagを含んだ コメント書いてよね!

15

[Confidential] © 2013 Actcat, Inc.

PHPMD / PHP_CodeSniffer

n PHPMD    l とりあえず入れておけば、あとで1メソッドが数百行になったりする確率は下がる  なるべくネストを浅く、変数名をreadableに書くようになったりする  

n PHP_CodeSniffer  l コーディング規約準拠にしたい場合に  l 規約を意識したコーディングが出来る  l phpcbfで一括修正してから運用しよう

16

[Confidential] © 2013 Actcat, Inc. 17

SIDECIの仕組み

[Confidential] © 2013 Actcat, Inc.

How does it works?

18

hook

PHP_CodeSniffer

[Confidential] © 2013 Actcat, Inc. 19

コードを共有のファイル置き場、  GitHub に保存すると  

[Confidential] © 2013 Actcat, Inc. 20

ソース  コード 解析

SideCIが自動でテストやコード解析を開始  今回の変更により発生した問題点を検出  

[Confidential] © 2013 Actcat, Inc. 21

GitHub上 のPullRequestにSideCIがコメント  プログラムとコラボした開発が出来る  

[Confidential] © 2013 Actcat, Inc. 22

SIDECI上で使えるアプリ

[Confidential] © 2013 Actcat, Inc.

PHP_CodeSniffer, PHPMD コーディング規約 + スメル系

23

[Confidential] © 2013 Actcat, Inc.

JSHint, CoffeeLint

24

[Confidential] © 2013 Actcat, Inc. 25

GitHub連携、Public/Privateの権限設定、  プロジェクト選択、アプリ選択で設定完了。  

所要時間はおおよそ30秒  

[Confidential] © 2013 Actcat, Inc. 26

SideCI管理画面上で解析結果を確認。  新たに発生した問題や、継続中の問題を確認可能  

[Confidential] © 2013 Actcat, Inc. 27

SIDECIのご利用実績

[Confidential] © 2013 Actcat, Inc.

Our Customers

GitHub  +  Railsな開発体制のプロジェクトで  ご利用頂いております    n Weekly  Over  50  Projects  /  Companies  n Weekly  Over  1000  Comments  

28

1名~10名ほどのチームでご利用頂いています。  テレビCMなどで話題のベンチャーでも。  

[Confidential] © 2013 Actcat, Inc.

1クリックで ソフトウェア開発を より早くより良い品質に

29

[Confidential] © 2013 Actcat, Inc. 30

https://www.sideci.com/  

[Confidential] © 2013 Actcat, Inc. 31

設定は30秒で終わるヨ!  Just  nowでSign  Upして貰えると嬉しいです  

https://www.sideci.com/  

top related