Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ on:

jobs:
tests:
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.0, 8.1, 8.2, 8.3]
php: ["8.0", "8.1", "8.2", "8.3", "8.4"]
dependency-versions: [lowest, highest]

name: Tests - P${{ matrix.php }} - ${{ matrix.dependency-versions }} - ${{ matrix.os }}
name: Tests - PHP ${{ matrix.php }} - ${{ matrix.dependency-versions }}

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -41,10 +40,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.0, 8.1, 8.2, 8.3]
php: ["8.0", "8.1", "8.2", "8.3", "8.4"]
dependency-versions: [lowest, highest]

name: Static Analysis - P${{ matrix.php }} - ${{ matrix.dependency-versions }}
name: Static Analysis - PHP ${{ matrix.php }} - ${{ matrix.dependency-versions }}

steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 1 addition & 5 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<?php declare(strict_types=1);

use function MLL\PhpCsFixerConfig\risky;

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->name('*.php')
->notPath('vendor')
->notPath('tests/Enums/Annotate') // Generated
->notPath('tests/Enums/AnnotateFixtures') // Matches laminas/laminas-code
->notPath('tests/Enums/ToNative') // Generated
->notPath('tests/Enums/ToNativeFixtures') // Matches laminas/laminas-code
->ignoreDotFiles(false)
->ignoreVCS(true);

return risky($finder);
return MLL\PhpCsFixerConfig\risky($finder);
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## 6.12.0

### Added

- Support Laravel 11
- Support Rector 2

## 6.11.1

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ it: fix stan test docs ## Run the commonly used targets

.PHONY: help
help: ## Displays this list of targets with descriptions
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}'
@grep --extended-regexp '^[a-zA-Z0-9_-]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: fix
fix: vendor ## Apply automatic code fixes
Expand Down
30 changes: 15 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@
"require": {
"php": "^8",
"composer/class-map-generator": "^1",
"illuminate/contracts": "^9 || ^10 || ^11",
"illuminate/support": "^9 || ^10 || ^11",
"illuminate/contracts": "^9 || ^10 || ^11 || ^12",
"illuminate/support": "^9 || ^10 || ^11 || ^12",
"laminas/laminas-code": "^3.4 || ^4",
"nikic/php-parser": "^4.13.2 || ^5"
},
"require-dev": {
"doctrine/dbal": "^3.4",
"ergebnis/composer-normalize": "^2.28.3",
"larastan/larastan": "^2.6.3",
"mll-lab/php-cs-fixer-config": "^5.4",
"mockery/mockery": "^1.5",
"orchestra/testbench": "^7.6.1 || ^8 || ^9",
"phpstan/extension-installer": "^1",
"phpstan/phpstan": "^1.8.2",
"phpstan/phpstan-mockery": "^1.1",
"phpstan/phpstan-phpunit": "^1.1.1",
"phpunit/phpunit": "^9.5.21 || ^10 || ^11",
"rector/rector": "^1",
"symplify/rule-doc-generator": "^11 || ^12 || ^13"
"doctrine/dbal": "^3.9.4",
"ergebnis/composer-normalize": "^2.45",
"larastan/larastan": "^2.9.14 || ^3.1",
"mll-lab/php-cs-fixer-config": "^5.10",
"mockery/mockery": "^1.6.12",
"orchestra/testbench": "^7.6.1 || ^8.33 || ^9.11 || ^10",
"phpstan/extension-installer": "^1.4.3",
"phpstan/phpstan": "^1.12.19 || ^2.1.6",
"phpstan/phpstan-mockery": "^1.1.3 || ^2",
"phpstan/phpstan-phpunit": "^1.4.2 || ^2.0.4",
"phpunit/phpunit": "^9.5.21 || ^10.5.45 || ^11.5.10 || ^12.0.5",
"rector/rector": "^1.2.10 || ^2.0.9",
"symplify/rule-doc-generator": "^11.2 || ^12.2.5"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ parameters:
checkOctaneCompatibility: true
reportUnmatchedIgnoredErrors: false # As long as we support multiple Laravel versions at once, there will be some dead spots
treatPhpDocTypesAsCertain: false
noEnvCallsOutsideOfConfig: false
ignoreErrors:
- '#Unsafe usage of new static.*#' # This is a library, so it should be extendable
# The Process API is only available in newer Laravel versions
Expand All @@ -16,7 +17,6 @@ parameters:
- '#invalid type Illuminate\\Process#'
- '#^Attribute class PHPUnit\\Framework\\Attributes\\DataProvider does not exist\.$#' # Only available with newer PHPUnit versions
excludePaths:
- tests/Enums/ToNativeFixtures # Fails with PHP < 8.1
- tests/PHPStan/Fixtures
# Install https://plugins.jetbrains.com/plugin/7677-awesome-console to make those links clickable
editorUrl: '%%relFile%%:%%line%%'
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/EnumAnnotateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function annotateFolder(): void
}
}

/** @param \ReflectionClass<\BenSampo\Enum\Enum<mixed>> $reflectionClass */
/** @param \ReflectionClass<*> $reflectionClass */
protected function annotate(\ReflectionClass $reflectionClass): void
{
$docBlock = $this->getDocBlock($reflectionClass);
Expand Down Expand Up @@ -111,7 +111,7 @@ protected function annotate(\ReflectionClass $reflectionClass): void
$this->info("Wrote new phpDocBlock to {$fileName}.");
}

/** @param \ReflectionClass<\BenSampo\Enum\Enum<mixed>> $reflectionClass */
/** @param \ReflectionClass<*> $reflectionClass */
protected function getDocBlock(\ReflectionClass $reflectionClass): DocBlockGenerator
{
$docBlock = DocBlockGenerator::fromArray([])
Expand Down Expand Up @@ -145,7 +145,7 @@ protected function getDocblockWithoutTags(DocBlockReflection $docBlockReflection
}

/**
* @param \ReflectionClass<\BenSampo\Enum\Enum<mixed>> $reflectionClass
* @param \ReflectionClass<*> $reflectionClass
*
* @return array<\Laminas\Code\Generator\DocBlock\Tag\TagInterface>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static function fromValue(mixed $enumValue): static
return $enumValue;
}

return new static($enumValue);
return new static($enumValue); // @phpstan-ignore return.type (generic variance)
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/PHPStan/UniqueValuesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ public function processNode(Node $node, Scope $scope): array
foreach ($constants as $name => $value) {
$constantsWithValue = array_filter($constants, fn (mixed $v): bool => $v === $value);
if (count($constantsWithValue) > 1) {
$duplicateConstants[] = array_keys($constantsWithValue);
$duplicateConstants[] = json_encode(array_keys($constantsWithValue));
}
}
$duplicateConstants = array_unique($duplicateConstants);

if (count($duplicateConstants) > 0) {
$fqcn = $reflection->getName();
$constantsString = json_encode($duplicateConstants);
$constantsString = implode(',', $duplicateConstants);

return [
RuleErrorBuilder::message("Enum class {$fqcn} contains constants with duplicate values: {$constantsString}.")
->identifier('enum.duplicateValues')
->build(),
];
}
Expand Down
4 changes: 4 additions & 0 deletions src/Rector/ToNativeUsagesRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
use PhpParser\Node\Stmt\Switch_;
use PhpParser\Node\VariadicPlaceholder;
use PHPStan\Type\ObjectType;
use PHPStan\Node\Expr\AlwaysRememberedExpr;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -664,6 +665,9 @@ protected function refactorKey(PropertyFetch $fetch): ?Node
protected function refactorMatch(Match_ $match): ?Node
{
$cond = $match->cond;
while ($cond instanceof AlwaysRememberedExpr) { // @phpstan-ignore phpstanApi.class (backwards compatibility not guaranteed)
$cond = $cond->getExpr(); // @phpstan-ignore phpstanApi.method (backwards compatibility not guaranteed)
}
if (($cond instanceof PropertyFetch || $cond instanceof NullsafePropertyFetch)
&& $this->inConfiguredClasses($cond->var)
) {
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/UniqueValuesRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testRule(): void
],
[
[
'Enum class BenSampo\Enum\Tests\PHPStan\Fixtures\DuplicateValue contains constants with duplicate values: [["A","B"]].',
'Enum class BenSampo\Enum\Tests\PHPStan\Fixtures\DuplicateValue contains constants with duplicate values: ["A","B"].',
13,
],
],
Expand Down
Loading