Skip to content

Commit

Permalink
Merge 2.x to master
Browse files Browse the repository at this point in the history
  • Loading branch information
rudashi authored Nov 3, 2024
2 parents 9fbceda + 234fb9e commit 00ed2de
Show file tree
Hide file tree
Showing 29 changed files with 153 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.1, 8.2, 8.3]
php: [8.2, 8.3]

name: PHP ${{ matrix.php }}

Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM php:8.2-fpm

RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
&& docker-php-ext-enable xdebug \
&& curl -sLS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer

# Configure Xdebug
RUN echo "xdebug.mode=develop,debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
RUN echo "xdebug.mode=develop,debug,coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

This package provides a simple way to create regular expression in a fluent way.

**Fluent Regex** is a library in PHP that simplifies the creation and management of regular expressions through
the use of fluent syntax. Traditional regular expressions can be difficult to read and understand, especially when
they become complex. **Fluent Regex** solves this problem by allowing you to build regular expressions using
**Fluent Regex** is a library in PHP that simplifies the creation and management of regular expressions through
the use of fluent syntax. Traditional regular expressions can be difficult to read and understand, especially when
they become complex. **Fluent Regex** solves this problem by allowing you to build regular expressions using
a readable and intuitive object-oriented interface.

> If you thought that finding a `needle` in a `haystack` was impossible, this repository is for you.
Expand All @@ -29,10 +29,10 @@ composer require rudashi/fluent-regex

## Version Guidance

| Version | Branch | PHP Version |
|---------|---------------------------------------------------------|-------------|
| v1.x | [1.x](https://github.com/rudashi/fluent-regex/tree/1.x) | ^8.1 |
| v2.x | [2.x](https://github.com/rudashi/fluent-regex/tree/2.x) | ^8.2 |
| Version | Branch | PHP Version | Composer Install |
|---------|---------------------------------------------------------|-------------|----------------------------------------------|
| v2.x | [2.x](https://github.com/rudashi/fluent-regex/tree/2.x) | ^8.2 | `composer require rudashi/fluent-regex:^2.0` |
| v1.x | [1.x](https://github.com/rudashi/fluent-regex/tree/1.x) | ^8.1 | `composer require rudashi/fluent-regex:^1.0` |

## Usage

Expand All @@ -52,11 +52,13 @@ $match = Regex::for('https://100commitow.pl/')->find('100commitow')->check();

## Documentation

The [Fluent Regex documentation](https://rudashi.github.io/fluent-regex/) is extensive and complete, making getting started with regular expression syntax a breeze.
The [Fluent Regex documentation](https://rudashi.github.io/fluent-regex/) is extensive and complete, making getting
started with regular expression syntax a breeze.

## Changelog

Detailed changes for each release are documented in the [CHANGELOG.md](https://github.com/rudashi/fluent-regex/blob/master/CHANGELOG.md).
Detailed changes for each release are documented in
the [CHANGELOG.md](https://github.com/rudashi/fluent-regex/blob/master/CHANGELOG.md).

## Credits

Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "rudashi/fluent-regex",
"description": "Elegant way for PHP regex",
"version": "1.0.0",
"version": "2.0.0",
"license": "MIT",
"keywords": [
"php",
Expand All @@ -17,15 +17,14 @@
}
],
"require": {
"php": ">=8.1"
"php": ">=8.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"nunomaduro/phpinsights": "^2.0",
"pestphp/pest": "^2.0",
"pestphp/pest": "^3.0",
"phpstan/phpstan": "^1.0",
"rector/rector": "^1.0",
"symfony/var-dumper": "^6.0"
"symfony/var-dumper": "^7.0"
},
"autoload": {
"psr-4": {
Expand All @@ -52,14 +51,15 @@
"test:arch": "pest --filter=arch",
"test:unit": "pest --testsuite=unit",
"test:integration": "pest --testsuite=integration",
"insights": "phpinsights analyse",
"test:mutate": "pest --mutate",
"test": [
"@test:pint",
"@test:refactor",
"@test:types",
"@test:arch",
"@test:unit",
"@test:integration"
"@test:integration",
"@test:mutate"
]
}
}
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ services:
php:
build:
dockerfile: Dockerfile
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
VAR_DUMPER_FORMAT: server
volumes:
- '.:/var/www/html'
composer:
image: composer
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
VAR_DUMPER_SERVER: host.docker.internal:9912
volumes:
- '.:/var/www/html'
12 changes: 7 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
includes:
- vendor/pestphp/pest/extension.neon

parameters:
paths:
- src
- tests
level: 9
level: max
ignoreErrors:
- '#Call to an undefined method Pest\\Mixins\\Expectation#'
-
message: '#Undefined variable: \$this.*#'
path: tests/**
- '#Call to an undefined method Pest#'
universalObjectCratesClasses:
- PHPUnit\Framework\TestCase
earlyTerminatingMethodCalls:
Rudashi\FluentBuilder:
- throwBadMethodException
5 changes: 1 addition & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
failOnRisky="true"
>
<testsuites>
<testsuite name="default">
<directory>./tests</directory>
</testsuite>
<testsuite name="unit">
<directory>./tests/Unit</directory>
</testsuite>
<testsuite name="integration">
<directory>./tests/Feature</directory>
<directory>./tests/Patterns</directory>
</testsuite>
</testsuites>
<source>
Expand Down
6 changes: 3 additions & 3 deletions src/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
use Rudashi\Tokens\Letter;
use Rudashi\Tokens\Number;

final class Token
final readonly class Token
{
public function __construct(
private readonly FluentBuilder $builder,
private readonly bool $sub = false,
private FluentBuilder $builder,
private bool $sub = false,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Tokens/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use LogicException;
use Rudashi\Contracts\TokenContract;

final class Group implements TokenContract
final readonly class Group implements TokenContract
{
public function __construct(
private readonly TokenContract $group,
private TokenContract $group,
) {
}

Expand Down
8 changes: 4 additions & 4 deletions src/Tokens/Letter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
use LogicException;
use Rudashi\Contracts\TokenContract;

final class Letter implements TokenContract
final readonly class Letter implements TokenContract
{
private const FIRST = 'a';
private const LAST = 'z';

public function __construct(
private readonly string $first,
private readonly string $last,
private readonly bool $onlyLower = false,
private string $first,
private string $last,
private bool $onlyLower = false,
) {
if (! in_array($this->first, range('a', 'y'), true)) {
$this->throwLogicException('The first letter must be between [a-y].');
Expand Down
6 changes: 3 additions & 3 deletions src/Tokens/NegativeGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

use Rudashi\Contracts\TokenContract;

final class NegativeGroup implements TokenContract
final readonly class NegativeGroup implements TokenContract
{
public function __construct(
private readonly bool $lookbehind = false,
private readonly bool $lookahead = false,
private bool $lookbehind = false,
private bool $lookahead = false,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/Tokens/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use LogicException;
use Rudashi\Contracts\TokenContract;

final class Number implements TokenContract
final readonly class Number implements TokenContract
{
private const MIN = 0;
private const MAX = 9;

public function __construct(
private readonly int $min,
private readonly int $max,
private int $min,
private int $max,
) {
if ($this->min < self::MIN || $this->min > self::MAX - 1) {
$this->throwLogicException();
Expand Down
6 changes: 3 additions & 3 deletions src/Tokens/PositiveGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

use Rudashi\Contracts\TokenContract;

final class PositiveGroup implements TokenContract
final readonly class PositiveGroup implements TokenContract
{
public function __construct(
private readonly bool $lookbehind = false,
private readonly bool $lookahead = false,
private bool $lookbehind = false,
private bool $lookahead = false,
) {
}

Expand Down
9 changes: 9 additions & 0 deletions tests/ArchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@
use Rudashi\Contracts\PatternContract;
use Rudashi\Flag;

arch()->preset()->security();

arch()->preset()->php()->ignoring(Dumpable::class);

arch('strict types are everywhere', function () {
expect('Rudashi')
->toUseStrictTypes();
});

arch('strict equality', function () {
expect('Rudashi\JavaScript')
->toUseStrictEquality();
});

arch('globals', function () {
expect(['dd', 'dump', 'die', 'var_dump', 'sleep'])
->not->toBeUsed()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

declare(strict_types=1);

use Rudashi\Contracts\PatternContract;
use Rudashi\FluentBuilder;
use Rudashi\Negate;
use Rudashi\Pattern;
use Rudashi\Token;

/*
Expand Down Expand Up @@ -63,3 +65,15 @@ function token(bool $asSub = false): Token
{
return new Token(fluentBuilder(), $asSub);
}

function fakePattern(): Pattern
{
return new class() extends Pattern implements PatternContract {
protected static string $name = 'fake-pattern';

public function getName(): string
{
return 'diff-name';
}
};
}
4 changes: 4 additions & 0 deletions tests/Unit/AnchorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

declare(strict_types=1);

use Rudashi\Anchors;

mutates(Anchors::class);

it('can add `start of a string` anchor', function () {
$regex = fluentBuilder()->start();

Expand Down
10 changes: 6 additions & 4 deletions tests/Unit/DumpableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
it('can use `dump`', function () {
ob_start();

$result = $this->builder->dump();
$this->builder->dump();
$dump = ob_get_clean();

expect($result)
->toBeInstanceOf(FluentBuilder::class)
->and($this->getDump($dump))
// @phpstan-ignore-next-line
expect($this->getDump($dump))
->toBeString()
->toContain(...EXPECTED_DUMP);
});

Expand All @@ -53,6 +53,7 @@
$this->builder->dump($var1);
$dump = ob_get_clean();

// @phpstan-ignore-next-line
expect($this->getDump($dump))
->toContain(
'}\n
Expand All @@ -71,6 +72,7 @@
$this->builder->dump($var1, $var2, $var3);
$dump = ob_get_clean();

// @phpstan-ignore-next-line
expect($this->getDump($dump))
->toContain(
'}\n
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/FlagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

declare(strict_types=1);

use Rudashi\Concerns\Flags;

mutates(Flags::class);

it('can add `insensitive` flag', function () {
$regex = fluentBuilder()->ignoreCase();

Expand Down
15 changes: 0 additions & 15 deletions tests/Unit/PatternTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@

declare(strict_types=1);

use Rudashi\Contracts\PatternContract;
use Rudashi\Pattern;

function fakePattern(): Pattern
{
return new class() extends Pattern implements PatternContract {
protected static string $name = 'fake-pattern';

public function getName(): string
{
return 'diff-name';
}
};
}

it('can return static name', function () {
$pattern = fakePattern();

Expand Down
Loading

0 comments on commit 00ed2de

Please sign in to comment.