<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # PHPMD(PHP Mess Detector)規則集 ## 規則集列表 - [Clean Code Rules](#1): 強化代碼整潔度的規則集,來自[SOLID](#solid)原則和“[對象健身操](#object_calisthenics)”原則。 - [Code Size Rules](#2): 代碼尺寸規則集. - [Controversial Rules](#3): 有爭議的代碼規則. - [Design Rules](#4): 軟件設計的相關問題規則集. - [Naming Rules](#5): 名稱太長,規則太短,等等規則集. - [Unused Code Rules](#6): 找到未使用的代碼的規則集. ## Clean Code Rules<span id="1"></span> - [BooleanArgumentFlag](http://phpmd.org/rules/cleancode.html#booleanargumentflag): 布爾參數是違反單一責任原則 (SRP) 的可靠指標。你可以通過提取這個標志中的邏輯到其自己的類或方法來解決此問題。 - [ElseExpression](http://phpmd.org/rules/cleancode.html#elseexpression): if表達式中的else分支并不是必須的。你可以重寫條件,去掉else,這樣代碼更簡單。你可能在代碼中就要使用return,或者把代碼分成幾個小的方法。對于更為簡單的情況,可以直接用三元表達式。 - [StaticAccess](http://phpmd.org/rules/cleancode.html#staticaccess): 靜態訪問(Static acccess)導致對其他類無法改變的依賴關系,而且難以測試代碼。應該想方設法避免靜態訪問。你可以通過構造器注入依賴的方式,代替靜態訪問。只有在使用工廠方法的時候,靜態訪問才是合適的。 ## Code Size Rules<span id="2"></span> - [CyclomaticComplexity](http://phpmd.org/rules/codesize.html#cyclomaticcomplexity):復雜性是由方法內關鍵點的個數加1來確定的。關鍵點有'if','while','for'和 'case labels'。一般來說,1-4復雜度低,5-7是適度的復雜性,8-10是高度復雜的,而11+有很高的復雜性。 - [NPathComplexity](http://phpmd.org/rules/codesize.html#npathcomplexity):一個方法的NPath復雜性是通過其中非循環執行路徑的數量來確定的。200被認為是必須降低復雜性的閥值。 - [ExcessiveMethodLength](http://phpmd.org/rules/codesize.html#excessivemethodlength): 違反此規則通常表明該方法做的太多了。通過創建輔助方法和消除任何復制/粘貼代碼的形式盡量減小方法體。 - [ExcessiveClassLength](http://phpmd.org/rules/codesize.html#excessiveclasslength):過長的類文件表名它試圖做的操作太多。可以通過拆分和減小類所管理的對象來重組它。 - [ExcessiveParameterList](http://phpmd.org/rules/codesize.html#excessiveparameterlist):長參數列表表明一個新的對象需要被創建以包容眾多參數。基本上,可以嘗試分組參數。 - [ExcessivePublicCount](http://phpmd.org/rules/codesize.html#excessivepubliccount):類中有大量的公共方法和屬性聲明表明這個類需要阻斷其增長,并進行徹底的測試。 - [TooManyFields](http://phpmd.org/rules/codesize.html#toomanyfields): 有太多字段的類可以考慮重新設計(可能是將一些信息打包為嵌套對象的方法)來減少字段。比如,類中的city/state/zip字段可以合并成一個Address字段。 - [TooManyMethods](http://phpmd.org/rules/codesize.html#toomanymethods): 一個類有太多的方法,將其重構是最好的選擇,以減少其復雜性和找到更細粒度的對象。 - [ExcessiveClassComplexity](http://phpmd.org/rules/codesize.html#excessiveclasscomplexity):確定一個類進行修改和維護需要多少時間和精力時,加權方法計數(WMC:The Weighted Method Count)是一個很好的指標。WMC定義為在類中聲明的所有方法復雜度的總和。大量的方法也意味著這個類對其派生類有更大的潛在影響。 ## Controversial Rules<span id="3"></span> - [Superglobals](http://phpmd.org/rules/controversial.html#superglobals):直接訪問超級全局變量是一個很差的做法。舉個例子,這些變量應該被封裝在由框架提供的對象里。 - [CamelCaseClassName](http://phpmd.org/rules/controversial.html#camelcaseclassname):最好使用CamelCase標記法命名類。 - [CamelCasePropertyName](http://phpmd.org/rules/controversial.html#camelcasepropertyname): 最好使用CamelCase標記法命名屬性。 - [CamelCaseMethodName](http://phpmd.org/rules/controversial.html#camelcasemethodname):最好使用CamelCase標記法命名方法。 - [CamelCaseParameterName](http://phpmd.org/rules/controversial.html#camelcaseparametername):最好使用CamelCase標記法命名參數。 - [CamelCaseVariableName](http://phpmd.org/rules/controversial.html#camelcasevariablename):最好使用CamelCase標記法命名變量。 ## Design Rules<span id="4"></span> - [ExitExpression](http://phpmd.org/rules/design.html#exitexpression): 正常代碼里存在exit-expression就會變得不可測試,所以要避免。可以將exit-expression轉化為某種類型的啟動腳本,其中錯誤/異常代碼被返回到調用環境。 - [EvalExpression](http://phpmd.org/rules/design.html#evalexpression): eval-expression是不可測試的,有安全風險,而且是一種壞實踐。我們要避免它。應該用符合常規的代碼替代它。 - [GotoStatement](http://phpmd.org/rules/design.html#gotostatement):Goto使代碼難以閱讀,無法了解應用程序的控制流結構。因此必須避免。可以用常規的控制結構和分離的方法/函數代替。 - [NumberOfChildren](http://phpmd.org/rules/design.html#numberofchildren):一個類擁有過多的子類,是不平衡的類層次結構的一個指標。此時應該對這個類的層次結構進行重構。 - [DepthOfInheritance](http://phpmd.org/rules/design.html#depthofinheritance):一個類的繼承深度過多,是不平衡的類層次結構的一個指標。此時應該對這類層次結構進行重構。 - [CouplingBetweenObjects](http://phpmd.org/rules/design.html#couplingbetweenobjects):一個類存在過多的外部依賴會對其產生幾個質量方面的負面影響:如穩定性、可維護性、可理解性。 ## Naming Rules<span id="5"></span> - [ShortVariable](http://phpmd.org/rules/naming.html#shortvariable):字段、局部變量或參數定義名稱過短。 - [LongVariable](http://phpmd.org/rules/naming.html#longvariable):字段、局部變量定義名稱過長。 - [ShortMethodName](http://phpmd.org/rules/naming.html#shortmethodname): 方法名過短。 - [ConstructorWithNameAsEnclosingClass](http://phpmd.org/rules/naming.html#constructorwithnameasenclosingclass):構造函數方法不應該和封裝的類有相同的名稱,應參照PHP 5 __construct方法來命名。 - [ConstantNamingConventions](http://phpmd.org/rules/naming.html#constantnamingconventions):類/接口常量必須用大寫字母定義。 - [BooleanGetMethodName](http://phpmd.org/rules/naming.html#booleangetmethodname):返回值為布爾型而以'getX()'格式命名的方法。習慣上此類方法的命名格式是 'isX()' 或者 'hasX()'。 ## Unused Code Rules<span id="6"></span> - [UnusedPrivateField](http://phpmd.org/rules/unusedcode.html#unusedprivatefield):存在已聲明或賦值的私有字段,但是卻未使用。 - [UnusedLocalVariable](http://phpmd.org/rules/unusedcode.html#unusedlocalvariable): 存在已聲明或賦值的局部變量,但是卻未使用。 - [UnusedPrivateMethod](http://phpmd.org/rules/unusedcode.html#unusedprivatemethod):存在已聲明但未使用的私有方法。 - [UnusedFormalParameter](http://phpmd.org/rules/unusedcode.html#unusedformalparameter): 避免將參數傳遞給方法或構造函數,然后不使用這些參數。 ## Remark This document is based on a ruleset xml-file, that was taken from the original source of the [PMD](http://pmd.sourceforge.net/) project. This means that most parts of the content on this page are the intellectual work of the PMD community and its contributors and not of the PHPMD project. ## 譯注 - <dfn id="solid">SOLID原則:</dfn>面向對象5個基本原則,參考http://www.cnblogs.com/shanyou/archive/2009/09/21/1570716.html - <dfn id="object_calisthenics">對象健身操:</dfn>即object calisthenics,由ThoughtWorks提出的一種設計規則集,參考http://blog.csdn.net/chgaowei/article/details/5456201
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看