From 4fe2d7dbd73dfdc7738f20110957eba19b4108d4 Mon Sep 17 00:00:00 2001 From: leocavalcante Date: Fri, 22 Dec 2023 16:07:57 -0300 Subject: [PATCH] feat: PHPStan --- Makefile | 1 + README.md | 2 ++ bin/phpstan | 2 ++ installer.sh | 11 ++++++++--- skeletons/phpstan.neon | 10 ++++++++++ src/help.sh | 1 + src/php.sh | 13 +++++++++++-- src/scaffold.sh | 3 +++ 8 files changed, 38 insertions(+), 5 deletions(-) create mode 100755 bin/phpstan create mode 100644 skeletons/phpstan.neon diff --git a/Makefile b/Makefile index 926efc4..8b26ba4 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index be085f4..b7017c1 100644 --- a/README.md +++ b/README.md @@ -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 | @@ -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 | diff --git a/bin/phpstan b/bin/phpstan new file mode 100755 index 0000000..3076cb9 --- /dev/null +++ b/bin/phpstan @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +phpctl phpstan $@ diff --git a/installer.sh b/installer.sh index f8e77bd..2c6b9b7 100755 --- a/installer.sh +++ b/installer.sh @@ -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 } @@ -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 diff --git a/skeletons/phpstan.neon b/skeletons/phpstan.neon new file mode 100644 index 0000000..b8c857c --- /dev/null +++ b/skeletons/phpstan.neon @@ -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\\_]+\(\)#' diff --git a/src/help.sh b/src/help.sh index a3133f4..e46ec4b 100644 --- a/src/help.sh +++ b/src/help.sh @@ -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" diff --git a/src/php.sh b/src/php.sh index fbebe97..36015e3 100644 --- a/src/php.sh +++ b/src/php.sh @@ -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 ${@} @@ -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 ${@} +} \ No newline at end of file diff --git a/src/scaffold.sh b/src/scaffold.sh index 5c8955f..cea5ebf 100644 --- a/src/scaffold.sh +++ b/src/scaffold.sh @@ -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