Skip to content

Commit

Permalink
Move to php 8.1 (#292)
Browse files Browse the repository at this point in the history
* Add code style tool

* Run Code style check in CI

* Fix code style

* Remove getTranslator method

* Update to php 8.1

* Reformat code according to php 8.1
  • Loading branch information
funivan authored Jan 11, 2024
1 parent ab579bf commit b7f5545
Showing 37 changed files with 167 additions and 270 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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": {
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
@@ -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
@@ -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;

/**
@@ -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
*/
@@ -39,7 +38,6 @@ final public function count(): int
return \count($this->all());
}


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


/**
* @throws InvalidArgumentException
*/
@@ -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(
@@ -107,7 +103,6 @@ final public function merge(ElementCollection $collection): ElementCollection
return new ElementCollection(array_merge($this->all(), $collection->all()));
}


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


/**
* Retrieve an external iterator
*
9 changes: 3 additions & 6 deletions src/Collection/Filters/StringFilter/RegexStringFilter.php
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 0 additions & 3 deletions src/Collection/Filters/StringFilter/StringFilterInterface.php
Original file line number Diff line number Diff line change
@@ -4,9 +4,6 @@

namespace Xparse\ElementFinder\Collection\Filters\StringFilter;

/**
*
*/
interface StringFilterInterface
{
public function valid(string $input): bool;
10 changes: 4 additions & 6 deletions src/Collection/Modify/StringModify/RegexReplace.php
Original file line number Diff line number Diff line change
@@ -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);
20 changes: 7 additions & 13 deletions src/Collection/ObjectCollection.php
Original file line number Diff line number Diff line change
@@ -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;

/**
@@ -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
*/
@@ -40,7 +39,6 @@ final public function count(): int
return \count($this->all());
}


/**
* @throws InvalidArgumentException
*/
@@ -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(
@@ -99,7 +96,6 @@ final public function merge(ObjectCollection $collection): ObjectCollection
return new ObjectCollection(array_merge($this->all(), $collection->all()));
}


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


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


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

0 comments on commit b7f5545

Please sign in to comment.