Skip to content

Commit

Permalink
Merge branch '5.x' into create-form-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zmitic authored Dec 29, 2023
2 parents 0372122 + f23ec34 commit 96c2a22
Show file tree
Hide file tree
Showing 68 changed files with 703 additions and 525 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
45 changes: 11 additions & 34 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,16 @@ jobs:
fail-fast: false
matrix:
php-version:
- 7.3
- 7.4
- 8.0
- 8.1

dependencies:
- highest
- lowest

exclude:
- php-version: 7.3
dependencies: lowest
- php-version: 7.4
dependencies: lowest

steps:
- name: "Checkout"
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: "Install PHP with extensions"
uses: shivammathur/setup-php@v2
Expand All @@ -48,7 +41,7 @@ jobs:
dependency-versions: ${{ matrix.dependencies }}

- name: "Cache cache directory for vimeo/psalm"
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: .build/psalm
key: php-${{ matrix.php-version }}-psalm-${{ github.sha }}
Expand All @@ -71,38 +64,26 @@ jobs:
fail-fast: false
matrix:
php-version:
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0
- 8.1
- 8.2

symfony-version:
- 4
- 5
- 6
- 7

exclude:
- php-version: 7.1
symfony-version: 5
- php-version: 7.1
symfony-version: 6
- php-version: 7.2
symfony-version: 6
- php-version: 7.3
symfony-version: 6
- php-version: 7.4
symfony-version: 6
- php-version: 7.1
symfony-version: 6
- php-version: 8.0
symfony-version: 3
- php-version: 8.0
symfony-version: 6
- php-version: 8.0
symfony-version: 7
- php-version: 8.1
symfony-version: 7

steps:
- name: "Checkout"
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: "Install PHP with extensions"
uses: shivammathur/setup-php@v2
Expand All @@ -125,7 +106,3 @@ jobs:

- name: "Run acceptance tests with codeception"
run: vendor/bin/codecept run -v -g symfony-common -g symfony-${{ matrix.symfony-version }}

- name: "Run acceptance tests with codeception PHP8 only tests"
run: vendor/bin/codecept run -v -g php-8
if: matrix.php-version == '8.0'
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ vendor/bin/psalm --init
vendor/bin/psalm-plugin enable psalm/plugin-symfony
```

### Versions & Dependencies

| Symfony Psalm Plugin | PHP | Symfony | Psalm |
|----------------------|------------|---------|-------|
| 5.x | ^7.4, ^8.0 | 5, 6 | 5 |
| 4.x | ^7.4, ^8.0 | 4, 5, 6 | 4 |
| 3.x | ^7.1, ^8.0 | 4, 5, 6 | 4 |
| 2.x | ^7.1, ^8.0 | 4, 5 | 4 |
| 1.x | ^7.1 | 3, 4, 5 | 3 |

### Features

- Detects the `ContainerInterface::get()` result type. Works better if you [configure](#configuration) a compiled container XML file.
Expand Down Expand Up @@ -59,7 +69,7 @@ This file path may change based on your Symfony version, file structure and envi
Default files are:
- Symfony 3: `var/cache/dev/srcDevDebugProjectContainer.xml`
- Symfony 4: `var/cache/dev/srcApp_KernelDevDebugContainer.xml`
- Symfony 5: `var/cache/dev/App_KernelDevDebugContainer.xml`
- Symfony 5+: `var/cache/dev/App_KernelDevDebugContainer.xml`

Multiple container files can be configured. In this case, the first valid file is taken into account.
If none of the given files is valid, a configuration exception is thrown.
Expand All @@ -80,6 +90,14 @@ If you're using PHP config files for Symfony 5.3+, you also need this for auto-l
</extraFiles>
```

If you're using Symfony's `env()` or `param()` functions in your PHP config files, you also need this for auto-loading them:

```xml
<stubs>
<file name="vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php" />
</stubs>
```

If you're getting the following error

> MissingFile - config/preload.php - Cannot find file ...var/cache/prod/App_KernelProdContainer.preload.php to include
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@
}
],
"require": {
"php": "^7.1 || ^8.0",
"php": "^7.4 || ^8.0",
"ext-simplexml": "*",
"symfony/framework-bundle": "^4.0 || ^5.0 || ^6.0",
"vimeo/psalm": "^4.12"
"symfony/framework-bundle": "^5.0 || ^6.0 || ^7.0",
"vimeo/psalm": "^5.1"
},
"require-dev": {
"symfony/form": "^4.0 || ^5.0 || ^6.0",
"doctrine/annotations": "^1.8",
"doctrine/orm": "^2.7",
"symfony/form": "^5.0 || ^6.0 || ^7.0",
"doctrine/annotations": "^1.8|^2",
"doctrine/orm": "^2.9",
"phpunit/phpunit": "~7.5 || ~9.5",
"symfony/cache-contracts": "^1.0 || ^2.0",
"symfony/console": "*",
"symfony/messenger": "^4.2 || ^5.0 || ^6.0",
"symfony/messenger": "^5.0 || ^6.0 || ^7.0",
"symfony/security-guard": "*",
"symfony/serializer": "^4.0 || ^5.0 || ^6.0",
"symfony/serializer": "^5.0 || ^6.0 || ^7.0",
"symfony/validator": "*",
"twig/twig": "^2.10 || ^3.0",
"weirdan/codeception-psalm-module": "^0.13.1"
"weirdan/codeception-psalm-module": "dev-master"
},
"autoload": {
"psr-4": {
Expand Down
19 changes: 7 additions & 12 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.7.3@38c452ae584467e939d55377aaf83b5a26f19dd1">
<files psalm-version="5.13.1@086b94371304750d1c673315321a55d15fc59015">
<file src="src/Plugin.php">
<UnusedPsalmSuppress occurrences="1">
<code>DeprecatedMethod</code>
</UnusedPsalmSuppress>
</file>
<file src="src/Twig/Context.php">
<UnnecessaryVarAnnotation occurrences="2">
<UnnecessaryVarAnnotation>
<code>int</code>
<code>string</code>
</UnnecessaryVarAnnotation>
</file>
<file src="src/Test/CodeceptionModule.php">
<UnusedPsalmSuppress occurrences="1">
<code>NonInvariantDocblockPropertyType</code>
</UnusedPsalmSuppress>
</file>
<file src="src/Symfony/ContainerMeta.php">
<PossiblyNullReference occurrences="1">
<code>attributes</code>
</PossiblyNullReference>
</file>
</files>
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
cacheDirectory=".build/psalm"
errorBaseline="psalm-baseline.xml"
findUnusedCode="true"
findUnusedBaselineEntry="false"
>
<projectFiles>
<directory name="src" />
Expand Down
3 changes: 0 additions & 3 deletions src/Handler/AnnotationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

class AnnotationHandler implements AfterClassLikeVisitInterface
{
/**
* {@inheritdoc}
*/
public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event)
{
$stmt = $event->getStmt();
Expand Down
38 changes: 15 additions & 23 deletions src/Handler/ConsoleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Psalm\Type\Atomic\TInt;
use Psalm\Type\Atomic\TNull;
use Psalm\Type\Atomic\TString;
use Psalm\Type\MutableUnion;
use Psalm\Type\Union;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -31,15 +32,12 @@ class ConsoleHandler implements AfterMethodCallAnalysisInterface
/**
* @var Union[]
*/
private static $arguments = [];
private static array $arguments = [];
/**
* @var Union[]
*/
private static $options = [];
private static array $options = [];

/**
* {@inheritdoc}
*/
public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $event): void
{
$statements_source = $event->getStatementsSource();
Expand Down Expand Up @@ -149,22 +147,19 @@ private static function analyseArgument(array $args, StatementsSource $statement
}

if ($mode & InputArgument::IS_ARRAY) {
$returnTypes = new Union([new TArray([new Union([new TInt()]), new Union([new TString()])])]);
$returnTypes = new MutableUnion([new TArray([new Union([new TInt()]), new Union([new TString()])])]);
} elseif ($mode & InputArgument::REQUIRED) {
$returnTypes = new Union([new TString()]);
$returnTypes = new MutableUnion([new TString()]);
} else {
$returnTypes = new Union([new TString(), new TNull()]);
$returnTypes = new MutableUnion([new TString(), new TNull()]);
}

$defaultParam = $normalizedParams['default'];
if ($defaultParam) {
if ($defaultParam && (!$defaultParam->value instanceof Expr\ConstFetch || 'null' !== $defaultParam->value->name->getFirst())) {
$returnTypes->removeType('null');
if ($defaultParam->value instanceof Expr\ConstFetch && 'null' === $defaultParam->value->name->parts[0]) {
$returnTypes->addType(new TNull());
}
}

self::$arguments[$identifier] = $returnTypes;
self::$arguments[$identifier] = $returnTypes->freeze();
}

/**
Expand Down Expand Up @@ -199,7 +194,7 @@ private static function analyseOption(array $args, StatementsSource $statements_
$mode = InputOption::VALUE_OPTIONAL;
}

$returnTypes = new Union([new TString(), new TNull()]);
$returnTypes = new MutableUnion([new TString(), new TNull()]);

$defaultParam = $normalizedParams['default'];
if ($defaultParam) {
Expand All @@ -208,7 +203,7 @@ private static function analyseOption(array $args, StatementsSource $statements_
}

if ($defaultParam->value instanceof Expr\ConstFetch) {
switch ($defaultParam->value->name->parts[0]) {
switch ($defaultParam->value->name->getFirst()) {
case 'null':
$returnTypes->addType(new TNull());
break;
Expand All @@ -221,18 +216,18 @@ private static function analyseOption(array $args, StatementsSource $statements_
}

if ($mode & InputOption::VALUE_NONE) {
$returnTypes = new Union([new TBool()]);
$returnTypes = new MutableUnion([new TBool()]);
}

if ($mode & InputOption::VALUE_REQUIRED && $mode & InputOption::VALUE_IS_ARRAY) {
$returnTypes->removeType('null');
}

if ($mode & InputOption::VALUE_IS_ARRAY) {
$returnTypes = new Union([new TArray([new Union([new TInt()]), $returnTypes])]);
$returnTypes = new MutableUnion([new TArray([new Union([new TInt()]), $returnTypes->freeze()])]);
}

self::$options[$identifier] = $returnTypes;
self::$options[$identifier] = $returnTypes->freeze();
}

/**
Expand Down Expand Up @@ -264,7 +259,7 @@ private static function normalizeParams(array $params, array $args): array

$key = array_search($name, $params);
Assert::integer($key);
$params = array_slice($params, $key + 1);
unset($params[$key]);
} else {
$name = array_shift($params);
}
Expand All @@ -275,10 +270,7 @@ private static function normalizeParams(array $params, array $args): array
return $result;
}

/**
* @param mixed $mode
*/
private static function getModeValue($mode): ?int
private static function getModeValue(Expr $mode): ?int
{
if ($mode instanceof Expr\BinaryOp\BitwiseOr) {
return self::getModeValue($mode->left) | self::getModeValue($mode->right);
Expand Down
3 changes: 0 additions & 3 deletions src/Handler/ContainerDependencyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

class ContainerDependencyHandler implements AfterFunctionLikeAnalysisInterface
{
/**
* {@inheritdoc}
*/
public static function afterStatementAnalysis(AfterFunctionLikeAnalysisEvent $event): ?bool
{
$stmt = $event->getStmt();
Expand Down
Loading

0 comments on commit 96c2a22

Please sign in to comment.