-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a script that inserts strict type declarations (#7716)
* Add a scripts that adds strict type declarations Checks all php files in a given directory for existing strict type declartions, and if it doesn't find one, adds it. * add strict types on deploy * add missing quotes * Added npm command to trigger strict type additions and passed 'last deployed hash' to get changed themes * fixed bash command and added error catching so errors won't stop deployment * Add condition for debug output --------- Co-authored-by: Jason Crist <jcrist@pbking.com>
- Loading branch information
Showing
3 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
|
||
# Verify an argument is provided | ||
if [ "$#" -ne 1 ]; then | ||
echo "Usage: $0 <directory>" | ||
echo "Error: Directory argument missing." | ||
exit 1 | ||
fi | ||
|
||
# Directory containing PHP files, passed as an argument | ||
DIRECTORY="$1" | ||
|
||
# Loop over each PHP file in the specified directory | ||
find "$DIRECTORY" -type f -name "*.php" | while read -r file; do | ||
[ -n "$DEBUG" ] && echo "Processing file: $file" | ||
# Check if the file contains the strict_types declaration | ||
if ! grep -qE 'declare\s*\(\s*strict_types\s*=\s*1\s*\)\s*;' "$file"; then | ||
[ -n "$DEBUG" ] && echo "Declaration not found in: $file" | ||
# If not, prepend the strict_types declaration | ||
{ | ||
echo '<?php declare( strict_types = 1 ); ?>' | ||
cat "$file" | ||
} > "$file.tmp" && mv "$file.tmp" "$file" | ||
else | ||
[ -n "$DEBUG" ] && echo "Declaration found in: $file" | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters