Skip to content

Commit

Permalink
build: min php version is 8.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Gemorroj committed Jul 3, 2023
1 parent 42796b3 commit 715bd33
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 70 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ jobs:
fail-fast: false
matrix:
include:
- operating-system: 'ubuntu-latest'
php-version: '7.4'
job-description: 'Ubuntu; PHP 7.4; latest-deps'

- operating-system: 'ubuntu-latest'
php-version: '7.4'
composer-flags: '--prefer-lowest'
job-description: 'Ubuntu; PHP 7.4; lowest-deps'

- operating-system: 'ubuntu-latest'
php-version: '8.0'
job-description: 'Ubuntu; PHP 8.0; latest-deps'
Expand Down
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'@PHP74Migration' => true,
'@PHP80Migration' => true,

'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ echo $xbbcode->getHtml();
```

### Requirements:
- PHP >= 7.4
- PHP >= 8.0.2


### Installation:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"keywords": ["xbbcode","bbcode"],
"license": "GPL-2.0-or-later",
"require": {
"php": ">=7.4",
"php": ">=8.0.2",
"geshi/geshi": "^1.0.9.1"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^9.6",
"friendsofphp/php-cs-fixer": "^3.0"
},
"authors": [
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace Xbbcode;

class Attributes extends \ArrayObject
class Attributes extends \ArrayObject implements \Stringable
{
/**
* @var array<string, string>
Expand Down
4 changes: 2 additions & 2 deletions src/Tag/TagAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use Xbbcode\Attributes;
use Xbbcode\Xbbcode;

abstract class TagAbstract extends Xbbcode
abstract class TagAbstract extends Xbbcode implements \Stringable
{
/**
* Задаёт возможность наличия у последнего атрибута у тега значений без необходимости наличия кавычек для значений с пробелами.
Expand Down Expand Up @@ -136,7 +136,7 @@ protected function parseUrl(string $url): string
$out = '';
if (isset($parse['scheme'])) {
$out .= $parse['scheme'].'://';
} elseif (0 === \strpos($url, '//')) {
} elseif (\str_starts_with($url, '//')) {
$out .= '//';
}

Expand Down
74 changes: 20 additions & 54 deletions src/Xbbcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Xbbcode
/**
* Список поддерживаемых тегов с указанием специализированных классов.
*
* @var array<string, string>
* @var array<string, class-string<TagAbstract>>
*/
protected array $tags = [
// Основные теги
Expand Down Expand Up @@ -1002,47 +1002,21 @@ protected function getToken(): ?array
break;
}
$char = $this->text[$this->cursor];
switch ($char) {
case '[':
$charType = 0;
break;
case ']':
$charType = 1;
break;
case '"':
$charType = 2;
break;
case "'":
$charType = 3;
break;
case '=':
$charType = 4;
break;
case '/':
$charType = 5;
break;
case ' ':
$charType = 6;
break;
case "\t":
$charType = 6;
break;
case "\n":
$charType = 6;
break;
case "\r":
$charType = 6;
break;
case "\0":
$charType = 6;
break;
case "\x0B":
$charType = 6;
break;
default:
$charType = 7;
break;
}
$charType = match ($char) {
'[' => 0,
']' => 1,
'"' => 2,
"'" => 3,
'=' => 4,
'/' => 5,
' ' => 6,
"\t" => 6,
"\n" => 6,
"\r" => 6,
"\0" => 6,
"\x0B" => 6,
default => 7,
};
if (false === $tokenType) {
$token = $char;
} elseif (5 >= $tokenType) {
Expand All @@ -1062,12 +1036,7 @@ protected function getToken(): ?array
return [$tokenType, $token];
}

/**
* Парсер
*
* @param array|string $code
*/
public function parse($code): void
public function parse(array|string $code): void
{
$time_start = \microtime(true);

Expand Down Expand Up @@ -1850,10 +1819,7 @@ protected function parseTree(): void
$this->setTree($result);
}

/**
* @param bool|array $tree
*/
protected function getSyntax($tree = false): array
protected function getSyntax(bool|array $tree = false): array
{
if (!\is_array($tree)) {
$tree = $this->getTree();
Expand Down Expand Up @@ -2029,7 +1995,7 @@ public function getHtml(array $elems = null): string
$elem['str'] = $this->insertMnemonics($elem['str']);
for ($i = 0; $i < $rbr; ++$i) {
$elem['str'] = \ltrim($elem['str']);
if (0 === \strpos($elem['str'], '<br />')) {
if (\str_starts_with($elem['str'], '<br />')) {
$elem['str'] = \substr_replace($elem['str'], '', 0, 6);
}
}
Expand All @@ -2042,7 +2008,7 @@ public function getHtml(array $elems = null): string
$rbr = $tag::BR_RIGHT;
for ($i = 0; $i < $lbr; ++$i) {
$result = \rtrim($result);
if ('<br />' === \substr($result, -6)) {
if (\str_ends_with($result, '<br />')) {
$result = \substr_replace($result, '', -6, 6);
}
}
Expand Down

0 comments on commit 715bd33

Please sign in to comment.