From ef98947b1af094d94eb979d6504f5cc5dc355c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Arroyo?= Date: Fri, 26 May 2023 16:10:49 +0200 Subject: [PATCH 01/13] feat: Add PHP-MD step in the pipelines --- .github/phpmd-ruleset.xml | 64 +++++++++++++++++++++++++++++++++++ .github/workflows/php-md.yaml | 21 ++++++++++++ controller/HighCC.php | 47 +++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 .github/phpmd-ruleset.xml create mode 100644 .github/workflows/php-md.yaml create mode 100644 controller/HighCC.php diff --git a/.github/phpmd-ruleset.xml b/.github/phpmd-ruleset.xml new file mode 100644 index 000000000..a56788b40 --- /dev/null +++ b/.github/phpmd-ruleset.xml @@ -0,0 +1,64 @@ + + + + + + + + + --> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.github/workflows/php-md.yaml b/.github/workflows/php-md.yaml new file mode 100644 index 000000000..a9724a352 --- /dev/null +++ b/.github/workflows/php-md.yaml @@ -0,0 +1,21 @@ +name: PHP Mess Detector + +on: push + +jobs: + phpmd: + name: PHP Mess Detector + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP environment + uses: shivammathur/setup-php@v2 + with: + coverage: none + tools: phpmd + + - name: PHP Mess Detector + run: phpmd . github .github/phpmd-ruleset.xml --exclude 'vendor/*' diff --git a/controller/HighCC.php b/controller/HighCC.php new file mode 100644 index 000000000..97498f798 --- /dev/null +++ b/controller/HighCC.php @@ -0,0 +1,47 @@ + Date: Fri, 26 May 2023 18:20:15 +0200 Subject: [PATCH 02/13] chore: Remove the noise from other linter tests --- controller/HighCC.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/controller/HighCC.php b/controller/HighCC.php index 97498f798..70de9915c 100644 --- a/controller/HighCC.php +++ b/controller/HighCC.php @@ -7,9 +7,9 @@ class HighCC { public function example() { - $a=$b=2; - $a1=$a2=$b1=$b2=$c=$d=1; - $e=$f=$h=$z=1; + $a =$b=2; + $a1 = $a2 = $b1 = $b2 = $c = $d = 1; + $e = $f = $h = $z = 1; if ($a == $b) { if ($a1 == $b1) { From d6e743b848de3dca0db5f458ae4191b9e450f76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Arroyo?= Date: Mon, 11 Dec 2023 16:03:01 +0100 Subject: [PATCH 03/13] feat: Run cyclomatic complexity checks only on changed files --- .github/workflows/php-md.yaml | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php-md.yaml b/.github/workflows/php-md.yaml index a9724a352..1a3e31382 100644 --- a/.github/workflows/php-md.yaml +++ b/.github/workflows/php-md.yaml @@ -17,5 +17,26 @@ jobs: coverage: none tools: phpmd - - name: PHP Mess Detector - run: phpmd . github .github/phpmd-ruleset.xml --exclude 'vendor/*' + - name: Run PHP Mess Detector on modified files + shell: bash + run: | + RETVAL=0 + FILELIST=$(mktemp /tmp/phpmd-check.XXXXXX) + mapfile -d ',' -t added_modified_files < <(printf '%s,' '${{ steps.files.outputs.added_modified }}') + for FILE in "${added_modified_files[@]}"; do + EXT="${FILE##*.}" + echo "Changed file: " $FILE ", extension: " $EXT + if [[ "$EXT" == "php" ]]; then + echo "src/${FILE}" >> "${FILELIST}" + echo "File added to the file list: " $FILE + fi + done + if [ -s "${FILELIST}" ]; then + FILES=`cat ${FILELIST} | paste -sd "," -` + echo "Running PHPMD on" $FILES + phpmd $FILES github .github/phpmd-ruleset.xml --exclude 'vendor/*' + RETVAL=$? + else + echo "There are no changes in PHP files (no PHP-MD test performed)" + fi + exit $RETVAL From c42f4d7cdfd48bf1c9f7088da3952c58d9b2963f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Arroyo?= Date: Mon, 11 Dec 2023 16:19:46 +0100 Subject: [PATCH 04/13] chore: Debug --- .github/workflows/php-md.yaml | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/.github/workflows/php-md.yaml b/.github/workflows/php-md.yaml index 1a3e31382..b940e7b9c 100644 --- a/.github/workflows/php-md.yaml +++ b/.github/workflows/php-md.yaml @@ -1,7 +1,6 @@ name: PHP Mess Detector on: push - jobs: phpmd: name: PHP Mess Detector @@ -9,7 +8,15 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get changed files + uses: tj-actions/changed-files@v40 + id: changed-files + with: + since_last_remote_commit: false - name: Setup PHP environment uses: shivammathur/setup-php@v2 @@ -20,23 +27,9 @@ jobs: - name: Run PHP Mess Detector on modified files shell: bash run: | - RETVAL=0 - FILELIST=$(mktemp /tmp/phpmd-check.XXXXXX) - mapfile -d ',' -t added_modified_files < <(printf '%s,' '${{ steps.files.outputs.added_modified }}') - for FILE in "${added_modified_files[@]}"; do - EXT="${FILE##*.}" - echo "Changed file: " $FILE ", extension: " $EXT - if [[ "$EXT" == "php" ]]; then - echo "src/${FILE}" >> "${FILELIST}" - echo "File added to the file list: " $FILE - fi + for file in ${{ steps.changed-files.outputs.all_changed_files }}; do + echo "$file was changed" done - if [ -s "${FILELIST}" ]; then - FILES=`cat ${FILELIST} | paste -sd "," -` - echo "Running PHPMD on" $FILES - phpmd $FILES github .github/phpmd-ruleset.xml --exclude 'vendor/*' - RETVAL=$? - else - echo "There are no changes in PHP files (no PHP-MD test performed)" - fi - exit $RETVAL + + + From a057585fd62015389796ec432031626c8199a702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Arroyo?= Date: Mon, 11 Dec 2023 18:28:15 +0100 Subject: [PATCH 05/13] chore: Define PHPMD rules in tao-extension-ci-action instead --- .github/php-md.yaml.deleted | 57 +++++++++++++++++++ ...-ruleset.xml => phpmd-ruleset.xml.deleted} | 0 .github/workflows/continuous-integration.yaml | 2 +- .github/workflows/php-md.yaml | 35 ------------ 4 files changed, 58 insertions(+), 36 deletions(-) create mode 100644 .github/php-md.yaml.deleted rename .github/{phpmd-ruleset.xml => phpmd-ruleset.xml.deleted} (100%) delete mode 100644 .github/workflows/php-md.yaml diff --git a/.github/php-md.yaml.deleted b/.github/php-md.yaml.deleted new file mode 100644 index 000000000..3b196fe52 --- /dev/null +++ b/.github/php-md.yaml.deleted @@ -0,0 +1,57 @@ +name: PHP Mess Detector + +on: push +jobs: + phpmd: + name: PHP Mess Detector + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get changed files + uses: tj-actions/changed-files@v40 + id: changed-files + with: + since_last_remote_commit: false + + - name: Setup PHP environment + uses: shivammathur/setup-php@v2 + with: + coverage: none + tools: phpmd + + - name: Run PHP Mess Detector on modified files + shell: bash + run: | + for file in ${{ steps.changed-files.outputs.all_changed_files }}; do + echo "$file was changed" + done + + FILELIST=$(mktemp /tmp/phpmd-check.XXXXXX) + mapfile -d ',' -t all_files < <(printf '%s,' '${{ steps.changed-files.outputs.all_changed_files }}') + for FILE in ${{ all_files[@] }}; do + EXT="${FILE##*.}" + echo "Changed file: " $FILE ", extension: " $EXT + if [[ "$EXT" == "php" ]]; then + echo "${FILE}" >> "${FILELIST}" + echo "File added to the file list: " $FILE + fi + done + if [ -s "${all_files[@]}" ]; then + FILES=`echo ${{ steps.files.outputs.all }} | paste -sd "," -` + echo "Running PHPMD on" $FILES + phpmd $FILES github .github/phpmd-ruleset.xml --exclude 'vendor/*' + RETVAL=$? + echo "The following files were tested for PSR-12 errors:"; echo + cat -n "$FILELIST" + else + echo "There are no changes in PHP files (no PHP-MD test performed)" + fi + rm "$FILELIST" + exit $RETVAL + + diff --git a/.github/phpmd-ruleset.xml b/.github/phpmd-ruleset.xml.deleted similarity index 100% rename from .github/phpmd-ruleset.xml rename to .github/phpmd-ruleset.xml.deleted diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 7829b6f1f..0c23e4b25 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -21,7 +21,7 @@ jobs: steps: - name: CI - uses: oat-sa/tao-extension-ci-action@v1 + uses: oat-sa/tao-extension-ci-action@experimental/phpmd-ci-checks with: php: ${{ matrix.php-version }} coverage: ${{ matrix.coverage }} diff --git a/.github/workflows/php-md.yaml b/.github/workflows/php-md.yaml deleted file mode 100644 index b940e7b9c..000000000 --- a/.github/workflows/php-md.yaml +++ /dev/null @@ -1,35 +0,0 @@ -name: PHP Mess Detector - -on: push -jobs: - phpmd: - name: PHP Mess Detector - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Get changed files - uses: tj-actions/changed-files@v40 - id: changed-files - with: - since_last_remote_commit: false - - - name: Setup PHP environment - uses: shivammathur/setup-php@v2 - with: - coverage: none - tools: phpmd - - - name: Run PHP Mess Detector on modified files - shell: bash - run: | - for file in ${{ steps.changed-files.outputs.all_changed_files }}; do - echo "$file was changed" - done - - - From 6297a18b3ecc37765d609a41208ed1503ec5509d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Arroyo?= Date: Mon, 11 Dec 2023 18:33:14 +0100 Subject: [PATCH 06/13] chore: Prevent PSR12 erorrs from stopping the PHPMD checks --- controller/HighCC.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller/HighCC.php b/controller/HighCC.php index 70de9915c..1c393f342 100644 --- a/controller/HighCC.php +++ b/controller/HighCC.php @@ -7,7 +7,7 @@ class HighCC { public function example() { - $a =$b=2; + $a = $b = 2; $a1 = $a2 = $b1 = $b2 = $c = $d = 1; $e = $f = $h = $z = 1; From b3fcd22e6b8dfa8d986d956c33e0baa468ae7bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Arroyo?= Date: Mon, 11 Dec 2023 18:35:23 +0100 Subject: [PATCH 07/13] chore: Trigger pipelines From 088d204600147a786345baa80d52515745994b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Arroyo?= Date: Mon, 11 Dec 2023 18:37:42 +0100 Subject: [PATCH 08/13] chore: Trigger pipelines again From e0e8ca23037a25077caffc770468d41e21700a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Arroyo?= Date: Mon, 11 Dec 2023 18:39:37 +0100 Subject: [PATCH 09/13] chore: Let's now lower the cyclomatic complexity --- controller/HighCC.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controller/HighCC.php b/controller/HighCC.php index 1c393f342..a94812bad 100644 --- a/controller/HighCC.php +++ b/controller/HighCC.php @@ -7,7 +7,7 @@ class HighCC { public function example() { - $a = $b = 2; + /*$a = $b = 2; $a1 = $a2 = $b1 = $b2 = $c = $d = 1; $e = $f = $h = $z = 1; @@ -42,6 +42,6 @@ public function example() fiddle(); break; } - } + }*/ } } From c9aa45c1e9992f7a99760c3aa3d39b3096c38c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Arroyo?= Date: Mon, 11 Dec 2023 18:41:21 +0100 Subject: [PATCH 10/13] chore: Let's now make it break again --- controller/HighCC.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controller/HighCC.php b/controller/HighCC.php index a94812bad..20557d558 100644 --- a/controller/HighCC.php +++ b/controller/HighCC.php @@ -7,7 +7,7 @@ class HighCC { public function example() { - /*$a = $b = 2; + $a = $b = $c = 2; $a1 = $a2 = $b1 = $b2 = $c = $d = 1; $e = $f = $h = $z = 1; @@ -42,6 +42,6 @@ public function example() fiddle(); break; } - }*/ + } } } From 4ef9f9a506c4b9cba1d0b01f1a5fdfbf20b0170b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Arroyo?= Date: Mon, 11 Dec 2023 18:44:14 +0100 Subject: [PATCH 11/13] chore: Let's now make no changes and see it still breaking From 232867e49ed0fbe877acb86d2da538e7c403cc1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Arroyo?= Date: Tue, 12 Dec 2023 11:22:29 +0100 Subject: [PATCH 12/13] chore: Check providing the phpmd config in the extension --- phpmd-ruleset.xml | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 phpmd-ruleset.xml diff --git a/phpmd-ruleset.xml b/phpmd-ruleset.xml new file mode 100644 index 000000000..d6757d8c3 --- /dev/null +++ b/phpmd-ruleset.xml @@ -0,0 +1,64 @@ + + + + + + + + + --> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 88906601b604976407afe4cd0488774efbba75de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Arroyo?= Date: Tue, 12 Dec 2023 12:38:36 +0100 Subject: [PATCH 13/13] chore: Tweak rules used by phpmd for this extension --- .github/php-md.yaml.deleted | 57 --------------------- .github/phpmd-ruleset.xml.deleted | 64 ------------------------ controller/HighCC.php | 47 ------------------ phpmd-ruleset.xml | 82 +++++++++++++------------------ 4 files changed, 35 insertions(+), 215 deletions(-) delete mode 100644 .github/php-md.yaml.deleted delete mode 100644 .github/phpmd-ruleset.xml.deleted delete mode 100644 controller/HighCC.php diff --git a/.github/php-md.yaml.deleted b/.github/php-md.yaml.deleted deleted file mode 100644 index 3b196fe52..000000000 --- a/.github/php-md.yaml.deleted +++ /dev/null @@ -1,57 +0,0 @@ -name: PHP Mess Detector - -on: push -jobs: - phpmd: - name: PHP Mess Detector - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Get changed files - uses: tj-actions/changed-files@v40 - id: changed-files - with: - since_last_remote_commit: false - - - name: Setup PHP environment - uses: shivammathur/setup-php@v2 - with: - coverage: none - tools: phpmd - - - name: Run PHP Mess Detector on modified files - shell: bash - run: | - for file in ${{ steps.changed-files.outputs.all_changed_files }}; do - echo "$file was changed" - done - - FILELIST=$(mktemp /tmp/phpmd-check.XXXXXX) - mapfile -d ',' -t all_files < <(printf '%s,' '${{ steps.changed-files.outputs.all_changed_files }}') - for FILE in ${{ all_files[@] }}; do - EXT="${FILE##*.}" - echo "Changed file: " $FILE ", extension: " $EXT - if [[ "$EXT" == "php" ]]; then - echo "${FILE}" >> "${FILELIST}" - echo "File added to the file list: " $FILE - fi - done - if [ -s "${all_files[@]}" ]; then - FILES=`echo ${{ steps.files.outputs.all }} | paste -sd "," -` - echo "Running PHPMD on" $FILES - phpmd $FILES github .github/phpmd-ruleset.xml --exclude 'vendor/*' - RETVAL=$? - echo "The following files were tested for PSR-12 errors:"; echo - cat -n "$FILELIST" - else - echo "There are no changes in PHP files (no PHP-MD test performed)" - fi - rm "$FILELIST" - exit $RETVAL - - diff --git a/.github/phpmd-ruleset.xml.deleted b/.github/phpmd-ruleset.xml.deleted deleted file mode 100644 index a56788b40..000000000 --- a/.github/phpmd-ruleset.xml.deleted +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/controller/HighCC.php b/controller/HighCC.php deleted file mode 100644 index 20557d558..000000000 --- a/controller/HighCC.php +++ /dev/null @@ -1,47 +0,0 @@ - + - - + --> - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - -