Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.1-8.3 code hardening + PHP 8.4 version bump #167

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"require": {
"php": "^8.3"
"php": "^8.4"
},
"require-dev": {
"phpunit/phpunit": "^10.0",
Expand Down
3 changes: 2 additions & 1 deletion src/CommonMark/CodeBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
use Tempest\Highlight\Highlighter;
use Tempest\Highlight\WebTheme;

final class CodeBlockRenderer implements NodeRendererInterface
final readonly class CodeBlockRenderer implements NodeRendererInterface
{
public function __construct(
private Highlighter $highlighter = new Highlighter(),
) {
}

#[\Override]
public function render(Node $node, ChildNodeRendererInterface $childRenderer)
{
if (! $node instanceof FencedCode) {
Expand Down
3 changes: 2 additions & 1 deletion src/CommonMark/HighlightExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
use League\CommonMark\Extension\ExtensionInterface;
use Tempest\Highlight\Highlighter;

final class HighlightExtension implements ExtensionInterface
final readonly class HighlightExtension implements ExtensionInterface
{
public function __construct(
private ?Highlighter $highlighter = new Highlighter(),
) {
}

#[\Override]
public function register(EnvironmentBuilderInterface $environment): void
{
$environment
Expand Down
3 changes: 2 additions & 1 deletion src/CommonMark/InlineCodeBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
use League\CommonMark\Renderer\NodeRendererInterface;
use Tempest\Highlight\Highlighter;

final class InlineCodeBlockRenderer implements NodeRendererInterface
final readonly class InlineCodeBlockRenderer implements NodeRendererInterface
{
public function __construct(
private Highlighter $highlighter = new Highlighter(),
) {
}

#[\Override]
public function render(Node $node, ChildNodeRendererInterface $childRenderer)
{
if (! $node instanceof Code) {
Expand Down
2 changes: 1 addition & 1 deletion src/IsInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjectio
{
$pattern = $this->getPattern();

if (! str_starts_with($pattern, '/')) {
if (! str_starts_with((string) $pattern, '/')) {
$pattern = "/{$pattern}/";
}

Expand Down
2 changes: 1 addition & 1 deletion src/IsPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function match(string $content): array
{
$pattern = $this->getPattern();

if (! str_starts_with($pattern, '/')) {
if (! str_starts_with((string) $pattern, '/')) {
$pattern = "/$pattern/";
}

Expand Down
3 changes: 3 additions & 0 deletions src/Languages/Base/BaseLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@

abstract class BaseLanguage implements Language
{
#[\Override]
public function getAliases(): array
{
return [];
}

#[\Override]
public function getInjections(): array
{
return [
Expand All @@ -36,6 +38,7 @@ public function getInjections(): array
];
}

#[\Override]
public function getPatterns(): array
{
return [
Expand Down
1 change: 1 addition & 0 deletions src/Languages/Base/Injections/AdditionInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#[After]
final readonly class AdditionInjection implements Injection
{
#[\Override]
public function parse(string $content, Highlighter $highlighter): ParsedInjection
{
// Standardize line endings
Expand Down
1 change: 1 addition & 0 deletions src/Languages/Base/Injections/CustomClassInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

final readonly class CustomClassInjection implements Injection
{
#[\Override]
public function parse(string $content, Highlighter $highlighter): ParsedInjection
{
$pattern = '/(?<start>{\:(?<class>[\w-]+)\:)(?<match>(.|\n)*?)(?<end>:})/';
Expand Down
1 change: 1 addition & 0 deletions src/Languages/Base/Injections/DeletionInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#[After]
final readonly class DeletionInjection implements Injection
{
#[\Override]
public function parse(string $content, Highlighter $highlighter): ParsedInjection
{
// Standardize line endings
Expand Down
3 changes: 2 additions & 1 deletion src/Languages/Base/Injections/GutterInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class GutterInjection implements Injection
private array $icons = [];
private array $classes = [];

public function __construct(private int $startAt = 1)
public function __construct(private readonly int $startAt = 1)
{
}

Expand All @@ -33,6 +33,7 @@ public function addClass(int $line, string $class): self
return $this;
}

#[\Override]
public function parse(string $content, Highlighter $highlighter): ParsedInjection
{
$lines = preg_split('/\R/u', trim($content, "\n"));
Expand Down
2 changes: 2 additions & 0 deletions src/Languages/Base/Patterns/AdditionEndTokenPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
{
use IsPattern;

#[\Override]
public function getPattern(): string
{
return '/(?<match>\+})/';
}

#[\Override]
public function getTokenType(): TokenType
{
return new IgnoreTokenType();
Expand Down
2 changes: 2 additions & 0 deletions src/Languages/Base/Patterns/AdditionStartTokenPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
{
use IsPattern;

#[\Override]
public function getPattern(): string
{
return '/(?<match>{\+)/';
}

#[\Override]
public function getTokenType(): TokenType
{
return new IgnoreTokenType();
Expand Down
2 changes: 2 additions & 0 deletions src/Languages/Base/Patterns/DeletionEndTokenPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
{
use IsPattern;

#[\Override]
public function getPattern(): string
{
return '/(?<!-)(?<match>\-})/';
}

#[\Override]
public function getTokenType(): TokenType
{
return new IgnoreTokenType();
Expand Down
2 changes: 2 additions & 0 deletions src/Languages/Base/Patterns/DeletionStartTokenPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
{
use IsPattern;

#[\Override]
public function getPattern(): string
{
return '/(?<match>{\-)(?!-)/';
}

#[\Override]
public function getTokenType(): TokenType
{
return new IgnoreTokenType();
Expand Down
2 changes: 2 additions & 0 deletions src/Languages/Base/Patterns/InjectionTokenPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
{
use IsPattern;

#[\Override]
public function getPattern(): string
{
return Escape::INJECTION_TOKEN . '(?<match>(.|\n)*?)' . Escape::INJECTION_TOKEN;
}

#[\Override]
public function getTokenType(): TokenTypeEnum
{
return TokenTypeEnum::INJECTION;
Expand Down
3 changes: 3 additions & 0 deletions src/Languages/Blade/BladeLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

class BladeLanguage extends HtmlLanguage
{
#[\Override]
public function getName(): string
{
return 'blade';
}

#[\Override]
public function getInjections(): array
{
return [
Expand All @@ -32,6 +34,7 @@ public function getInjections(): array
];
}

#[\Override]
public function getPatterns(): array
{
return [
Expand Down
2 changes: 2 additions & 0 deletions src/Languages/Blade/Injections/BladeEchoInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
{
use IsInjection;

#[\Override]
public function getPattern(): string
{
return '({{(?!--))(?<match>.*)(}})';
}

#[\Override]
public function parseContent(string $content, Highlighter $highlighter): string
{
return $highlighter->parse($content, 'php');
Expand Down
2 changes: 2 additions & 0 deletions src/Languages/Blade/Injections/BladeKeywordInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
{
use IsInjection;

#[\Override]
public function getPattern(): string
{
return '(\@[\w]+)\s?\((?<match>.*)\)';
}

#[\Override]
public function parseContent(string $content, Highlighter $highlighter): string
{
return $highlighter->parse($content, 'php');
Expand Down
2 changes: 2 additions & 0 deletions src/Languages/Blade/Injections/BladePhpInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
{
use IsInjection;

#[\Override]
public function getPattern(): string
{
return '\@php(?<match>(.|\n)*?)\@endphp';
}

#[\Override]
public function parseContent(string $content, Highlighter $highlighter): string
{
return $highlighter->parse($content, 'php');
Expand Down
2 changes: 2 additions & 0 deletions src/Languages/Blade/Injections/BladeRawEchoInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
{
use IsInjection;

#[\Override]
public function getPattern(): string
{
return '({!!)(?<match>.*)(!!})';
}

#[\Override]
public function parseContent(string $content, Highlighter $highlighter): string
{
return $highlighter->parse($content, 'php');
Expand Down
2 changes: 2 additions & 0 deletions src/Languages/Blade/Patterns/BladeCommentPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
{
use IsPattern;

#[\Override]
public function getPattern(): string
{
return '(?<match>\{\{\-\-(.|\n)*?\-\-\}\})';
}

#[\Override]
public function getTokenType(): TokenTypeEnum
{
return TokenTypeEnum::COMMENT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
{
use IsPattern;

#[\Override]
public function getPattern(): string
{
return '<\/(?<match>[\w\-\:\.]+)';
}

#[\Override]
public function getTokenType(): TokenTypeEnum
{
return TokenTypeEnum::KEYWORD;
Expand Down
2 changes: 2 additions & 0 deletions src/Languages/Blade/Patterns/BladeComponentOpenTagPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
{
use IsPattern;

#[\Override]
public function getPattern(): string
{
return '<(?<match>[\w\-\:\.]+)';
}

#[\Override]
public function getTokenType(): TokenTypeEnum
{
return TokenTypeEnum::KEYWORD;
Expand Down
2 changes: 2 additions & 0 deletions src/Languages/Blade/Patterns/BladeKeywordPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
{
use IsPattern;

#[\Override]
public function getPattern(): string
{
return '(?<match>\@[\w]+)\b';
}

#[\Override]
public function getTokenType(): TokenTypeEnum
{
return TokenTypeEnum::KEYWORD;
Expand Down
3 changes: 3 additions & 0 deletions src/Languages/Css/CssLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@

class CssLanguage extends BaseLanguage
{
#[\Override]
public function getName(): string
{
return 'css';
}

#[\Override]
public function getInjections(): array
{
return [
...parent::getInjections(),
];
}

#[\Override]
public function getPatterns(): array
{
return [
Expand Down
2 changes: 2 additions & 0 deletions src/Languages/Css/Patterns/CssAttributePattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
{
use IsPattern;

#[\Override]
public function getPattern(): string
{
return '(?<match>[\w\-]+):';
}

#[\Override]
public function getTokenType(): TokenTypeEnum
{
return TokenTypeEnum::PROPERTY;
Expand Down
2 changes: 2 additions & 0 deletions src/Languages/Css/Patterns/CssCommentPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
{
use IsPattern;

#[\Override]
public function getPattern(): string
{
return '/(?<match>\/\*(.|\n)*?\*\/)/m';
}

#[\Override]
public function getTokenType(): TokenTypeEnum
{
return TokenTypeEnum::COMMENT;
Expand Down
Loading
Loading