@@ -51,10 +51,10 @@ jobs:
5151 composer require --dev wp-coding-standards/wpcs dealerdirect/phpcodesniffer-composer-installer phpcompatibility/php-compatibility --no-interaction
5252 fi
5353
54+
5455 - name : Run PHP Code Beautifier and Fixer
5556 run : |
5657 echo "Running PHP Code Beautifier and Fixer to automatically fix code style issues..."
57-
5858 if [ -f phpcs.xml ] || [ -f phpcs.xml.dist ]; then
5959 # Try to fix code style issues automatically using the project's standards
6060 vendor/bin/phpcbf --standard=phpcs.xml || vendor/bin/phpcbf --standard=phpcs.xml.dist || true
6363 echo "Using custom phpcbf ruleset to fix alignment and common issues"
6464 vendor/bin/phpcbf --standard=phpcbf-custom.xml --extensions=php . || true
6565 fi
66-
6766 # Check if changes were made and output a summary
6867 if git diff --name-only | grep -q "\.php$"; then
6968 echo "PHPCBF fixed issues in the following files:"
@@ -89,16 +88,16 @@ jobs:
8988 run : |
9089 # Install PHP compatibility standards and required packages
9190 composer require --dev phpcompatibility/php-compatibility squizlabs/php_codesniffer wp-coding-standards/wpcs dealerdirect/phpcodesniffer-composer-installer --no-interaction || true
92-
91+
9392 # Set up PHPCompatibility standards properly with absolute paths
9493 ABSOLUTE_PHPCOMP_PATH=$(composer config vendor-dir)/phpcompatibility/php-compatibility
9594 ABSOLUTE_WPCS_PATH=$(composer config vendor-dir)/wp-coding-standards/wpcs
9695 vendor/bin/phpcs --config-set installed_paths ${ABSOLUTE_PHPCOMP_PATH},${ABSOLUTE_WPCS_PATH}
97-
96+
9897 # Verify configured standards
9998 echo "Available coding standards:"
10099 vendor/bin/phpcs -i
101-
100+
102101 # Try to auto-fix compatibility issues where possible
103102 vendor/bin/phpcbf --standard=phpcs.xml --extensions=php --ignore=vendor/,node_modules/ . || true
104103
@@ -120,34 +119,28 @@ jobs:
120119 <exclude-pattern>/node_modules/*</exclude-pattern>
121120</ruleset>
122121EOF
123- vendor/bin/phpcs --config-set installed_paths ${ABSOLUTE_PHPCOMP_PATH},${ABSOLUTE_WPCS_PATH}
124- vendor/bin/phpcs --standard=phpcs-compat.xml --extensions=php --ignore=vendor/,node_modules/ .
125- fi
122+
123+ vendor/bin/phpcs --config-set installed_paths ${ABSOLUTE_PHPCOMP_PATH},${ABSOLUTE_WPCS_PATH}
124+ vendor/bin/phpcs --standard=phpcs-compat.xml --extensions=php --ignore=vendor/,node_modules/ .
125+ fi
126126
127127 - name : Fix text argument escaping issues
128128 run : |
129129 echo "Checking for text argument escaping issues..."
130-
131130 # Find PHP files with potential escaping issues (echo with variables not wrapped in esc_html)
132131 FILES_WITH_ESCAPING_ISSUES=$(grep -r --include="*.php" -l 'echo ".*\$' --exclude-dir={vendor,node_modules,tests} . || echo "")
133-
134132 if [ -n "$FILES_WITH_ESCAPING_ISSUES" ]; then
135133 echo "Found potential escaping issues in the following files:"
136134 echo "$FILES_WITH_ESCAPING_ISSUES"
137-
138135 # Find problematic patterns and fix them
139136 for FILE in $FILES_WITH_ESCAPING_ISSUES; do
140137 echo "Checking $FILE for escaping issues..."
141-
142138 # Replace direct echo of strings with variables to use esc_html
143139 sed -i 's/echo "\(.*\)\$\([a-zA-Z0-9_]*\)\(.*\)";/if (function_exists('\''esc_html'\'')) { echo esc_html("\1$\2\3"); } else { echo "\1$\2\3"; }/g' "$FILE" || true
144-
145140 # Also fix single quoted strings
146141 sed -i 's/echo '\''\(.*\)\$\([a-zA-Z0-9_]*\)\(.*\)'\'';/if (function_exists('\''esc_html'\'')) { echo esc_html('\''\1$\2\3'\''); } else { echo '\''\1$\2\3'\''; }/g' "$FILE" || true
147-
148142 # Fix multi-line echo statements
149143 sed -i 's/echo \("\|\x27\)\(.*\)\$\([a-zA-Z0-9_]*\)\(.*\)\("\|\x27\) \. \("\|\x27\)\(.*\)\("\|\x27\);/if (function_exists('\''esc_html'\'')) { echo esc_html(\1\2$\3\4\5 . \6\7\8); } else { echo \1\2$\3\4\5 . \6\7\8; }/g' "$FILE" || true
150-
151144 echo "Applied escaping fixes to $FILE"
152145 done
153146 else
0 commit comments