diff --git a/src/Symfony/Component/Finder/CHANGELOG.md b/src/Symfony/Component/Finder/CHANGELOG.md index 0532e1a8da264..5c63312156df1 100644 --- a/src/Symfony/Component/Finder/CHANGELOG.md +++ b/src/Symfony/Component/Finder/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +6.0 +--- + + * Remove `Comparator::setTarget()` and `Comparator::setOperator()` + 5.4.0 ----- diff --git a/src/Symfony/Component/Finder/Comparator/Comparator.php b/src/Symfony/Component/Finder/Comparator/Comparator.php index 996c7a4e703ad..d292bb40894e8 100644 --- a/src/Symfony/Component/Finder/Comparator/Comparator.php +++ b/src/Symfony/Component/Finder/Comparator/Comparator.php @@ -16,17 +16,17 @@ */ class Comparator { - private ?string $target; - private string $operator = '=='; + private string $target; + private string $operator; - public function __construct(string $target = null, string $operator = '==') + public function __construct(string $target, string $operator = '==') { - if (null === $target) { - trigger_deprecation('symfony/finder', '5.4', 'Constructing a "%s" without setting "$target" is deprecated.', __CLASS__); + if (!\in_array($operator, ['>', '<', '>=', '<=', '==', '!='])) { + throw new \InvalidArgumentException(sprintf('Invalid operator "%s".', $operator)); } $this->target = $target; - $this->doSetOperator($operator); + $this->operator = $operator; } /** @@ -36,23 +36,9 @@ public function __construct(string $target = null, string $operator = '==') */ public function getTarget() { - if (null === $this->target) { - trigger_deprecation('symfony/finder', '5.4', 'Calling "%s" without initializing the target is deprecated.', __METHOD__); - } - return $this->target; } - /** - * @deprecated set the target via the constructor instead - */ - public function setTarget(string $target) - { - trigger_deprecation('symfony/finder', '5.4', '"%s" is deprecated. Set the target via the constructor instead.', __METHOD__); - - $this->target = $target; - } - /** * Gets the comparison operator. * @@ -63,20 +49,6 @@ public function getOperator() return $this->operator; } - /** - * Sets the comparison operator. - * - * @throws \InvalidArgumentException - * - * @deprecated set the operator via the constructor instead - */ - public function setOperator(string $operator) - { - trigger_deprecation('symfony/finder', '5.4', '"%s" is deprecated. Set the operator via the constructor instead.', __METHOD__); - - $this->doSetOperator('' === $operator ? '==' : $operator); - } - /** * Tests against the target. * @@ -84,10 +56,6 @@ public function setOperator(string $operator) */ public function test(mixed $test) { - if (null === $this->target) { - trigger_deprecation('symfony/finder', '5.4', 'Calling "%s" without initializing the target is deprecated.', __METHOD__); - } - switch ($this->operator) { case '>': return $test > $this->target; @@ -103,13 +71,4 @@ public function test(mixed $test) return $test == $this->target; } - - private function doSetOperator(string $operator): void - { - if (!\in_array($operator, ['>', '<', '>=', '<=', '==', '!='])) { - throw new \InvalidArgumentException(sprintf('Invalid operator "%s".', $operator)); - } - - $this->operator = $operator; - } } diff --git a/src/Symfony/Component/Finder/Tests/Comparator/ComparatorTest.php b/src/Symfony/Component/Finder/Tests/Comparator/ComparatorTest.php index a04cc62f34585..a42d07fcb025c 100644 --- a/src/Symfony/Component/Finder/Tests/Comparator/ComparatorTest.php +++ b/src/Symfony/Component/Finder/Tests/Comparator/ComparatorTest.php @@ -12,25 +12,10 @@ namespace Symfony\Component\Finder\Tests\Comparator; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Finder\Comparator\Comparator; class ComparatorTest extends TestCase { - use ExpectDeprecationTrait; - - /** - * @group legacy - */ - public function testGetSetOperator() - { - $comparator = new Comparator('some target'); - - $this->expectDeprecation('Since symfony/finder 5.4: "Symfony\Component\Finder\Comparator\Comparator::setOperator" is deprecated. Set the operator via the constructor instead.'); - $comparator->setOperator('>'); - $this->assertEquals('>', $comparator->getOperator(), '->getOperator() returns the current operator'); - } - public function testInvalidOperator() { $this->expectException(\InvalidArgumentException::class); @@ -39,19 +24,6 @@ public function testInvalidOperator() new Comparator('some target', 'foo'); } - /** - * @group legacy - */ - public function testGetSetTarget() - { - $this->expectDeprecation('Since symfony/finder 5.4: Constructing a "Symfony\Component\Finder\Comparator\Comparator" without setting "$target" is deprecated.'); - $comparator = new Comparator(); - - $this->expectDeprecation('Since symfony/finder 5.4: "Symfony\Component\Finder\Comparator\Comparator::setTarget" is deprecated. Set the target via the constructor instead.'); - $comparator->setTarget(8); - $this->assertEquals(8, $comparator->getTarget(), '->getTarget() returns the target'); - } - /** * @dataProvider provideMatches */ diff --git a/src/Symfony/Component/Finder/composer.json b/src/Symfony/Component/Finder/composer.json index 203a498da914d..2e4b324544517 100644 --- a/src/Symfony/Component/Finder/composer.json +++ b/src/Symfony/Component/Finder/composer.json @@ -16,8 +16,7 @@ } ], "require": { - "php": ">=8.0.2", - "symfony/deprecation-contracts": "^2.1|^3" + "php": ">=8.0.2" }, "autoload": { "psr-4": { "Symfony\\Component\\Finder\\": "" },