SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
PHP

PHP static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your PHP code

  • All rules 273
  • Vulnerability42
  • Bug51
  • Security Hotspot34
  • Code Smell146
Filtered: 25 rules found
regex
    Impact
      Clean code attribute
        1. Character classes in regular expressions should not contain only one character

           Code Smell
        2. Superfluous curly brace quantifiers should be avoided

           Code Smell
        3. Non-capturing groups without quantifier should not be used

           Code Smell
        4. Regular expressions should have valid delimiters

           Bug
        5. Regular expression quantifiers and character classes should be used concisely

           Code Smell
        6. Regular expressions should not contain empty groups

           Code Smell
        7. Replacement strings should reference existing regular expression groups

           Bug
        8. Regular expressions should not contain multiple spaces

           Code Smell
        9. Alternation in regular expressions should not contain empty alternatives

           Bug
        10. Single-character alternations in regular expressions should be replaced with character classes

           Code Smell
        11. Reluctant quantifiers in regular expressions should be followed by an expression that can't match the empty string

           Code Smell
        12. Regex lookahead assertions should not be contradictory

           Bug
        13. Back references in regular expressions should only refer to capturing groups that are matched before the reference

           Bug
        14. Regex boundaries should not be used in a way that can never be matched

           Bug
        15. Regex patterns following a possessive quantifier should not always fail

           Bug
        16. Character classes in regular expressions should not contain the same character twice

           Code Smell
        17. Unicode Grapheme Clusters should be avoided inside regex character classes

           Bug
        18. Unicode-aware versions of character classes should be preferred

           Code Smell
        19. Character classes should be preferred over reluctant quantifiers in regular expressions

           Code Smell
        20. Regular expressions should be syntactically valid

           Bug
        21. Regex alternatives should not be redundant

           Bug
        22. Alternatives in regular expressions should be grouped when used with anchors

           Bug
        23. Regular expressions should not be too complicated

           Code Smell
        24. Repeated patterns in regular expressions should not match the empty string

           Bug
        25. `str_replace` should be preferred to `preg_replace`

           Code Smell

        Single-character alternations in regular expressions should be replaced with character classes

        intentionality - efficient
        maintainability
        Code Smell
        • regex

        Why is this an issue?

        When an alternation contains multiple alternatives that consist of a single character, it can be rewritten as a character class. This should be preferred because it is more efficient.

        Noncompliant code example

        preg_match("/a|b|c/", $str); // Noncompliant
        

        Compliant solution

        preg_match("/[abc]/", $str);
        // or
        preg_match("/[a-c]/", $str);
        
          Available In:
        • SonarQube IdeCatch issues on the fly,
          in your IDE
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories
        • SonarQube Community BuildAnalyze code in your
          on-premise CI
          Available Since
          9.1
        • SonarQube ServerAnalyze code in your
          on-premise CI
          Developer Edition
          Available Since
          9.1

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use