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

Move to php 8.1 #292

Merged
merged 6 commits into from
Jan 11, 2024
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
5 changes: 4 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.0', '8.1', '8.2', '8.3']
php-versions: [ '8.1', '8.2', '8.3']
name: PHP ${{ matrix.php-versions }}
steps:
- name: Checkout
Expand Down Expand Up @@ -45,3 +45,6 @@ jobs:

- name: Run rector
run: ./vendor/bin/rector --dry-run

- name: Run code style check
run: ./vendor/bin/ecs
2 changes: 2 additions & 0 deletions .idea/ElementFinder.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"ext-dom": "*",
"ext-libxml": "*",
"symfony/css-selector": "^5.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.16",
"phpunit/phpunit": "^9.5.2",
"rector/rector": "^0.19.0"
"rector/rector": "^0.19",
"symplify/easy-coding-standard": "^12.1"
},
"autoload": {
"psr-4": {
Expand Down
21 changes: 21 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer;
use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
__FILE__,
]);

$ecsConfig->rules([NoUnusedImportsFixer::class, VoidReturnFixer::class]);

// this way you can add sets - group of rules
$ecsConfig->sets([SetList::SPACES, SetList::ARRAY, SetList::DOCBLOCK, SetList::NAMESPACES, SetList::COMMENTS, SetList::PSR_12]);
};
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
$rectorConfig->rule(TypedPropertyFromStrictConstructorRector::class);
$rectorConfig->rule(SeparateMultiUseImportsRector::class);
$rectorConfig->importNames();
$rectorConfig->sets([LevelSetList::UP_TO_PHP_80, PHPUnitSetList::PHPUNIT_90]);
$rectorConfig->sets([LevelSetList::UP_TO_PHP_81, PHPUnitSetList::PHPUNIT_90]);
};
20 changes: 7 additions & 13 deletions src/Collection/ElementCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Xparse\ElementFinder\Collection;

use IteratorAggregate;
use ArrayIterator;
use Countable;
use InvalidArgumentException;
use IteratorAggregate;
use Traversable;
use ArrayIterator;
use Xparse\ElementFinder\ElementFinder\Element;

/**
Expand All @@ -21,16 +21,15 @@ class ElementCollection implements IteratorAggregate, Countable
*/
private $validated = false;


/**
* @param Element[] $items
* @throws InvalidArgumentException
*/
public function __construct(private array $items = [])
{
public function __construct(
private readonly array $items = []
) {
}


/**
* @throws InvalidArgumentException
*/
Expand All @@ -39,7 +38,6 @@ final public function count(): int
return \count($this->all());
}


/**
* @throws InvalidArgumentException
*/
Expand All @@ -64,7 +62,6 @@ final public function first(): ?Element
return reset($items);
}


/**
* @throws InvalidArgumentException
*/
Expand All @@ -73,16 +70,15 @@ final public function get(int $index): ?Element
return $this->all()[$index] ?? null;
}


/**
* @return Element[]
* @throws InvalidArgumentException
*/
final public function all(): array
{
if (!$this->validated) {
if (! $this->validated) {
foreach ($this->items as $key => $item) {
if (!$item instanceof Element) {
if (! $item instanceof Element) {
$className = ($item === null) ? \gettype($item) : $item::class;
throw new InvalidArgumentException(
sprintf(
Expand All @@ -107,7 +103,6 @@ final public function merge(ElementCollection $collection): ElementCollection
return new ElementCollection(array_merge($this->all(), $collection->all()));
}


/**
* @throws InvalidArgumentException
*/
Expand All @@ -118,7 +113,6 @@ final public function add(Element $element): ElementCollection
return new ElementCollection($items);
}


/**
* Retrieve an external iterator
*
Expand Down
9 changes: 3 additions & 6 deletions src/Collection/Filters/StringFilter/RegexStringFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@

namespace Xparse\ElementFinder\Collection\Filters\StringFilter;

/**
*
*/
class RegexStringFilter implements StringFilterInterface
{
public function __construct(private string $regex)
{
public function __construct(
private readonly string $regex
) {
}


final public function valid(string $input): bool
{
return preg_match($this->regex, $input) === 1;
Expand Down
3 changes: 0 additions & 3 deletions src/Collection/Filters/StringFilter/StringFilterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace Xparse\ElementFinder\Collection\Filters\StringFilter;

/**
*
*/
interface StringFilterInterface
{
public function valid(string $input): bool;
Expand Down
10 changes: 4 additions & 6 deletions src/Collection/Modify/StringModify/RegexReplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

namespace Xparse\ElementFinder\Collection\Modify\StringModify;

/**
*
*/
class RegexReplace implements StringModifyInterface
{
public function __construct(private string $from, private string $to)
{
public function __construct(
private readonly string $from,
private readonly string $to
) {
}


final public function modify(string $input): string
{
return preg_replace($this->from, $this->to, $input);
Expand Down
20 changes: 7 additions & 13 deletions src/Collection/ObjectCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Xparse\ElementFinder\Collection;

use IteratorAggregate;
use ArrayIterator;
use Countable;
use Exception;
use InvalidArgumentException;
use IteratorAggregate;
use Traversable;
use ArrayIterator;
use Xparse\ElementFinder\ElementFinderInterface;

/**
Expand All @@ -22,16 +22,15 @@ class ObjectCollection implements IteratorAggregate, Countable
*/
private $validated = false;


/**
* @param ElementFinderInterface[] $items
* @throws Exception
*/
public function __construct(private array $items = [])
{
public function __construct(
private readonly array $items = []
) {
}


/**
* @throws InvalidArgumentException
*/
Expand All @@ -40,7 +39,6 @@ final public function count(): int
return \count($this->all());
}


/**
* @throws InvalidArgumentException
*/
Expand All @@ -65,16 +63,15 @@ final public function first(): ?ElementFinderInterface
return reset($items);
}


/**
* @return ElementFinderInterface[]
* @throws InvalidArgumentException
*/
final public function all(): array
{
if (!$this->validated) {
if (! $this->validated) {
foreach ($this->items as $key => $item) {
if (!$item instanceof ElementFinderInterface) {
if (! $item instanceof ElementFinderInterface) {
$className = ($item === null) ? \gettype($item) : $item::class;
throw new InvalidArgumentException(
sprintf(
Expand All @@ -99,7 +96,6 @@ final public function merge(ObjectCollection $collection): ObjectCollection
return new ObjectCollection(array_merge($this->all(), $collection->all()));
}


/**
* @throws Exception
*/
Expand All @@ -110,7 +106,6 @@ final public function add(ElementFinderInterface $element): ObjectCollection
return new ObjectCollection($items);
}


/**
* @throws InvalidArgumentException
*/
Expand All @@ -119,7 +114,6 @@ final public function get(int $index): ?ElementFinderInterface
return $this->all()[$index] ?? null;
}


/**
* @return ElementFinderInterface[]|Traversable
* @throws InvalidArgumentException
Expand Down
Loading
Loading