Skip to content

Commit

Permalink
feat: PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
leocavalcante committed Dec 22, 2023
1 parent 5dd99aa commit 4fe2d7d
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 5 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ install:
@sudo ln -sf $(shell pwd)/bin/php-cs-fixer /usr/local/bin/php-cs-fixer
@sudo ln -sf $(shell pwd)/bin/phpctl /usr/local/bin/pctl
@sudo ln -sf $(shell pwd)/bin/phpctl /usr/local/bin/phpctl
@sudo ln -sf $(shell pwd)/bin/phpstan /usr/local/bin/phpstan
@sudo ln -sf $(shell pwd)/bin/phpunit /usr/local/bin/phpunit
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ phpctl sh echo 'Hello, World!' # To run arbitrary sh commands inside the contain
| `sh [commands]` | Starts an interactive Shell session or runs `sh` commands. |
| `repl` | Starts a PHP REPL session (powered by [PsySH](https://psysh.org/)). |
| `php-cs-fixer` | Runs PHP-CS-Fixer. |
| `phpstan` | Runs PHPStan. |

### Scaffolders
| Command | Description |
Expand All @@ -69,6 +70,7 @@ phpctl sh echo 'Hello, World!' # To run arbitrary sh commands inside the contain
#### Skeletons
- `phpunit`
- `php-cs-fixer`
- `phpstan`

### Helpers
| Command | Description |
Expand Down
2 changes: 2 additions & 0 deletions bin/phpstan
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sh
phpctl phpstan $@
11 changes: 8 additions & 3 deletions installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ symlink() {
sudo ln -sf "${INSTALL_DIR}/bin/php-cs-fixer" /usr/local/bin/php-cs-fixer
sudo ln -sf "${INSTALL_DIR}/bin/phpctl" /usr/local/bin/pctl
sudo ln -sf "${INSTALL_DIR}/bin/phpctl" /usr/local/bin/phpctl
sudo ln -sf "${INSTALL_DIR}/bin/phpstan" /usr/local/bin/phpstan
sudo ln -sf "${INSTALL_DIR}/bin/phpunit" /usr/local/bin/phpunit
}

Expand All @@ -22,11 +23,15 @@ if [ "$answer" != "${answer#[Yy]}" ]; then
else
echo "\033[0;31mTo use phpclt globally, link the cloned script to your bin directory, like:\033[0m"
echo ""
echo " sudo ln -sf ${INSTALL_DIR}/bin/composer /usr/local/bin/composer"
echo " sudo ln -sf ${INSTALL_DIR}/bin/php /usr/local/bin/php"
echo " sudo ln -sf ${INSTALL_DIR}/bin/php-cs-fixer /usr/local/bin/php-cs-fixer"
echo " sudo ln -sf ${INSTALL_DIR}/bin/phpctl /usr/local/bin/pctl"
echo " sudo ln -sf ${INSTALL_DIR}/bin/composer /usr/local/bin/composer"
echo " sudo ln -sf ${INSTALL_DIR}/bin/phpctl /usr/local/bin/phpctl"
echo " sudo ln -sf ${INSTALL_DIR}/bin/phpctl /usr/local/bin/pctl"
echo ""
echo "\033[0;31mYou can also complement with another useful binaries:\033[0m"
echo ""
echo " sudo ln -sf ${INSTALL_DIR}/bin/phpunit /usr/local/bin/phpunit"
echo " sudo ln -sf ${INSTALL_DIR}/bin/php-cs-fixer /usr/local/bin/php-cs-fixer"
echo " sudo ln -sf ${INSTALL_DIR}/bin/phpstan /usr/local/bin/phpstan"
echo ""
fi
10 changes: 10 additions & 0 deletions skeletons/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
parameters:
level: 9
paths:
- src
reportUnmatchedIgnoredErrors: false
ignoreErrors:
# Magic behaviour with __get, __set, __call and __callStatic is not exactly static analyser-friendly :)
# Fortunately, You can ignore it by the following config.
- '#Static call to instance method Hyperf\\HttpServer\\Router\\Router::[a-zA-Z0-9\\_]+\(\)#'
- '#Static call to instance method Hyperf\\DbConnection\\Db::[a-zA-Z0-9\\_]+\(\)#'
1 change: 1 addition & 0 deletions src/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ help() {
echo -e "\033[0;32m sh [commands] \033[0m Starts an interactive Shell session or runs sh commands"
echo -e "\033[0;32m repl \033[0m Starts a PHP REPL session (powered by PsySH)"
echo -e "\033[0;32m php-cs-fixer \033[0m Runs PHP-CS-Fixer"
echo -e "\033[0;32m phpstan \033[0m Runs PHPStan"
echo -e "\033[0;32m create [framework] [dir] \033[0m Creates a new project using the given framework (or package)"
echo -e "\033[0;32m init [skeleton] \033[0m Initializes a skeleton configuration (phpunit, php-cs-fixer)"
echo -e "\033[0;32m help or man \033[0m Displays this help message"
Expand Down
13 changes: 11 additions & 2 deletions src/php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ server() {
phpunit() {
if [ ! -f vendor/bin/phpunit ]; then
echo "PHPUnit not found. Installing..."
composer require --dev phpunit/phpunit
run -- composer require --dev phpunit/phpunit
fi;

run -- vendor/bin/phpunit ${@}
Expand All @@ -33,8 +33,17 @@ phpunit() {
php-cs-fixer() {
if [ ! -f vendor/bin/php-cs-fixer ]; then
echo "PHP-CS-Fixer not found. Installing..."
composer require --dev friendsofphp/php-cs-fixer
run -- composer require --dev friendsofphp/php-cs-fixer
fi;

run -- vendor/bin/php-cs-fixer ${@}
}

phpstan() {
if [ ! -f vendor/bin/phpstan ]; then
echo "PHPStan not found. Installing..."
run -- composer require --dev phpstan/phpstan
fi;

run -- vendor/bin/phpstan ${@}
}
3 changes: 3 additions & 0 deletions src/scaffold.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ init() {
"php-cs-fixer")
skeleton=".php-cs-fixer.php"
;;
"phpstan")
skeleton="phpstan.neon"
;;
*)
echo -e "\033[0;31mSkeleton ($skeleton_alias) not handled.\033[0m"
exit 1
Expand Down

0 comments on commit 4fe2d7d

Please sign in to comment.