Skip to content

Commit

Permalink
Backport phan
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeweerd committed Aug 12, 2024
1 parent 892d9cc commit fbfef0b
Show file tree
Hide file tree
Showing 51 changed files with 37,879 additions and 6 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: "CI"

on: [push, pull_request]
jobs:
pre-commit:
if: false
uses: ./.github/workflows/pre-commit.yml
secrets: inherit
with:
gh_event: ${{ github.event_name }}
phan:
uses: ./.github/workflows/phan.yml
secrets: inherit
with:
gh_event: ${{ github.event_name }}
phpstan:
if: false
uses: ./.github/workflows/phpstan.yml
secrets: inherit
needs: [pre-commit, phan]
with:
gh_event: ${{ github.event_name }}
windows-ci:
if: false
needs: [pre-commit, phan]
secrets: inherit
uses: ./.github/workflows/windows-ci.yml
with:
gh_event: ${{ github.event_name }}
gh-travis: # Runs travis script on github runner (not on travis)
if: false
# needs: [pre-commit, phan]
# needs: [windows-ci]
secrets: inherit
uses: ./.github/workflows/gh-travis.yml
with:
gh_event: ${{ github.event_name }}


# Note (not tested, from https://github.com/orgs/community/discussions/38361)
# To cancel jobs if one failes, the following action may help
# - if: "failure()"
# uses: "andymckay/[email protected]"
Empty file added .github/workflows/phan.yaml
Empty file.
34 changes: 28 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ build/yarn-error.log
build/node_modules/
node_modules/

vendor/
tmp/

#yarn
yarn.lock

Expand All @@ -59,11 +62,30 @@ package-lock.json
doc/install.lock
/.asciidoctorconfig.adoc

# Qodana
.idea/vcs.xml
.idea/modules.xml
.idea/workspace.xml
.idea/inspectionProfiles/Project_Default.xml
.idea/jsLinters/jshint.xml
.idea
/composer.json
/composer.lock

# Local script, executed during pre-commit
/local.sh

# Local phpstan configuration
/phpstan.neon
/phpstan-baseline.neon

# Logs
/*.log

# Vim swap files
*.sw?

# Generated by PHPUNIT.BAT
/INI_PHPUNIT

# ignore cache builds
/build/phpstan/phpstan
/build/phpstan/bootstrap_custom.php
phpstan_custom.neon
/.php-cs-fixer.cache
/.php_cs.cache
/.cache
46 changes: 46 additions & 0 deletions dev/tools/phan/PHAN.BAT
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@ECHO OFF
REM Usage (use from root of project):
REM - Standard checks:
REM PHAN.BAT
REM - Extended checks:
REM PHAN.BAT extended
REM - Use fixer configuration:
REM PHAN.BAT fix
REM
REM Standard phan options can be added on the command line.

set MEMOPT=--memory-limit=4G
set CONFIG=--config-file
set CONFIG_FILE=dev/tools/phan/config.php
set FIX=
set USERARGS=
SET TWICE=--analyze-twice

rem Iterate through each argument
for %%i in (%*) do (
if "%%i"=="--memory-limit" (
set MEMOPT=""
)
if "%%i"=="extended" (
set CONFIG="--config-file"
set CONFIG_FILE=dev/tools/phan/config_extended.php
goto :nextloop
)
if "%%i"=="fix" (
set FIX="--automatic-fix"
set CONFIG="--config-file"
set CONFIG_FILE=dev/tools/phan/config_fixer.php
set TWICE=
goto :nextloop
)
if "%%i"=="--config-file" (
set CONFIG=
set CONFIG_FILE=
)
set "USERARGS=%USERARGS% %%i"

:nextloop
REM NEXTLOOP
)

../phan/vendor/bin/phan.bat %TWICE% %MEMOPT% %FIX% %CONFIG% %CONFIG_FILE% %USERARGS%
46 changes: 46 additions & 0 deletions dev/tools/phan/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
### Static Code Checks using [phan]

#### Installation, running

`run-phan.sh` can install and run `phan`.

See instructions in `run-phan.sh` for installing (or just run it).

The configuration file in `PROJECT_DIR/.phan/config.php` also allows you to run
`phan` independently from the script.

#### Run options:

No option : Runs the minimum checks

Option 'full' : Runs all an extensive set of checks

Option '1' : Writes the baseline

Examples:

- `run-phan.sh` runs the default checks
- `run-phan.sh 1` updates the baseline for the default checks
- `run-phan.sh full` runs the extended checks
- `run-phan.sh full 1` updates the baseline for the extended checks

#### Baseline

The `baseline.txt` file in this directory defines the issues that are currently
excluded from the final report. In principle you should not add any more
exceptions to that file, but rather fix the issues or add [phan annotations]
that provide more information or to exclude specific cases.

#### Configuration

`config.php` : Default configuration file

`config_extended.php` : Configuration that enables more checks.

`baseline.txt` : Ignored issues (with `config.php`)

`baseline_extended.txt` : Ignored issues (with `config_extended.php`), not
currently in git

[phan]: https://github.com/phan/phan/wiki/Getting-Started
[phan annotations]: https://github.com/phan/phan/wiki/Annotating-Your-Source-Code
1,828 changes: 1,828 additions & 0 deletions dev/tools/phan/baseline.txt

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions dev/tools/phan/baseline_extended.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* /!\ DO NOT generate this baseline - it should only suppress notices
* that are to be excluded from the technical debt and that can
* not be excluded using other methods.
* The 'internal' PhanUndeclaredConstant is such a case.
*
* When Phan is invoked with --load-baseline=path/to/baseline.php,
* The pre-existing issues listed in this file won't be emitted.
*
* This file can be updated by invoking Phan with --save-baseline=path/to/baseline.php
* (can be combined with --load-baseline)
*/
return [

// Currently, file_suppressions and directory_suppressions are the only supported suppressions
'file_suppressions' => [
'htdocs/accountancy/admin/productaccount.php' => ['PhanTypeMismatchArgumentNullableInternal'], // false positive
'internal' => ['PhanUndeclaredConstant'],
],
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed.
// (directory_suppressions will currently be ignored by subsequent calls to --save-baseline, but may be preserved in future Phan releases)
];
Loading

0 comments on commit fbfef0b

Please sign in to comment.