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
2 changes: 1 addition & 1 deletion tools/.phpstan/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"require-dev": {
"phpstan/phpstan": "^2.3.4",
"phpstan/extension-installer": "^1.4.3",
"phpstan/phpstan-strict-rules": "^2.1.0",
"phpstan/phpstan-strict-rules": "^2.1.1",
"ergebnis/phpstan-rules": "^2.17.0"
},
"config": {
Expand Down
15 changes: 8 additions & 7 deletions tools/.phpstan/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions tools/.phpstan/vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,17 @@
},
{
"name": "phpstan/phpstan-strict-rules",
"version": "2.1.0",
"version_normalized": "2.1.0.0",
"version": "2.1.1",
"version_normalized": "2.1.1.0",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-strict-rules.git",
"reference": "24ec51589f896f048d0d36de373d993b5cf71786"
"reference": "fe4a0afae773eedf178fab17ed9361c0061d2804"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/24ec51589f896f048d0d36de373d993b5cf71786",
"reference": "24ec51589f896f048d0d36de373d993b5cf71786",
"url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/fe4a0afae773eedf178fab17ed9361c0061d2804",
"reference": "fe4a0afae773eedf178fab17ed9361c0061d2804",
"shasum": ""
},
"require": {
Expand All @@ -309,7 +309,8 @@
"phpunit/phpunit": "^9.6",
"shipmonk/name-collision-detector": "^2.1"
},
"time": "2026-10-01T21:30:37+00:00",
"time": "2026-11-02T08:16:15+00:00",
"published-time": "2026-11-02T10:55:07+00:00",
"type": "phpstan-extension",
"extra": {
"phpstan": {
Expand All @@ -334,7 +335,7 @@
],
"support": {
"issues": "https://github.com/phpstan/phpstan-strict-rules/issues",
"source": "https://github.com/phpstan/phpstan-strict-rules/tree/2.1.0"
"source": "https://github.com/phpstan/phpstan-strict-rules/tree/2.1.1"
},
"install-path": "../phpstan/phpstan-strict-rules"
}
Expand Down
10 changes: 5 additions & 5 deletions tools/.phpstan/vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => '__root__',
'pretty_version' => '12.5.x-dev',
'version' => '12.5.9999999.9999999-dev',
'reference' => '52eeb60043ea6058735cb3c34b254daf9390cc36',
'reference' => '37c76a2f7b026814e3a4874b5c7730274c97a3a7',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -13,7 +13,7 @@
'__root__' => array(
'pretty_version' => '12.5.x-dev',
'version' => '12.5.9999999.9999999-dev',
'reference' => '52eeb60043ea6058735cb3c34b254daf9390cc36',
'reference' => '37c76a2f7b026814e3a4874b5c7730274c97a3a7',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down Expand Up @@ -56,9 +56,9 @@
'dev_requirement' => true,
),
'phpstan/phpstan-strict-rules' => array(
'pretty_version' => '2.1.0',
'version' => '2.1.0.0',
'reference' => '24ec51589f896f048d0d36de373d993b5cf71786',
'pretty_version' => '2.1.1',
'version' => '2.1.1.0',
'reference' => 'fe4a0afae773eedf178fab17ed9361c0061d2804',
'type' => 'phpstan-extension',
'install_path' => __DIR__ . '/../phpstan/phpstan-strict-rules',
'aliases' => array(),
Expand Down
41 changes: 41 additions & 0 deletions tools/.phpstan/vendor/phpstan/phpstan-strict-rules/.agents/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
# Prepares an Amp orb: installs PHP, Composer, project dependencies and the coding standard.
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."

step() {
echo "==> $(basename "$PWD"): $*"
SECONDS=0
}

step "PHP"
packages=(php8.2-cli php8.2-curl php8.2-intl php8.2-mbstring php8.2-xml php8.2-zip unzip)
missing=()
for package in "${packages[@]}"; do
dpkg-query -W -f='${Status}' "$package" 2>/dev/null | grep -q 'install ok installed' || missing+=("$package")
done
if ((${#missing[@]})); then
sudo apt-get update -qq
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends "${missing[@]}"
fi
echo " $(php -r 'echo PHP_VERSION;') (${SECONDS}s)"

step "Composer"
if ! command -v composer >/dev/null 2>&1; then
tmp="$(mktemp -d)"
curl -fsSL -o "$tmp/composer.phar" https://getcomposer.org/download/latest-stable/composer.phar
curl -fsSL -o "$tmp/composer.phar.sha256sum" https://getcomposer.org/download/latest-stable/composer.phar.sha256sum
(cd "$tmp" && sed 's/ .*/ composer.phar/' composer.phar.sha256sum | sha256sum -c --quiet)
sudo install -m 0755 "$tmp/composer.phar" /usr/local/bin/composer
rm -rf "$tmp"
fi
echo " $(composer --version --no-ansi 2>/dev/null | head -n1) (${SECONDS}s)"

step "composer update"
# There is no committed lockfile, so resolve like CI does.
composer update --no-interaction --no-progress --quiet
echo " (${SECONDS}s)"

step "make cs-install"
make -s cs-install
echo " (${SECONDS}s)"
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ public function __construct(RuleLevelHelper $ruleLevelHelper)
public function passesAsBoolean(Scope $scope, Expr $expr): bool
{
$type = $scope->getType($expr);
if ($type instanceof MixedType) {
return !$type->isExplicitMixed();
if ($type instanceof ErrorType) {
return true;
}
if ($type instanceof MixedType && $type->isExplicitMixed()) {
return false;
}
$typeToCheck = $this->ruleLevelHelper->findTypeToCheck(
$scope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,39 @@ public function processNode(Node $node, Scope $scope): array
$expressionType = $scope->getNativeType($node->expr);
}
if ($castType->isSuperTypeOf($expressionType)->yes()) {
$addTip = function (RuleErrorBuilder $ruleErrorBuilder) use ($scope, $node, $castType): RuleErrorBuilder {
if (!$this->treatPhpDocTypesAsCertain) {
return $ruleErrorBuilder;
}
$ruleErrorBuilder = RuleErrorBuilder::message(sprintf(
'Casting to %s something that\'s already %s.',
$castType->describe(VerbosityLevel::typeOnly()),
$expressionType->describe(VerbosityLevel::typeOnly()),
))->identifier('cast.useless');

if (!$this->treatPhpDocTypesAsCertainTip) {
return $ruleErrorBuilder;
}
$nativeType = $scope->getNativeType($node->expr);
if ($castType->isSuperTypeOf($nativeType)->yes()) {
$ruleErrorBuilder->fixNode($node, static function (Cast $node) use ($nativeType): Node {
if ($node instanceof Cast\Bool_) {
if (!$nativeType->isBoolean()->yes()) {
return $node;
}
} elseif ($node instanceof Cast\Int_) {
if (
$node->expr instanceof Node\Expr\UnaryMinus
|| !$nativeType->isInteger()->yes()
) {
return $node;
}
} else {
// skip all other casts
return $node;
}

$expressionTypeWithoutPhpDoc = $scope->getNativeType($node->expr);
if ($castType->isSuperTypeOf($expressionTypeWithoutPhpDoc)->yes()) {
return $ruleErrorBuilder;
}
return $node->expr;
});
} elseif ($this->treatPhpDocTypesAsCertain && $this->treatPhpDocTypesAsCertainTip) {
$ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
}

return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
};
return [
$addTip(RuleErrorBuilder::message(sprintf(
'Casting to %s something that\'s already %s.',
$castType->describe(VerbosityLevel::typeOnly()),
$expressionType->describe(VerbosityLevel::typeOnly()),
)))->identifier('cast.useless')->build(),
$ruleErrorBuilder->build(),
];
}

Expand Down
Loading