Project

General

Profile

Actions

Enhancement(機能追加・改善) #2498

open

実行できるPHP_CodeSnifferのバージョンを1.2.2から1.3.0に上げる

Added by Yuya Watanabe over 13 years ago. Updated almost 5 years ago.

Status:
New(新規)
Priority:
Normal(通常)
Assignee:
-
Target version:
Start date:
2011-10-17
Due date:
% Done:

0%

Estimated time:

Description

概要

data/CodingStandard以下にはPHP_CodeSnifferによってコーディングスタンダートをチェックするための定義があるが,これらはPHP_CodeSnifferの1.2.2で動作するものである.現在の最新の安定版は1.3.0であるが現状の定義では動作しない.これのバージョンアップの必要性及びバージョンアップの方法などについてを検討する.

参考URL

PHP_CodeSnifferのサイト
http://pear.php.net/package/PHP_CodeSniffer

Actions #1

Updated by Yuya Watanabe over 13 years ago

動作確認

Ubuntu 11.04 で下記手順で動作確認したところPHP_CodeSniffer 1.3.0 でも動作したことを確認.ただし動作しただけで正しく動いているわけではない.

  1. PEARでPHP_CodeSniffer 1.3.0 をインストール
  2. data/CodingStandard/OpenPNE3/ruleset.xmlを追加して以下の内容を記述
    <?xml version="1.0"?>
    <ruleset name="OpenPNE3">
     <description>OpenPNE3 coding standard.</description>
    </ruleset>
    
  1. data/CodingStandard/OpenPNE3/Sniffs/WhiteSpace/ScopeIndentSniff.php のprotectedをpublicに変える
    diff --git a/data/CodingStandard/OpenPNE3/Sniffs/WhiteSpace/ScopeIndentSniff.php b/data/CodingStandard/OpenPNE3/Sniffs/WhiteSpace/ScopeIndentSniff.php
    index c79cc5c..699e652 100644
    --- a/data/CodingStandard/OpenPNE3/Sniffs/WhiteSpace/ScopeIndentSniff.php
    +++ b/data/CodingStandard/OpenPNE3/Sniffs/WhiteSpace/ScopeIndentSniff.php
    @@ -16,5 +16,5 @@
      */
     class OpenPNE3_Sniffs_WhiteSpace_ScopeIndentSniff extends Generic_Sniffs_WhiteSpace_ScopeIndentSniff
     {
    -  protected $indent = 2;
    +  public $indent = 2;
     }
    
  1. 下記コマンドを実行
    phpcs --standard=data/CodingStandard/OpenPNE3 --ignore="lib/vendor*","*/base/*","test/*","data/*","plugins/*","web/*","*/templates/*","cache/*","config/*","*/op*Plugin*/*" --report-file=$OPENPNE_DIR/log/checkstyle-result.xml --report=checkstyle .
    
  • log/checkstype-result.xmlに実行結果が出力されている
Actions #2

Updated by Yuya Watanabe over 13 years ago

補足

if (...) などの直後が改行であるべきなどのコーディングスタンダードについて空白によって不正確なチェックが行われていたので以下のように修正することを提案.

diff --git a/data/CodingStandard/OpenPNE3/Sniffs/WhiteSpace/ControlSignatureSniff.php b/data/CodingStandard/OpenPNE3/Sniffs/WhiteSpace/ControlSignatureSniff.php
index d89fd62..b05ca6a 100644
--- a/data/CodingStandard/OpenPNE3/Sniffs/WhiteSpace/ControlSignatureSniff.php
+++ b/data/CodingStandard/OpenPNE3/Sniffs/WhiteSpace/ControlSignatureSniff.php
@@ -19,14 +19,14 @@ class OpenPNE3_Sniffs_WhiteSpace_ControlSignatureSniff extends PHP_CodeSniffer_S
   protected function getPatterns()
   {
     return array(
-       'tryEOL{EOL...}EOLcatch (...)EOL{EOL',
-       'doEOL{EOL...}EOLwhile (...);EOL',
-       'while (...)EOL{EOL',
-       'for (...)EOL{EOL',
-       'if (...)EOL{EOL',
-       'foreach (...)EOL{EOL',
-       '}EOLelseif (...)EOL{EOL',
-       '}EOLelseEOL{EOL',
+       'tryEOL *{EOL...}EOL *catch (...)EOL *{EOL',
+       'doEOL *{EOL...}EOL *while (...);EOL',
+       'while (...)EOL *{EOL',
+       'for (...)EOL *{EOL',
+       'if (...)EOL *{EOL',
+       'foreach (...)EOL *{EOL',
+       '}EOL *elseif (...)EOL *{EOL',
+       '}EOL *elseEOL *{EOL',
     );
   }
 }
Actions #3

Updated by kaoru n almost 5 years ago

  • Target version set to OpenPNE 3.10.x
Actions

Also available in: Atom PDF