Skip to content

Commit

Permalink
Add PHPMD to dev tools
Browse files Browse the repository at this point in the history
- Add PHPMD
- Define ruleset.xml
- Ignore some complex code blocks
  • Loading branch information
gapple committed Feb 14, 2024
1 parent c7e89e8 commit 6897d27
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpmd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
tools: phpmd

- name: Run PHPMD
run: phpmd . sarif codesize --reportfile phpmd-results.sarif
run: phpmd --ignore-violations-on-exit . sarif phpmd.ruleset.xml --reportfile phpmd-results.sarif
continue-on-error: true

- name: Upload analysis results to GitHub
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"scripts": {
"phpcs": "phpcs",
"phpstan": "phpstan analyse",
"phpunit": "phpunit"
"phpunit": "phpunit",
"phpmd": "phpmd src,tests ansi phpmd.ruleset.xml"
},
"require": {
"php": "^7.3 || ^8.0",
Expand All @@ -34,6 +35,7 @@
"require-dev": {
"httpwg/structured-field-tests": "*@dev",
"paragonie/constant_time_encoding": "^2.6.3",
"phpmd/phpmd": "^2.15",
"phpstan/phpstan": "^1.9",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^9.5.27",
Expand Down
13 changes: 13 additions & 0 deletions phpmd.ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<ruleset name="PHPMD Ruleset"
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 Ruleset</description>

<rule ref="rulesets/codesize.xml"/>
<rule ref="rulesets/unusedcode.xml"/>
</ruleset>
6 changes: 6 additions & 0 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace gapple\StructuredFields;

/**
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class Parser
{
public static function parseDictionary(string $string): Dictionary
Expand Down Expand Up @@ -276,6 +279,9 @@ private static function parseString(string &$string): string
throw new ParseException("Invalid end of string");
}

/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private static function parseDisplayString(string &$string): DisplayString
{
if (strpos($string, '%"') !== 0) {
Expand Down
5 changes: 5 additions & 0 deletions src/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace gapple\StructuredFields;

/**
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class Serializer
{
/**
Expand Down Expand Up @@ -145,6 +148,8 @@ private static function serializeInnerList(array $value, ?object $parameters = n

/**
* @param mixed $value
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private static function serializeBareItem($value): string
{
Expand Down
3 changes: 3 additions & 0 deletions tests/Httpwg/HttpwgTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ abstract class HttpwgTest extends RulesetTest
*/
protected $ruleset;

/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function rulesetDataProvider(): array
{
$path = __DIR__ . '/../../vendor/httpwg/structured-field-tests/' . $this->ruleset . '.json';
Expand Down

0 comments on commit 6897d27

Please sign in to comment.