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 src/Analyser/ExprHandler/NewHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ private function getConstructorThrowPoint(MethodReflection $constructorReflectio
}
} elseif ($this->implicitThrows) {
if (!$context->isInThrow() || !$constructorReflection->getDeclaringClass()->is(Throwable::class)) {
return InternalThrowPoint::createImplicit($scope, $methodCall);
return InternalThrowPoint::createImplicit($scope, $new);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Turbo/TurboExtensionEnabler.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
final class TurboExtensionEnabler
{

public const EXPECTED_EXTENSION_VERSION = '6351afb';
public const EXPECTED_EXTENSION_VERSION = '12acf37';

private static bool $active = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public function testParameterReadOnlyInCatchOfOverridingThrows(): void
$this->analyse([__DIR__ . '/data/unused-method-parameters-overriding-throws.php'], []);
}

public function testParameterReadOnlyInCatchOfImplicitConstructorThrows(): void
{
$this->analyse([__DIR__ . '/data/unused-method-parameters-implicit-constructor-throws.php'], []);
}

public function testParameterCapturedByReference(): void
{
$this->analyse([__DIR__ . '/data/unused-method-parameters-by-ref-use.php'], [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php // lint >= 8.0

namespace UnusedMethodParametersImplicitConstructorThrows;

class Foo
{

public function __construct(string $value)
{
if ($value === '') {
throw new \InvalidArgumentException('Empty value');
}
}

}

class Bar
{

private function readOnlyInCatch(string $value, string $param): ?Foo
{
try {
return new Foo($value);
} catch (\Throwable $e) {
echo $param;
return null;
}
}

private function readOnlyInCatchOfException(string $value, string $param): ?Foo
{
try {
return new Foo($value);
} catch (\Exception $e) {
echo $param;
return null;
}
}

public function doBar(): void
{
$this->readOnlyInCatch('x', 'y');
$this->readOnlyInCatchOfException('x', 'y');
}

}
2 changes: 1 addition & 1 deletion turbo-ext/src/NewHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ class NewHandler
implicit = !isThrowable;
}
if (implicit) {
return pt_internal_throw_point_create_implicit(scope, methodCall.raw());
return pt_internal_throw_point_create_implicit(scope, new_);
}
}

Expand Down
Loading