Skip to content

Latest commit

 

History

History
203 lines (169 loc) · 7.05 KB

File metadata and controls

203 lines (169 loc) · 7.05 KB

PHPCS Rules vs Go PHP Parser Implementation

Overview

This document compares the available rules in PHP CodeSniffer (PHPCS) with the rules implemented in this Go-based PHP parser project.

Statistics Summary

  • PHPCS Rules Available: ~300+ rules across 50+ standards
  • Project Rules Implemented: 16 total
    • Style Rules: 13
    • Analysis Rules: 3

PHPCS Standards and Categories

Core Standards

  • PSR-1: Basic Coding Standard (implemented: 5/5 rules)
  • PSR-2: Coding Style Guide (implemented: 2/15+ rules)
  • PSR-12: Extended Coding Style Guide (implemented: 8/25+ rules)

Other Major Standards

  • PEAR: PEAR Coding Standards (implemented: 0/50+ rules)
  • Zend: Zend Framework Coding Standard (implemented: 0/40+ rules)
  • Squiz: Squiz Coding Standard (implemented: 0/100+ rules)
  • MySource: MySource Coding Standard (implemented: 0/30+ rules)

Detailed Rule Comparison

Implemented Rules in Go Project

Style Rules (14 rules)

  1. Generic.Arrays.DisallowLongArraySyntax - ✅ Implemented
  2. Generic.Formatting.DisallowMultipleStatements - ✅ Implemented
  3. Generic.Functions.FunctionCallArgumentSpacing - ✅ Implemented
  4. PSR1.Classes.ClassConstantName - ✅ Implemented
  5. PSR1.Classes.ClassDeclaration.PascalCase - ✅ Implemented
  6. PSR1.Classes.ClassInstantiation - ✅ Implemented
  7. PSR1.Methods.CamelCapsMethodName - ✅ Implemented
  8. PSR12.Classes.ClosingBraceOnOwnLine - ✅ Implemented
  9. PSR12.Classes.OpenBraceOnOwnLine - ✅ Implemented
  10. PSR12.Files.EndFileNewline - ✅ Implemented
  11. PSR12.Files.EndFileNoTrailingWhitespace - ✅ Implemented
  12. PSR12.Files.NoBlankLineAfterPHPOpeningTag - ✅ Implemented
  13. PSR12.Files.NoSpaceBeforeSemicolon - ✅ Implemented
  14. PSR12.Methods.VisibilityDeclared - ✅ Implemented

Analysis Rules (3 rules)

  1. A.RETURN.TYPE - ✅ Implemented (Return type checking)
  2. Generic.CodeAnalysis.AssignmentInCondition - ✅ Implemented
  3. PSR1.Files.SideEffects - ✅ Implemented

Major PHPCS Rules NOT Implemented

Code Quality Rules

  • Generic.CodeAnalysis.EmptyStatement
  • Generic.CodeAnalysis.ForLoopShouldBeWhileLoop
  • Generic.CodeAnalysis.JumbledIncrementer
  • Generic.CodeAnalysis.UnconditionalIfStatement
  • Generic.CodeAnalysis.UnnecessaryFinalModifier
  • Generic.CodeAnalysis.UselessOverridingMethod

Documentation Rules

  • Generic.Commenting.DocComment
  • Generic.Commenting.FileComment
  • Generic.Commenting.Fixme
  • Generic.Commenting.Todo
  • PEAR.Commenting.ClassComment
  • PEAR.Commenting.FileComment
  • PEAR.Commenting.FunctionComment

Control Structure Rules

  • Generic.ControlStructures.InlineControlStructure
  • PSR2.ControlStructures.ControlStructureSpacing
  • PSR2.ControlStructures.ElseIfDeclaration
  • PSR2.ControlStructures.SwitchDeclaration

Function Rules

  • Generic.Functions.CallTimePassByReference
  • Generic.Functions.FunctionCallArgumentSpacing (partially implemented)
  • Generic.Functions.OpeningFunctionBraceBsdAllman
  • PEAR.Functions.FunctionCallSignature
  • PEAR.Functions.ValidDefaultValue

Class Rules

  • Generic.Classes.DuplicateClassName
  • PSR2.Classes.ClassDeclaration
  • PSR2.Classes.PropertyDeclaration
  • Squiz.Classes.ValidClassName

Naming Convention Rules

  • Generic.NamingConventions.UpperCaseConstantName
  • PEAR.NamingConventions.ValidClassName
  • PEAR.NamingConventions.ValidFunctionName
  • PEAR.NamingConventions.ValidVariableName
  • Squiz.NamingConventions.ValidFunctionName
  • Squiz.NamingConventions.ValidVariableName

File Rules

  • Generic.Files.ByteOrderMark
  • Generic.Files.EndFileNewline (implemented)
  • Generic.Files.EndFileNoTrailingWhitespace (implemented)
  • Generic.Files.LineEndings
  • Generic.Files.LineLength
  • PSR2.Files.EndFileNewline (implemented)
  • Zend.Files.ClosingTag

Metric Rules

  • Generic.Metrics.CyclomaticComplexity
  • Generic.Metrics.NestingLevel

Operator Rules

  • Generic.Operators.ValidLogicalOperators
  • PSR2.Operators.OperatorSpacing

PHP Rules

  • Generic.PHP.BacktickOperator
  • Generic.PHP.DeprecatedFunctions
  • Generic.PHP.DisallowAlternativePHPTags
  • Generic.PHP.DisallowShortOpenTag
  • Generic.PHP.ForbiddenFunctions
  • Generic.PHP.LowerCaseConstant
  • Generic.PHP.LowerCaseKeyword
  • Generic.PHP.NoSilencedErrors
  • Generic.PHP.UpperCaseConstant

Security Rules

  • Generic.PHP.BacktickOperator
  • Generic.PHP.DiscourageGoto
  • Generic.PHP.EvalExpression
  • Generic.PHP.ExecutionOperator
  • Generic.PHP.ForbiddenFunctions

String Rules

  • Generic.Strings.UnnecessaryStringConcat
  • Squiz.Strings.ConcatenationSpacing
  • Squiz.Strings.DoubleQuoteUsage
  • Squiz.Strings.EchoedStrings

Variable Rules

  • Generic.Variables.VariableName
  • PSR2.Classes.PropertyDeclaration

WhiteSpace Rules

  • Generic.WhiteSpace.ArbitraryParenthesesSpacing
  • Generic.WhiteSpace.DisallowSpaceIndent
  • Generic.WhiteSpace.DisallowTabIndent
  • Generic.WhiteSpace.IncrementDecrementSpacing
  • Generic.WhiteSpace.LanguageConstructSpacing
  • Generic.WhiteSpace.ScopeIndent
  • PEAR.WhiteSpace.ObjectOperatorIndent
  • PEAR.WhiteSpace.ScopeClosingBrace
  • PEAR.WhiteSpace.ScopeIndent
  • PSR2.WhiteSpace.ObjectOperatorIndent
  • PSR2.WhiteSpace.ScopeClosingBrace
  • PSR2.WhiteSpace.ScopeIndent
  • Squiz.WhiteSpace.CastSpacing
  • Squiz.WhiteSpace.ControlStructureSpacing
  • Squiz.WhiteSpace.FunctionClosingBraceSpace
  • Squiz.WhiteSpace.FunctionOpeningBraceSpace
  • Squiz.WhiteSpace.FunctionSpacing
  • Squiz.WhiteSpace.LanguageConstructSpacing
  • Squiz.WhiteSpace.LogicalOperatorSpacing
  • Squiz.WhiteSpace.MemberVarSpacing
  • Squiz.WhiteSpace.ObjectOperatorSpacing
  • Squiz.WhiteSpace.OperatorSpacing
  • Squiz.WhiteSpace.PropertyLabelSpacing
  • Squiz.WhiteSpace.SemicolonSpacing
  • Squiz.WhiteSpace.SuperfluousWhitespace

Coverage Analysis

By Category

  • Files: ~20% implemented (2/10 major rules)
  • Classes: ~15% implemented (3/20 major rules)
  • Functions: ~5% implemented (1/20 major rules)
  • Control Structures: 0% implemented (0/15 major rules)
  • Naming: ~5% implemented (1/20 major rules)
  • Documentation: 0% implemented (0/15 major rules)
  • Security: 0% implemented (0/10 major rules)
  • Code Quality: ~15% implemented (3/20 major rules)

By PSR Standard

  • PSR-1: 100% implemented (5/5 rules)
  • PSR-2: ~13% implemented (2/15+ rules)
  • PSR-12: ~32% implemented (8/25+ rules)

Recommendations for Future Development

  1. High Priority: Implement core PSR-2 rules for broader compatibility
  2. Medium Priority: Add security-focused rules (eval, backticks, etc.)
  3. Medium Priority: Implement code quality analysis rules
  4. Low Priority: Add comprehensive documentation rules
  5. Low Priority: Implement PEAR and Zend standard rules

Current Project Focus

The Go PHP parser currently focuses on:

  • Basic syntax validation
  • Return type checking (analysis)
  • Fundamental PSR-12 style compliance
  • Minimal class and function structure validation

This represents a solid foundation that could be expanded with additional PHPCS-compatible rules as needed.