Skip to content

Commit

Permalink
(Added) Add Phan Static Analysis Tool (#24)
Browse files Browse the repository at this point in the history
* Add new extensions and phan tests to composer.json

The changes made to the composer.json file include the addition of new extensions for development purposes. Furthermore, a new test command for Phan, a static analysis tool, is added for identifying code issues or bugs. This enhances our project's code quality control measures.

* Update Dockerfiles to simplify dependencies

The Dockerfiles for the PHP versions 8.1, 8.2 and 8.3 have been updated to simplify the system dependencies. In addition, the installation of 'pdo', 'pdo_mysql', 'git', and 'libzip-dev' has been removed, 'zip' is now the only library installed through apt-get, and the 'pcntl' PHP extension has been added. These changes should make the Docker build process faster and less prone to errors caused by unnecessary dependencies.

* Update dev dependencies in localTest.sh

The dev dependencies in localTest.sh have been updated from phpstan/phpstan and phpstan/phpstan-phpunit to phan/phan. This change ensures that the development environment uses the most recent and suitable package for code analysis.

* Update PHP extensions and enable Phan analysis in workflow

The GitHub Actions workflow for PHP has been updated to include pcntl and xdebug extensions, replacing ast, mbstring, pdo, pdo_mysql, xml, and zip. Furthermore, previously commented Phan static analysis step has been uncommented, enabling it in the testing workflow. This will improve the PHP testing environment and code quality checks.

* Update PHP extensions in Qodana code quality workflow

The PHP extensions used in the .github/workflows/qodana_code_quality.yml file have been modified. The new set of extensions includes ast, pcntl, xdebug, and xhprof replacing the previous extensions - ast, mbstring, pdo, pdo_mysql, xml, xhprof, zip.

* Add Phan config file

A `config.php` file for Phan, the PHP static analyzer, has been added. This configuration file includes settings such as target PHP version, plugins to run, and directories to include in the analysis. This will help improve and ensure the quality of the codebase.

* Update target PHP version in Phan config

Changed the target PHP version from '8.2' to '8.1' in the Phan configuration file. This adjustment ensures the tool runs under the appropriate PHP version, improving overall analysis. Remember to align this setting with the PHP versions your project supports, or consider running Phan for each supported version.

* Enable dead_code_detection in Phan config

This commit enables the `dead_code_detection` setting in Phan config. This change will help in identifying unused or redundant code bits, thereby improving the cleanliness and maintainability of the codebase. It's important to remember to scrutinize the potential false positives resulting from this setting.

* Refactor Dockerfile RUN instructions

The apt-get update and apt-get install commands have been combined into a single RUN instruction in all Dockerfiles. This modification helps to avoid potential caching issues. Further image size reduction could be achieved by also removing the apt cache within the same RUN instruction.

* Disable dead code detection in Phan config

Due to an assertion error encountered when running dead code detection on more than one core, the setting has been deactivated. This change resolves the issue by setting `'dead_code_detection'` to `false` in the Phan config file. This change will prevent similar errors from occurring when running Phan on multiple cores.

* Refactor Dockerfiles for readability and maintainability

This revision groups related pecl install and docker-php-ext-enable commands in all Dockerfiles. This restructuring improves the organization of the Dockerfiles, easing the task of future addition or removal of extensions.
  • Loading branch information
MarjovanLier authored Mar 5, 2024
1 parent 46c549e commit 2abb2e8
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 42 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: ast, mbstring, pdo, pdo_mysql, xml, xhprof, zip
extensions: ast, pcntl, xdebug, xhprof

# This step caches the Composer packages for faster execution.
- name: Cache Composer packages
Expand Down Expand Up @@ -110,13 +110,13 @@ jobs:
id: phpstan
if: steps.infection.outcome == 'success'
run: composer test:phpstan
#
# # This step runs static analysis with Phan.
# - name: Run static analysis with phan
# id: phan
# if: steps.phpstan.outcome == 'success'
# run: composer test:phan
#

# This step runs static analysis with Phan.
- name: Run static analysis with phan
id: phan
if: steps.phpstan.outcome == 'success'
run: composer test:phan

# # This step runs static analysis with Psalm.
# - name: Run static analysis with psalm
# id: psalm
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/qodana_code_quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: "8.1"
extensions: ast, mbstring, pdo, pdo_mysql, xml, xhprof, zip
extensions: ast, pcntl, xdebug, xhprof
coverage: xdebug

- name: Cache Composer Dependencies
Expand Down
366 changes: 366 additions & 0 deletions .phan/config.php

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@
"symfony/console": "^v5|^v6|^v7"
},
"require-dev": {
"ext-ast": "*",
"ext-pcntl": "*",
"ext-xdebug": "*",
"enlightn/security-checker": "^v1|^v2",
"infection/infection": ">=0.27.10",
"laravel/pint": "^1.14",
"phan/phan": ">=5.4.3",
"php-parallel-lint/php-console-highlighter": "^1",
"php-parallel-lint/php-parallel-lint": "^1",
"phpmd/phpmd": "^2",
Expand All @@ -69,11 +73,13 @@
"@test:code-style",
"@test:phpmd",
"@test:infection",
"@test:phpstan"
"@test:phpstan",
"@test:phan"
],
"test:code-style": "pint --test",
"test:infection": "infection --min-msi=100 --min-covered-msi=100 --threads=4 --show-mutations --only-covered --formatter=progress",
"test:lint": "parallel-lint --exclude vendor --show-deprecated .",
"test:phan": "phan --analyze-twice --no-progress-bar",
"test:phpmd": "phpmd src,tests text phpmd.xml",
"test:phpstan": "php -d memory_limit=-1 ./vendor/bin/phpstan analyse --no-progress --no-interaction",
"test:phpunit": "phpunit --no-coverage --no-logging",
Expand All @@ -83,6 +89,7 @@
"test:code-style": "Check code for stylistic consistency.",
"test:infection": "Conduct mutation testing for robustness.",
"test:lint": "Search for syntax errors and problematic patterns.",
"test:phan": "Perform static analysis with Phan to identify code issues.",
"test:phpmd": "Detect bugs and suboptimal code with PHP Mess Detector.",
"test:phpstan": "Conduct PHPStan static analysis for identifying code quality issues.",
"test:phpunit": "Execute PHPUnit tests to verify code functionality.",
Expand Down
14 changes: 4 additions & 10 deletions docker/Dockerfile81
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
FROM php:8.1-cli

# Install system dependencies
RUN set -eux; apt-get update && apt-get install -y \
git \
zip \
libzip-dev \
&& pecl install ast \
&& pecl install xdebug \
&& pecl install xhprof \
&& docker-php-ext-install pdo pdo_mysql \
&& docker-php-ext-enable ast pdo pdo_mysql xdebug xhprof \
&& docker-php-ext-install zip \
RUN set -eux; apt-get update && apt-get install -y zip \
&& pecl install ast xdebug xhprof \
&& docker-php-ext-install pcntl \
&& docker-php-ext-enable ast xdebug xhprof \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /tmp/pear ~/.pearrc

Expand Down
14 changes: 4 additions & 10 deletions docker/Dockerfile82
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
FROM php:8.2-cli

# Install system dependencies
RUN set -eux; apt-get update && apt-get install -y \
git \
zip \
libzip-dev \
&& pecl install ast \
&& pecl install xdebug \
&& pecl install xhprof \
&& docker-php-ext-install pdo pdo_mysql \
&& docker-php-ext-enable ast pdo pdo_mysql xdebug xhprof \
&& docker-php-ext-install zip \
RUN set -eux; apt-get update && apt-get install -y zip \
&& pecl install ast xdebug xhprof \
&& docker-php-ext-install pcntl \
&& docker-php-ext-enable ast xdebug xhprof \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /tmp/pear ~/.pearrc

Expand Down
14 changes: 4 additions & 10 deletions docker/Dockerfile83
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
FROM php:8.3-cli

# Install system dependencies
RUN set -eux; apt-get update && apt-get install -y \
git \
zip \
libzip-dev \
&& pecl install ast \
&& pecl install xdebug \
&& pecl install xhprof \
&& docker-php-ext-install pdo pdo_mysql \
&& docker-php-ext-enable ast pdo pdo_mysql xdebug xhprof \
&& docker-php-ext-install zip \
RUN set -eux; apt-get update && apt-get install -y zip \
&& pecl install ast xdebug xhprof \
&& docker-php-ext-install pcntl \
&& docker-php-ext-enable ast xdebug xhprof \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /tmp/pear ~/.pearrc

Expand Down
3 changes: 1 addition & 2 deletions localTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ for version in {81..83}; do
rm -f composer.lock && \
$DOCKER_CMD composer install && \
$DOCKER_CMD composer update --with-all-dependencies && \
$DOCKER_CMD composer require --dev --with-all-dependencies "phpstan/phpstan":"^1.10" && \
$DOCKER_CMD composer require --dev --with-all-dependencies "phpstan/phpstan-phpunit":"^1.3"
$DOCKER_CMD composer require --dev --with-all-dependencies "phan/phan":">=5.4.3"

# Check for errors immediately after Composer commands
if [ $? -ne 0 ]; then
Expand Down

0 comments on commit 2abb2e8

Please sign in to comment.