-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57c7f61
commit d4b3c9a
Showing
7 changed files
with
109 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters