Contenu connexe
Similaire à PHPMD, PHP_CodeSniffer x SideCIによる継続的コードチェック (20)
Plus de Koichiro Sumi (20)
PHPMD, PHP_CodeSniffer x SideCIによる継続的コードチェック
- 3. [Confidential] © 2013 Actcat, Inc.
PHPMDとは
n PHP
Mess
Detector
l PHP
ちらかった 検出器
l JavaのPMDにスピンオフプロジェクト
l http://phpmd.org/
n 例えばこんなのを発見
l =>
エラーに繋がりそうなコード、可読性
の低いコード、使っていないローカル変
数、巨大化したメソッド・クラス
3
- 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. [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
- 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. [Confidential] © 2013 Actcat, Inc.
使い方
1. Phar
or
Composer
or
PearでInstall
2. phpcs
[filename|directory]
で実行
3. 結果が出るよ
4. phpcbf
で自動修正も出来るよ
11
- 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. [Confidential] © 2013 Actcat, Inc.
コマンドラインだと見づらいよね…
⇒ Editor連携しよう
or
⇒ SideCIで使ってみよう
<=
今回はこっち
13
- 16. [Confidential] © 2013 Actcat, Inc.
PHPMD / PHP_CodeSniffer
n PHPMD
l とりあえず入れておけば、あとで1メソッ
ドが数百行になったりする確率は下がる
なるべくネストを浅く、変数名を
readableに書くようになったりする
n PHP_CodeSniffer
l コーディング規約準拠にしたい場合に
l 規約を意識したコーディングが出来る
l phpcbfで一括修正してから運用しよう
16
- 25. [Confidential] © 2013 Actcat, Inc. 25
GitHub連携、Public/Privateの権限設定、
プロジェクト選択、アプリ選択で設定完了。
所要時間はおおよそ30秒
- 28. [Confidential] © 2013 Actcat, Inc.
Our Customers
GitHub
+
Railsな開発体制のプロジェクトで
ご利用頂いております
n Weekly
Over
50
Projects
/
Companies
n Weekly
Over
1000
Comments
28
1名∼10名ほどのチームでご利用頂いています。
テレビCMなどで話題のベンチャーでも。
- 31. [Confidential] © 2013 Actcat, Inc. 31
設定は30秒で終わるヨ!
Just
nowでSign
Upして貰えると嬉しいです
https://www.sideci.com/