Skip to content
Merged
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
1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

15 changes: 3 additions & 12 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [ "*" ]
branches: ["*"]
pull_request:
branches: [ "*" ]
branches: ["*"]
workflow_dispatch:

permissions:
Expand All @@ -15,26 +15,17 @@ concurrency:
cancel-in-progress: true

jobs:

cs:
uses: altophp/.github/.github/workflows/CS.yml@main
with:
php-version: '8.4'
# composer-validate: true
# php-cs-fixer-args: '--diff --dry-run'

sa:
uses: altophp/.github/.github/workflows/SA.yml@main
with:
php-version: '8.4'
# phpstan-args: 'analyse --no-progress --memory-limit=-1'

tests:
strategy:
fail-fast: false
matrix:
php: ['8.4', '8.5']
php: ["8.4", "8.5"]
uses: altophp/.github/.github/workflows/tests.yml@main
with:
php-version: ${{ matrix.php }}
# phpunit-args: '--colors=never'
32 changes: 0 additions & 32 deletions CONTRIBUTING.md

This file was deleted.

8 changes: 0 additions & 8 deletions SECURITY.md

This file was deleted.

10 changes: 0 additions & 10 deletions SUPPORT.md

This file was deleted.

10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
"ext-mbstring": "*",
"ext-tokenizer": "*"
},
"suggest": {
"ext-simplexml": "Required by the optional TextMate theme adapter"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.94",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^12.5"
},
"suggest": {
"ext-simplexml": "Required by the optional TextMate theme adapter"
},
"autoload": {
"psr-4": {
"Alto\\Code\\Highlight\\": "src/"
Expand All @@ -60,6 +60,7 @@
"sort-packages": true
},
"scripts": {
"coverage": "vendor/bin/phpunit --coverage-text",
"cs": "vendor/bin/php-cs-fixer fix --dry-run --diff --sequential",
"cs:fix": "vendor/bin/php-cs-fixer fix --sequential",
"docs:capture": "npm --prefix tools/docs-showcase run capture",
Expand All @@ -76,7 +77,6 @@
"@test"
],
"sa": "vendor/bin/phpstan analyse --memory-limit=-1",
"test": "phpunit",
"coverage": "vendor/bin/phpunit --coverage-text"
"test": "phpunit"
}
}
3 changes: 1 addition & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
parameters:
level: 10
level: max
paths:
- src
treatPhpDocTypesAsCertain: false
22 changes: 15 additions & 7 deletions src/CodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@ public function __construct(
$this->embeddedRegistry = $embeddedRegistry ?? new EmbeddedLanguageRegistry();

$languages ??= Languages::getDefaultLanguages();
foreach ($languages as $language) {
if (!$language instanceof LanguageInterface) {
throw new \InvalidArgumentException('All languages must implement LanguageInterface.');
}

$this->registerLanguage($language);
}
$this->registerLanguages($languages);
}

/**
Expand Down Expand Up @@ -110,6 +104,20 @@ private function getLanguage(string $identifier): LanguageInterface
return $this->languages[$identifier];
}

/**
* @param array<array-key, mixed> $languages
*/
private function registerLanguages(array $languages): void
{
foreach ($languages as $language) {
if (!$language instanceof LanguageInterface) {
throw new \InvalidArgumentException('All languages must implement LanguageInterface.');
}

$this->registerLanguage($language);
}
}

private function parseWithLanguage(LanguageInterface $language, string $code): ParsedStream
{
if ($language instanceof EmbeddedLanguageCapable) {
Expand Down
2 changes: 1 addition & 1 deletion src/Embedded/EmbeddedTrigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private static function normalizeAttributeConstraints(array $constraints): array
continue;
}

$normalized[$key] = array_values($allowedValues);
$normalized[$key] = $allowedValues;
}

return $normalized;
Expand Down
8 changes: 1 addition & 7 deletions src/Language/CssLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,7 @@ protected function getTextBefore(array $tokens): string
return '';
}

$last = end($tokens);

if (false === $last) {
return '';
}

return $last->getText();
return $tokens[count($tokens) - 1]->getText();
}

protected function isPseudoClass(string $text): bool
Expand Down
5 changes: 1 addition & 4 deletions src/Language/TypeScriptLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,7 @@ private function isRegexContext(array $tokens): bool
return true;
}

$lastToken = end($tokens);
if (false === $lastToken) {
return true;
}
$lastToken = $tokens[count($tokens) - 1];

if (Scope::Whitespace === $lastToken->getScope()) {
for ($i = count($tokens) - 1; $i >= 0; --$i) {
Expand Down