E5DB [Finder] Remove deprecated code by derrabus · Pull Request #42172 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
10BC0 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
5 changes: 5 additions & 0 deletions src/Symfony/Component/Finder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.0
---

* Remove `Comparator::setTarget()` and `Comparator::setOperator()`

5.4.0
-----

Expand Down
53 changes: 6 additions & 47 deletions src/Symfony/Component/Finder/Comparator/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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.
*
Expand All @@ -63,31 +49,13 @@ 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.
*
* @return bool
*/
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;
Expand All @@ -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;
}
}
28 changes: 0 additions & 28 deletions src/Symfony/Component/Finder/Tests/Comparator/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
*/
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Finder/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\\": "" },
Expand Down
0