Skip to content

Commit

Permalink
Support PHP>8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hason committed Dec 26, 2024
1 parent b2eef00 commit 0979bbb
Show file tree
Hide file tree
Showing 28 changed files with 171 additions and 136 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ jobs:
strategy:
matrix:
deps_strategy: [ '', '--prefer-lowest' ]
php: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
php: [ '8.1', '8.2', '8.3', '8.4' ]
symfony: [ ^3.0, ^4.0, ^5.0, ^6.0, ^7.0 ]
exclude:
- php: '7.4'
symfony: ^6.0
- php: '7.4'
symfony: ^7.0
- php: '8.0'
symfony: ^7.0
- php: '8.1'
symfony: ^7.0
steps:
Expand All @@ -31,14 +25,15 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: pcov
tools: composer:v2

- name: Install dependencies
run: composer update ${{ matrix.deps_strategy }} --with symfony/yaml:${{ matrix.symfony }}

- name: Code style
run: vendor/bin/php-cs-fixer fix --ansi --allow-risky=yes --dry-run
env:
PHP_CS_FIXER_IGNORE_ENV: 1

- name: Code quality
run: vendor/bin/phpstan analyse --no-progress --ansi
4 changes: 2 additions & 2 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
php-version: 8.4
coverage: xdebug
tools: composer:v2

Expand All @@ -32,7 +32,7 @@ jobs:
run: vendor/bin/phpunit --coverage-clover=coverage.xml

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
uses: SonarSource/sonarqube-scan-action@4.2.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
deps_strategy: [ '', '--prefer-lowest' ]
php: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
php: [ '8.1', '8.2', '8.3', '8.4' ]
steps:
- name: Update code
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.phpunit.result.cache
.runner
composer.lock
coverage/
phpstan.neon
phpunit.xml
psalm.xml
Expand Down
3 changes: 3 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@

return (new PhpCsFixer\Config())
->setRules([
'@PhpCsFixer' => true,
'@PSR12:risky' => true,
'@PHP84Migration' => true,
'header_comment' => [
'header' => $header,
],
'php_unit_attributes' => true,
])
->setLineEnding("\n")
->setUsingCache(false)
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGELOG
=========

2.1.0 (2024-12-xx)
------------------

* PHP 8.4 support
* Drop PHP 7 support

2.0.0 (2024-02-22)
------------------

Expand Down
4 changes: 3 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
services:
php:
image: "minidocks/php:${PHP_VERSION:-8.3}"
image: "minidocks/php:${PHP_VERSION:-8.4}"
volumes:
- .:$PWD
- ~/.composer/cache:/composer-cache
- ~/.composer/auth.json:/composer/auth.json
environment:
PATH_SUFFIX: './vendor/bin'
PHP_EXT_XDEBUG: 1
PHP_XDEBUG__MODE: coverage
working_dir: $PWD
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.1",
"symfony/yaml": "^3.4.31 || ^4.3.4 || ^5.0 || ^6.0 || ^7.0"
},
"require-dev": {
"ext-json": "*",
"friendsofphp/php-cs-fixer": "^3.41",
"friendsofphp/php-cs-fixer": "^3.65",
"league/commonmark": "^2.0",
"mthaml/mthaml": "^1.3",
"nette/neon": "^2.2 || ^3.0",
"phpunit/phpunit": "^9.6",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.5",
"phpstan/phpstan": "^2.0",
"twig/twig": "^3.0",
"yosymfony/toml": "^1.0"
},
Expand Down
6 changes: 4 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
parameters:
level: 8
level: 10
paths:
- src
- tests
checkMissingIterableValueType: false
ignoreErrors:
-
identifier: missingType.iterableValue
15 changes: 13 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
<coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true">
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>

<coverage includeUncoveredFiles="true" pathCoverage="true">
</coverage>

<testsuites>
Expand Down
8 changes: 6 additions & 2 deletions run
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ task_composer__normalize()( composer normalize "$@" )

# Run tests
# @service php
task_tests()( phpunit --colors=always "$@" )
task_tests()( XDEBUG_MODE=coverage phpunit --colors=always --coverage-html coverage "$@" )

# Fix code style
# @service php
task_cs()( php-cs-fixer fix --ansi --allow-risky=yes "$@" )
task_cs()( PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --ansi --allow-risky=yes "$@" )

# Analyse code
# @service php
Expand All @@ -44,3 +44,7 @@ task_clean()( _docker_compose down --remove-orphans "$@" )
# Run shell with tools
# @service php
task_tools()( sh "$@" )

task_act__tests__latest()(
act -j phpunit --matrix php:8.4 --matrix deps_strategy:
)
12 changes: 6 additions & 6 deletions src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class Document
private $data;

/**
* @param string $content
* @param array<string, mixed> $data
*/
public function __construct(string $content = '', array $data = [])
Expand All @@ -30,6 +29,11 @@ public function __construct(string $content = '', array $data = [])
$this->data = $data;
}

public function __toString(): string
{
return $this->content;
}

public function getContent(): string
{
return $this->content;
Expand Down Expand Up @@ -57,6 +61,7 @@ public function setContent(string $content): self

/**
* @param array<string, mixed> $data
*
* @return $this
*/
public function setData(array $data): self
Expand All @@ -65,9 +70,4 @@ public function setData(array $data): self

return $this;
}

public function __toString(): string
{
return $this->content;
}
}
36 changes: 14 additions & 22 deletions src/FrontMatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ final class FrontMatter implements FrontMatterInterface
private ProcessorInterface $processor;
private string $regexp;

public function __construct(?ProcessorInterface $processor = null, string $startSep = '---', string $endSep = '---')
{
$this->startSep = $startSep;
$this->endSep = $endSep;
$this->processor = $processor ?: new YamlProcessor();
$this->regexp = $this->getRegExp($startSep, $endSep);
}

public static function createYaml(): self
{
return new self(new YamlProcessor(), '---', '---');
Expand All @@ -39,20 +47,9 @@ public static function createJson(): self
return new self(new JsonWithoutBracesProcessor(), '{', '}');
}

public function __construct(?ProcessorInterface $processor = null, string $startSep = '---', string $endSep = '---')
{
$this->startSep = $startSep;
$this->endSep = $endSep;
$this->processor = $processor ?: new YamlProcessor();
$this->regexp = $this->getRegExp($startSep, $endSep);
}

/**
* {@inheritdoc}
*/
public function parse(string $source): Document
{
if (preg_match($this->regexp, $source, $matches) !== 1) {
if (1 !== preg_match($this->regexp, $source, $matches)) {
return new Document($source);
}

Expand All @@ -64,9 +61,6 @@ public function parse(string $source): Document
return new Document($matches[2], $data);
}

/**
* {@inheritdoc}
*/
public function dump(Document $document): string
{
$data = trim($this->processor->dump($document->getData()));
Expand All @@ -77,12 +71,9 @@ public function dump(Document $document): string
return sprintf("%s\n%s\n%s\n%s", $this->startSep, $data, $this->endSep, $document->getContent());
}

/**
* {@inheritdoc}
*/
public function exists(string $source): bool
{
return preg_match($this->regexp, $source) === 1;
return 1 === preg_match($this->regexp, $source);
}

private function cancelIndentation(string $string): string
Expand All @@ -93,16 +84,17 @@ private function cancelIndentation(string $string): string
return trim($string);
}

return trim((string) preg_replace("/^$indent/m", '', $string));
return trim((string) preg_replace("/^{$indent}/m", '', $string));
}

private function revealIndention(string $string): string
{
$separator = "\r\n";
$line = strtok($string, $separator);
while ($line !== false) {
if (trim($line) !== '') {
while (false !== $line) {
if ('' !== trim($line)) {
preg_match('/^(\s+)/', $line, $match);

return $match[1] ?? '';
}
$line = strtok($separator);
Expand Down
5 changes: 2 additions & 3 deletions src/FrontMatterChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

namespace Webuni\FrontMatter;

use InvalidArgumentException;
use Webuni\FrontMatter\Pug\PugCommentFrontMatter;
use Webuni\FrontMatter\Twig\TwigCommentFrontMatter;

Expand All @@ -25,14 +24,14 @@ public function __construct(iterable $adapters)
{
foreach ($adapters as $adapter) {
if (!$adapter instanceof FrontMatterInterface) {
throw new InvalidArgumentException('Adapter should be instance of '.FrontMatterInterface::class);
throw new \InvalidArgumentException('Adapter should be instance of '.FrontMatterInterface::class);
}

$this->adapters[] = $adapter;
}

if (empty($this->adapters)) {
throw new InvalidArgumentException(
throw new \InvalidArgumentException(
'It is necessary add at least one front matter adapter '.FrontMatterInterface::class
);
}
Expand Down
4 changes: 0 additions & 4 deletions src/FrontMatterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,13 @@ public function exists(string $source): bool;
* Parse source.
*
* @param string $source The source
*
* @return Document
*/
public function parse(string $source): Document;

/**
* Dump document.
*
* @param Document $document The document
*
* @return string
*/
public function dump(Document $document): string;
}
4 changes: 0 additions & 4 deletions src/Processor/ProcessorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ interface ProcessorInterface
* Parses front matter string into a data.
*
* @param string $string The string
*
* @return array
*/
public function parse(string $string): array;

/**
* Dumps a data to a string.
*
* @param array $data The data
*
* @return string
*/
public function dump(array $data): string;
}
11 changes: 11 additions & 0 deletions src/Processor/YamlProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,22 @@

final class YamlProcessor implements ProcessorInterface
{
/**
* @var int-mask-of<Yaml::PARSE_*>
*/
private int $parseFlags;

/**
* @var int-mask-of<Yaml::DUMP_*>
*/
private int $dumpFlags;
private int $inline;
private int $indent;

/**
* @param int-mask-of<Yaml::PARSE_*> $parseFlags
* @param int-mask-of<Yaml::DUMP_*> $dumpFlags
*/
public function __construct(int $parseFlags = 0, int $dumpFlags = 0, int $inline = 2, int $indent = 4)
{
$this->parseFlags = $parseFlags;
Expand Down
Loading

0 comments on commit 0979bbb

Please sign in to comment.