LoginSignup
4
8

More than 5 years have passed since last update.

ATOMでPHPの静的コード解析する、『linter-phpmd』を使ってみた

Posted at

概要

最近何かとAtomの話題が出てくるので、Atomを利用し始めました。
Atom上でphpmdの結果を表示するプラグインを利用してみます。

前提条件

MacにてAtomを利用しています。
Macにphpmdが既にインストールされている状態です。
phpmdがインストールされていない場合、前回の記事にてインストールする手順を記載しています。

インストール

linterというものを利用します。以下の2つをAtomにインストールします。

apm install linter
apm install linter-phpmd

設定

.atom/config.csonに以下の設定を行います。
PHPMD_PATHと記載した場所に、phpmdをインストールしたpathを記載してください。
phpmdのルールについては、このまま記載していても大丈夫だと思います。

~/.atom/config.cson
'linter-phpmd':
  'phpmdExecutablePath': PHPMD_PATH #phpmd path. run 'which phpmd' to find the path
  'rulesets': 'cleancode,codesize,controversial,design,naming,unusedcode' #phpmd rulesets

動作確認

以下のファイルを用意します。

phpmdtest.php
<?php

class PhpMdTest
{
    public function test_function($param_string)
    {
        print "Hello World!!" . $param_string . "\n";
    }
}

$hoge_fuga = new PhpMdTest();
$hoge_fuga->test_function("( ゚д゚ )クワッ!!");

Atom上ではこんな感じで表示されます。

phpmd

camelCaseの指摘を直すと、解消されます。

phpmd

都度phpmdを叩かなくても済むのでいい感じですね。

参考にしたURL

4
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
8