CakePHPでえいえいコーディングしてたらあれ?phpcsがどうにもひっかかってぽくない?と思い、st3のコンソールをだしてみたら、
[Phpcs] PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'DirectoryIterator::__construct(Vendor/cakephp/cakephp-codesniffer): failed to open dir: No such file or directory' in /Users/kmori/php/Vendor/squizlabs/php_codesniffer/CodeSniffer.php:1990
えー。phpcsがエラーだしてるやん…と思い、いろいろぐぐってみてもひっかからず…

phpcsのソースを見たところ、ああ…なるほど。installed_pathsが怪しい…のでフルパスで再セット。
phpcs --config-set installed_paths /Users/kmori/php/Vendor/cakephp/cakephp-codesniffer
んで再度save
[Phpcs] <?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="1.5.4">
<file name="/Users/kmori/git/***/***/Controller/AdminsController.php">
 <error line="21" column="2" severity="error" message="Doc blocks must not be indented" source="CakePHP.WhiteSpace.ScopeIndent.DocCommentStartColumn"/>
 <error line="34" column="2" severity="error" message="Doc blocks must not be indented" source="CakePHP.WhiteSpace.ScopeIndent.DocCommentStartColumn"/>
 <error line="40" column="1" severity="error" message="Parameters must appear immediately after the comment" source="CakePHP.Commenting.FunctionComment.SpacingBeforeParams"/>
 <error line="48" column="2" severity="error" message="Doc blocks must not be indented" source="CakePHP.WhiteSpace.ScopeIndent.DocCommentStartColumn"/>
 <error line="71" column="3" severity="error" message="Expected &quot;if (...) {\n&quot;; found &quot;if(...) {\n&quot;" source="PEAR.ControlStructures.ControlSignature"/>
 <error line="81" column="23" severity="error" message="Missing space after comma" source="CakePHP.WhiteSpace.CommaSpacing"/>
 <error line="84" column="3" severity="error" message="Expected &quot;if (...) {\n&quot;; found &quot;if(...) {\n&quot;" source="PEAR.ControlStructures.ControlSignature"/>
 <error line="113" column="27" severity="error" message="Missing space after comma" source="CakePHP.WhiteSpace.CommaSpacing"/>
 <error line="114" column="22" severity="error" message="Missing space after comma" source="CakePHP.WhiteSpace.CommaSpacing"/>
 <error line="115" column="62" severity="error" message="Missing space after comma" source="CakePHP.WhiteSpace.CommaSpacing"/>
 <error line="116" column="62" severity="error" message="Missing space after comma" source="CakePHP.WhiteSpace.CommaSpacing"/>
 <error line="125" column="2" severity="error" message="Doc blocks must not be indented" source="CakePHP.WhiteSpace.ScopeIndent.DocCommentStartColumn"/>
 <error line="139" column="26" severity="error" message="Expected 0 blank lines after opening function brace; 1 found" source="CakePHP.WhiteSpace.FunctionOpeningBraceSpace.SpacingAfter"/>
 <error line="144" column="18" severity="error" message="Missing space after comma" source="CakePHP.WhiteSpace.CommaSpacing"/>
 <error line="148" column="26" severity="error" message="Missing space after comma" source="CakePHP.WhiteSpace.CommaSpacing"/>
 <error line="150" column="18" severity="error" message="Missing space after comma" source="CakePHP.WhiteSpace.CommaSpacing"/>
 <error line="157" column="3" severity="error" message="Expected &quot;if (...) {\n&quot;; found &quot;if(...) {\n&quot;" source="PEAR.ControlStructures.ControlSignature"/>
 <error line="168" column="3" severity="error" message="Expected &quot;if (...) {\n&quot;; found &quot;if(...){\n&quot;" source="PEAR.ControlStructures.ControlSignature"/>
 <error line="169" column="4" severity="error" message="Expected &quot;foreach (...) {\n&quot;; found &quot;foreach (...){\n&quot;" source="PEAR.ControlStructures.ControlSignature"/>
 <error line="170" column="5" severity="error" message="Curly brackets required for if/elseif/else." source="CakePHP.ControlStructures.ControlStructures.NotAllowed"/>
 <error line="177" column="2" severity="error" message="Doc blocks must not be indented" source="CakePHP.WhiteSpace.ScopeIndent.DocCommentStartColumn"/>
 <error line="192" column="2" severity="error" message="Doc blocks must not be indented" source="CakePHP.WhiteSpace.ScopeIndent.DocCommentStartColumn"/>
 <error line="203" column="1" severity="error" message="Parameters must appear immediately after the comment" source="CakePHP.Commenting.FunctionComment.SpacingBeforeParams"/>
 <error line="225" column="2" severity="error" message="Doc blocks must not be indented" source="CakePHP.WhiteSpace.ScopeIndent.DocCommentStartColumn"/>
 <error line="241" column="12" severity="error" message="Missing space after comma" source="CakePHP.WhiteSpace.CommaSpacing"/>
 <error line="242" column="13" severity="error" message="Missing space after comma" source="CakePHP.WhiteSpace.CommaSpacing"/>
 <error line="255" column="2" severity="error" message="Doc blocks must not be indented" source="CakePHP.WhiteSpace.ScopeIndent.DocCommentStartColumn"/>
 <error line="283" column="2" severity="error" message="Doc blocks must not be indented" source="CakePHP.WhiteSpace.ScopeIndent.DocCommentStartColumn"/>
 <error line="289" column="1" severity="error" message="Parameters must appear immediately after the comment" source="CakePHP.Commenting.FunctionComment.SpacingBeforeParams"/>
 <error line="298" column="2" severity="error" message="Doc blocks must not be indented" source="CakePHP.WhiteSpace.ScopeIndent.DocCommentStartColumn"/>
 <error line="307" column="1" severity="error" message="Parameters must appear immediately after the comment" source="CakePHP.Commenting.FunctionComment.SpacingBeforeParams"/>
 <error line="310" column="37" severity="error" message="Expected 0 blank lines after opening function brace; 1 found" source="CakePHP.WhiteSpace.FunctionOpeningBraceSpace.SpacingAfter"/>
 <error line="321" column="19" severity="error" message="Missing space after comma" source="CakePHP.WhiteSpace.CommaSpacing"/>
</file>
</checkstyle>
治った。(※ 一部マスキングしております)

[ おまけ ]
cakephpは$idよく使うので、phpmdのShortVariableに引っかからないようにしたかったので、phpmd_additional_argsを修正
 
    "phpmd_additional_args": {
        "/Users/kmori/php/config/phpmd.xml": ""
    },

こうして、phpmd.xmlはこんな感じにしてあります。
尚、つぎはぎでいろんな所からかっぱらってきた模様。
<?xml version="1.0" encoding="UTF-8"?>
<!--
    PHPMD rule set file.
    @link http://phpmd.org/
-->
<ruleset name="PHPMD rule set for CakePHP"
    xmlns="http://pmd.sf.net/ruleset/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
    http://pmd.sf.net/ruleset_xml_schema.xsd"
    xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">

    <description>PHPMD rule set for CakePHP</description>

    <!-- Import rule set -->
    <rule ref="rulesets/codesize.xml" />
    <rule ref="rulesets/design.xml" />
    <rule ref="rulesets/naming.xml">
        <!-- Exclude the rule for variable like $id, that baked by CakePHP. -->
        <exclude name="ShortVariable" />
    </rule>
    <rule ref="rulesets/naming.xml/ShortVariable"
          since="0.2"
          message="Avoid variables with short names like {0}. Configured minimum length is {1}."
          class="PHPMD\Rule\Naming\ShortVariable"
          externalInfoUrl="http://phpmd.org/rules/naming.html#shortvariable">
        <priority>3</priority>
        <properties>
            <property name="minimum" description="Minimum length for a variable, property or parameter name" value="3"/>
            <property name="exceptions" value="id,q,w,i,j,v,e,f,fp" />
        </properties>
    </rule>
    <rule ref="rulesets/unusedcode.xml" />

</ruleset>

Add Comments

名前
URL
 
  絵文字
 
 

Trackback URL

livedoor プロフィール
Twitter
instagram(SnapWidget)
タグクラウド
  • ライブドアブログ