Skip to content

Instantly share code, notes, and snippets.

@YukiYamashina
Last active July 8, 2022 02:24
Show Gist options
  • Save YukiYamashina/646df7279b48d5a87e8a862b6f78bcd1 to your computer and use it in GitHub Desktop.
Save YukiYamashina/646df7279b48d5a87e8a862b6f78bcd1 to your computer and use it in GitHub Desktop.
Laravel のプロジェクトディレクトリで実行することで Faker のチートシートを作成する.
#!/bin/sh
### ###
### Create a Faker Cheat Sheet. ###
### ###
function extract_methods() {
while read line; do
if [[ $line =~ ^\*[[:space:]]@example[[:space:]](.*) ]]; then
example=${BASH_REMATCH[1]}
fi
if [[ $line =~ ^\*[[:space:]]@return[[:space:]](.*) ]]; then
type=${BASH_REMATCH[1]}
fi
if [[ $line =~ ^\*[[:space:]](Return.*|Generate.*) ]]; then
description=${BASH_REMATCH[1]}
fi
if [[ $line =~ ^public.*function[[:space:]](.*) ]]; then
method=${BASH_REMATCH[1]}
if [[ $method != *"__construct"* ]]; then
echo "| \`$method\` | \`$type\` | \`$example\` | $description |" >> $markdown
fi
example=''
type=''
method=''
description=''
fi
done < $1
}
markdown="faker_cheat_sheet.md"
echo "# Faker Cheat Sheet" > $markdown
for entry in vendor/fakerphp/faker/src/Faker/Provider/*.php; do
filename=$(basename "$entry" .php)
echo "Reading $filename..."
echo "" >> $markdown
echo "" >> $markdown
echo "## Provider/$filename.php" >> $markdown
echo "" >> $markdown
echo "| Method | Type | Example | Description |" >> $markdown
echo "|:--|:--|:--|:--|" >> $markdown
extract_methods $entry
done
for entry in vendor/fakerphp/faker/src/Faker/Provider/ja_JP/*.php; do
filename=$(basename "$entry" .php)
echo "Reading $filename..."
echo "" >> $markdown
echo "" >> $markdown
echo "## Provider/ja_JP/$filename.php" >> $markdown
echo "" >> $markdown
echo "| Method | Type | Example | Description |" >> $markdown
echo "|:--|:--|:--|:--|" >> $markdown
extract_methods $entry
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment