Skip to content

Commit

Permalink
Fix rector deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Sep 10, 2024
1 parent 57c7f61 commit d4b3c9a
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
php: [ '8.1', '8.2', '8.3', '8.4' ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
stability: [ prefer-lowest, prefer-stable ]
steps:
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
],
"require": {
"php": "^8.1",
"phplrt/position-contracts": "^4.0",
"phplrt/source-contracts": "^4.0",
"phplrt/position-contracts": "^3.7",
"phplrt/source-contracts": "^3.7",
"symfony/deprecation-contracts": "^2.5|^3.0"
},
"autoload": {
Expand All @@ -27,7 +27,7 @@
}
},
"require-dev": {
"phplrt/source": "^4.0",
"phplrt/source": "^3.7",
"phpunit/phpunit": "^10.5|^11.0",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^1.11",
Expand All @@ -39,12 +39,12 @@
}
},
"provide": {
"phplrt/position-contracts-implementation": "^4.0"
"phplrt/position-contracts-implementation": "^3.7"
},
"extra": {
"branch-alias": {
"dev-master": "4.x-dev",
"dev-main": "4.x-dev"
"dev-master": "3.x-dev",
"dev-main": "3.x-dev"
}
},
"config": {
Expand Down
45 changes: 45 additions & 0 deletions src/Interval.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Phplrt\Position;

use Phplrt\Contracts\Position\IntervalInterface;
use Phplrt\Contracts\Position\PositionInterface;

/**
* @deprecated since phplrt 3.4 and will be removed in 4.0.
*/
final class Interval implements IntervalInterface
{
use IntervalFactoryTrait;

private PositionInterface $from;

private PositionInterface $to;

public function __construct(PositionInterface $from, PositionInterface $to)
{
trigger_deprecation('phplrt/position', '3.4', <<<'MSG'
Using "%s::class" is deprecated.
MSG, self::class);

$this->from = $from;
$this->to = $to;
}

public function getFrom(): PositionInterface
{
return $this->from;
}

public function getTo(): PositionInterface
{
return $this->to;
}

public function getLength(): int
{
return \max(0, \abs($this->to->getOffset() - $this->from->getOffset()));
}
}
43 changes: 43 additions & 0 deletions src/IntervalFactoryTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Phplrt\Position;

use Phplrt\Contracts\Position\IntervalInterface;
use Phplrt\Contracts\Source\SourceExceptionInterface;

/**
* @deprecated since phplrt 3.4 and will be removed in 4.0.
*/
trait IntervalFactoryTrait
{
/**
* @param int<0, max> $offset
* @param int<0, max> $length
*
* @throws SourceExceptionInterface
*/
public static function fromOffset($source, int $offset = 0, int $length = 0): IntervalInterface
{
return new Interval(
Position::fromOffset($source, $offset),
Position::fromOffset($source, $offset + $length)
);
}

/**
* @param int<1, max> $line
* @param int<1, max> $column
* @param int<0, max> $length
*
* @throws SourceExceptionInterface
*/
public static function fromPosition($source, int $line = 1, int $column = 1, int $length = 0): IntervalInterface
{
return new Interval(
$from = Position::fromPosition($source, $line, $column),
Position::fromOffset($source, $from->getOffset() + $length)
);
}
}
2 changes: 1 addition & 1 deletion src/PositionFactoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static function start(): PositionInterface
* @throws SourceExceptionInterface in case of an error in creating the
* source object
*/
public static function end(mixed $source): PositionInterface
public static function end($source): PositionInterface
{
$factory = self::getPositionFactory();

Expand Down
12 changes: 12 additions & 0 deletions src/PositionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Phplrt\Position;

use Phplrt\Contracts\Position\PositionInterface as PositionContract;

/**
* @deprecated since phplrt 3.2 and will be removed in 4.0, use {@see PositionContract} instead.
*/
interface PositionInterface extends PositionContract {}
2 changes: 1 addition & 1 deletion tests/Unit/LinesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testOffsetOverflow(string $text, int $lines): void
}

#[DataProvider('provider')]
public function testOffsetUnderflow(string $text): void
public function testOffsetUnderflow(string $text, int $lines): void
{
$position = Position::fromOffset($text, \PHP_INT_MIN);

Expand Down

0 comments on commit d4b3c9a

Please sign in to comment.