Skip to content

Commit

Permalink
PHP 8.2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
bigwhoop committed Jul 21, 2023
1 parent f12ad11 commit 32a8010
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
operating-system: [ ubuntu-latest ]
php-versions: [ '7.4', '8.0', '8.1' ]
php-versions: [ '7.4', '8.0', '8.1', '8.2' ]
composer-deps: [ 'lowest', 'latest' ]
name: PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }} with ${{ matrix.composer-deps }} deps
steps:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": "^7.4 || ~8.0.0 || ~8.1.0",
"php": "^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0",
"ext-simplexml": "*"
},
"require-dev": {
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
parameters:
phpVersion: 70400 # PHP 7.4
level: 9
paths:
- src
Expand Down
18 changes: 10 additions & 8 deletions src/GeneratorOffsetIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,36 @@

namespace Bigwhoop\SentenceBreaker;

use Generator;
use Iterator;

/**
* @template T
*
* @implements Iterator<T>
*/
class GeneratorOffsetIterator implements Iterator
class GeneratorOffsetIterator implements \Iterator
{
/**
* @var Generator<int, T, mixed, void>
*/
private Generator $generator;
/** @var \Generator<int, T, mixed, void> */
private \Generator $generator;

/** @var array<T> */
private array $cache = [];

private int $currentIndex = 0;

/**
* @param Generator<int, T, mixed, void> $generator
* @param \Generator<int, T, mixed, void> $generator
*/
public function __construct(iterable $generator)
public function __construct(\Generator $generator)
{
$this->generator = $generator;
$this->addCurrentToCache();
}

/**
* @return T
*/
#[\ReturnTypeWillChange]
public function current()
{
return $this->cache[$this->currentIndex];
Expand Down
3 changes: 0 additions & 3 deletions src/Lexing/States/TextState.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

class TextState extends State
{
/**
* {@inheritdoc}
*/
protected function call(Lexer $lexer): ?State
{
while (true) {
Expand Down
3 changes: 0 additions & 3 deletions src/Lexing/States/WhitespaceState.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ class WhitespaceState extends State
{
public const CHARS = [' ', "\t", "\r", "\n"];

/**
* {@inheritdoc}
*/
protected function call(Lexer $lexer): ?State
{
while (in_array($lexer->peek(), self::CHARS, true)) {
Expand Down
3 changes: 0 additions & 3 deletions src/Lexing/States/WordState.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ private function getNonWordChars(): array
return array_merge(['.', '?', '!', null], WhitespaceState::CHARS);
}

/**
* {@inheritdoc}
*/
protected function call(Lexer $lexer): ?State
{
$nonWordChars = $this->getNonWordChars();
Expand Down
3 changes: 0 additions & 3 deletions src/Lexing/Tokens/PeriodToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ public function getName(): string
return 'T_PERIOD';
}

/**
* {@inheritdoc}
*/
public function getPrintableValue(): string
{
return '.';
Expand Down
5 changes: 2 additions & 3 deletions src/ProbabilityCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Bigwhoop\SentenceBreaker\Lexing\Tokens\Token;
use Bigwhoop\SentenceBreaker\Rules\ConfigurationException;
use Bigwhoop\SentenceBreaker\Rules\Rules;
use Generator;

class ProbabilityCalculator
{
Expand Down Expand Up @@ -47,11 +46,11 @@ public function addRules(Rules $rules): void
/**
* @param iterable<Token> $tokens
*
* @return Generator<TokenProbability>
* @return \Generator<TokenProbability>
*
* @throws ConfigurationException
*/
public function calculate(iterable $tokens): Generator
public function calculate(iterable $tokens): \Generator
{
$tokenGenerator = function () use ($tokens) {
foreach ($tokens as $token) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/IniConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function loadFile(string $path): self
}

/**
@throws ConfigurationException
* @throws ConfigurationException
*/
public function __construct(string $data)
{
Expand Down
1 change: 0 additions & 1 deletion src/Rules/RulePattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public function getTokensOffsetRelativeToStartToken(string $startTokenName): arr
range(0, count($this->tokens) - 1)
);

/* @phpstan-ignore-next-line */
return array_combine($offsets, $this->tokens);
}
}
4 changes: 1 addition & 3 deletions src/Rules/XMLConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

namespace Bigwhoop\SentenceBreaker\Rules;

use SimpleXMLElement;

class XMLConfiguration implements Configuration
{
private SimpleXMLElement $data;
private \SimpleXMLElement $data;

/**
* @throws ConfigurationException
Expand Down
7 changes: 3 additions & 4 deletions src/SentenceBreaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Bigwhoop\SentenceBreaker\Rules\ConfigurationException;
use Bigwhoop\SentenceBreaker\Rules\IniConfiguration;
use Bigwhoop\SentenceBreaker\Rules\Rules;
use Generator;

class SentenceBreaker
{
Expand All @@ -29,7 +28,7 @@ class SentenceBreaker
/**
* @throws ConfigurationException
*/
public function __construct(?Configuration $rulesConfig = null)
public function __construct(Configuration $rulesConfig = null)
{
$rules = $rulesConfig ? $rulesConfig->getRules() : $this->loadDefaultRules();

Expand Down Expand Up @@ -88,12 +87,12 @@ public function addAbbreviations($values): void
}

/**
* @return Generator<string>
* @return \Generator<string>
*
* @throws ConfigurationException
* @throws Lexing\States\StateException
*/
public function split(string $text): Generator
public function split(string $text): \Generator
{
$this->probabilityCalculator->setAbbreviations($this->getAbbreviations());

Expand Down
6 changes: 2 additions & 4 deletions src/SentenceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

namespace Bigwhoop\SentenceBreaker;

use Generator;

class SentenceBuilder
{
/**
* @param iterable<TokenProbability> $tokenProbabilities
*
* @return Generator<string>
* @return \Generator<string>
*/
public function build(iterable $tokenProbabilities, int $threshold = 50): Generator
public function build(iterable $tokenProbabilities, int $threshold = 50): \Generator
{
$currentSentence = '';

Expand Down

0 comments on commit 32a8010

Please sign in to comment.