Skip to content

Commit bf74e0c

Browse files
committed
:octocat: phan on CI
1 parent 5790e0f commit bf74e0c

File tree

6 files changed

+80
-5
lines changed

6 files changed

+80
-5
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
- "8.2"
3939
- "8.3"
4040
- "8.4"
41+
- "8.5"
4142

4243
steps:
4344
- name: "Checkout"
@@ -47,21 +48,24 @@ jobs:
4748
uses: shivammathur/setup-php@v2
4849
with:
4950
php-version: ${{ matrix.php-version }}
50-
extensions: ${{ env.PHP_EXTENSIONS }}
51+
extensions: ast, ${{ env.PHP_EXTENSIONS }}
5152
ini-values: ${{ env.PHP_INI_VALUES }}
5253
coverage: none
5354

5455
- name: "Validate composer.json"
55-
run: composer validate --ansi --strict
56+
run: composer validate --no-interaction --ansi --verbose --with-dependencies
5657

5758
- name: "Install dependencies with composer"
5859
uses: ramsey/composer-install@v3
5960

6061
- name: "Run PHPCodeSniffer"
6162
run: php vendor/bin/phpcs
6263

63-
- name: "Run PHPStan"
64-
run: php vendor/bin/phpstan
64+
- name: "Run phan"
65+
run: php vendor/bin/phan --target-php-version=${{ matrix.php-version }}
66+
67+
# - name: "Run PHPStan"
68+
# run: php vendor/bin/phpstan
6569

6670

6771
tests:
@@ -80,6 +84,7 @@ jobs:
8084
- "8.2"
8185
- "8.3"
8286
- "8.4"
87+
- "8.5"
8388

8489
steps:
8590
- name: "Checkout"

.phan/config.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* This configuration will be read and overlaid on top of the
4+
* default configuration. Command-line arguments will be applied
5+
* after this file is read.
6+
*/
7+
return [
8+
// If this is set to `null`,
9+
// then Phan assumes the PHP version which is closest to the minor version
10+
// of the php executable used to execute Phan.
11+
//
12+
// Note that the **only** effect of choosing `'5.6'` is to infer
13+
// that functions removed in php 7.0 exist.
14+
// (See `backward_compatibility_checks` for additional options)
15+
'target_php_version' => null,
16+
'minimum_target_php_version' => '8.1',
17+
18+
// A list of directories that should be parsed for class and
19+
// method information. After excluding the directories
20+
// defined in exclude_analysis_directory_list, the remaining
21+
// files will be statically analyzed for errors.
22+
//
23+
// Thus, both first-party and third-party code being used by
24+
// your application should be included in this list.
25+
'directory_list' => [
26+
# 'benchmark',
27+
'examples',
28+
'src',
29+
'tests',
30+
'vendor',
31+
# '.phan/stubs',
32+
],
33+
34+
// A regex used to match every file name that you want to
35+
// exclude from parsing. Actual value will exclude every
36+
// "test", "tests", "Test" and "Tests" folders found in
37+
// "vendor/" directory.
38+
'exclude_file_regex' => '@^vendor/.*/(tests?|Tests?)/@',
39+
40+
// A directory list that defines files that will be excluded
41+
// from static analysis, but whose class and method
42+
// information should be included.
43+
//
44+
// Generally, you'll want to include the directories for
45+
// third-party code (such as "vendor/") in this list.
46+
//
47+
// n.b.: If you'd like to parse but not analyze 3rd
48+
// party code, directories containing that code
49+
// should be added to both the `directory_list`
50+
// and `exclude_analysis_directory_list` arrays.
51+
'exclude_analysis_directory_list' => [
52+
'vendor/',
53+
'.phan/stubs',
54+
],
55+
'suppress_issue_types' => [
56+
# 'PhanAccessMethodInternal',
57+
# 'PhanDeprecatedClass',
58+
# 'PhanDeprecatedClassConstant',
59+
# 'PhanNoopNew',
60+
# 'PhanTypePossiblyInvalidDimOffset',
61+
],
62+
];

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"ext-sodium": "*"
3737
},
3838
"require-dev": {
39+
"phan/phan": "^6.0.2",
3940
"phpmd/phpmd": "^2.15",
4041
"phpstan/phpstan": "^2.1.42",
4142
"phpstan/phpstan-deprecation-rules": "^2.0",
@@ -56,7 +57,9 @@
5657
}
5758
},
5859
"scripts": {
59-
"phpcs": "@php vendor/bin/phpcs",
60+
"phan": "@php vendor/bin/phan",
61+
"phpcs": "@php vendor/bin/phpcs -v",
62+
"phpmd": "@php vendor/bin/phpmd src text ./phpmd.xml.dist",
6063
"phpstan": "@php vendor/bin/phpstan",
6164
"phpstan-baseline": "@php vendor/bin/phpstan --generate-baseline",
6265
"phpunit": "@php vendor/bin/phpunit"

src/Arr.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public static function random(array $array):mixed{
8080
}
8181

8282
if(PHP_VERSION_ID >= 80200){
83+
/** @phan-suppress-next-line PhanParamTooManyInternal (false positive) */
8384
$key = (new \Random\Randomizer(new \Random\Engine\Secure))->pickArrayKeys($array, 1)[0];
8485
}
8586
else{

src/File.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public static function load(string $file, int $offset = 0, int|null $length = nu
115115
throw new RuntimeException('cannot read the given file'); // @codeCoverageIgnore
116116
}
117117

118+
/** @phan-suppress-next-line PhanTypeMismatchArgumentNullableInternal (false positive) */
118119
$content = file_get_contents(filename: $file, offset: $offset, length: $length);
119120

120121
if($content === false){

tests/StrTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ final class StrTest extends TestCase{
2222

2323
/**
2424
* @return array<string, array{0: array<int, string>, 1: bool, 2: bool}>
25+
* @phan-suppress PhanTypeMismatchReturn
2526
*/
2627
public static function startsWithProvider():array{
2728
return [
@@ -44,6 +45,7 @@ public function startsWith(array $needles, bool $ignoreCase, bool $expected):voi
4445

4546
/**
4647
* @return array<string, array{0: array<int, string>, 1: bool, 2: bool}>
48+
* @phan-suppress PhanTypeMismatchReturn
4749
*/
4850
public static function containsAllProvider():array{
4951
return [
@@ -66,6 +68,7 @@ public function containsAll(array $needles, bool $ignoreCase, bool $expected):vo
6668

6769
/**
6870
* @return array<string, array{0: array<int, string>, 1: bool, 2: bool}>
71+
* @phan-suppress PhanTypeMismatchReturn
6972
*/
7073
public static function containsAnyProvider():array{
7174
return [

0 commit comments

Comments
 (0)