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
27 changes: 27 additions & 0 deletions .github/workflows/rector-cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Rector + PHP CS Fixer

on:
pull_request_target:
paths:
- 'src/**'
- 'tests/**'
- '.github/workflows/rector-cs.yml'
- 'composer.json'
- 'rector.php'
- '.php-cs-fixer.dist.php'

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector-cs.yml@master
secrets:
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
php: '8.0'
21 changes: 0 additions & 21 deletions .github/workflows/rector.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ phpunit.phar
/phpunit.xml
# phpunit cache
.phpunit.result.cache

# PHP CS Fixer
/.php-cs-fixer.cache
/.php-cs-fixer.php
40 changes: 40 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

$finder = (new Finder())->in([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// TODO: Update the configuration after raising the minimum PHP version
return (new Config())
->setRiskyAllowed(true)
->setParallelConfig(ParallelConfigFactory::detect())
->setRules([
'@PER-CS2.0' => true,
'nullable_type_declaration' => true,
'operator_linebreak' => true,
'ordered_types' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'single_class_element_per_statement' => true,
'types_spaces' => true,
'no_unused_imports' => true,
'ordered_class_elements' => true,
'class_attributes_separation' => ['elements' => ['method' => 'one']],
'declare_strict_types' => true,
'native_function_invocation' => true,
'native_constant_invocation' => true,
'fully_qualified_strict_types' => [
'import_symbols' => true
],
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => true,
],
])
->setFinder($finder);
85 changes: 0 additions & 85 deletions .styleci.yml

This file was deleted.

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"symfony/finder": "^5.4|^6.0|^7.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.66",
"maglnet/composer-require-checker": "^4.2",
"phpunit/phpunit": "^9.5",
"rector/rector": "^2.0.3",
Expand Down
8 changes: 6 additions & 2 deletions src/Classifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
use ReflectionClass;
use Symfony\Component\Finder\Finder;

use function count;

use const DIRECTORY_SEPARATOR;

/**
* Classifier traverses file system to find classes by a certain criteria.
*/
Expand Down Expand Up @@ -37,7 +41,7 @@
*/
public function __construct(string $directory, string ...$directories)
{
$this->directories = [$directory, ...array_values($directories)];

Check warning on line 44 in src/Classifier.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "UnwrapArrayValues": --- Original +++ New @@ @@ */ public function __construct(string $directory, string ...$directories) { - $this->directories = [$directory, ...array_values($directories)]; + $this->directories = [$directory, ...$directories]; } /** * @param string ...$interfaces Interfaces to search for.
}

/**
Expand All @@ -46,8 +50,8 @@
*/
public function withInterface(string ...$interfaces): self
{
$new = clone $this;

Check warning on line 53 in src/Classifier.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "CloneRemoval": --- Original +++ New @@ @@ */ public function withInterface(string ...$interfaces) : self { - $new = clone $this; + $new = $this; array_push($new->interfaces, ...array_values($interfaces)); return $new; }
array_push($new->interfaces, ...array_values($interfaces));

Check warning on line 54 in src/Classifier.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "UnwrapArrayValues": --- Original +++ New @@ @@ public function withInterface(string ...$interfaces) : self { $new = clone $this; - array_push($new->interfaces, ...array_values($interfaces)); + array_push($new->interfaces, ...$interfaces); return $new; } /**

return $new;
}
Expand All @@ -58,7 +62,7 @@
*/
public function withParentClass(string $parentClass): self
{
$new = clone $this;

Check warning on line 65 in src/Classifier.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "CloneRemoval": --- Original +++ New @@ @@ */ public function withParentClass(string $parentClass) : self { - $new = clone $this; + $new = $this; $new->parentClass = $parentClass; return $new; }
$new->parentClass = $parentClass;
return $new;
}
Expand All @@ -69,8 +73,8 @@
*/
public function withAttribute(string ...$attributes): self
{
$new = clone $this;

Check warning on line 76 in src/Classifier.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "CloneRemoval": --- Original +++ New @@ @@ */ public function withAttribute(string ...$attributes) : self { - $new = clone $this; + $new = $this; array_push($new->attributes, ...array_values($attributes)); return $new; }
array_push($new->attributes, ...array_values($attributes));

Check warning on line 77 in src/Classifier.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "UnwrapArrayValues": --- Original +++ New @@ @@ public function withAttribute(string ...$attributes) : self { $new = clone $this; - array_push($new->attributes, ...array_values($attributes)); + array_push($new->attributes, ...$attributes); return $new; } /**

return $new;
}
Expand Down Expand Up @@ -108,14 +112,14 @@

$matchedDirs = array_filter(
$directories,
static fn($directory) => str_starts_with($reflection->getFileName(), $directory)
static fn($directory) => str_starts_with($reflection->getFileName(), $directory),
);

if (count($matchedDirs) === 0) {
continue;
}

if ($countInterfaces > 0) {

Check warning on line 122 in src/Classifier.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "GreaterThan": --- Original +++ New @@ @@ if (count($matchedDirs) === 0) { continue; } - if ($countInterfaces > 0) { + if ($countInterfaces >= 0) { $interfaces = $reflection->getInterfaces(); $interfaces = array_map(static fn(ReflectionClass $class) => $class->getName(), $interfaces); if (count(array_intersect($this->interfaces, $interfaces)) !== $countInterfaces) {
$interfaces = $reflection->getInterfaces();
$interfaces = array_map(static fn(ReflectionClass $class) => $class->getName(), $interfaces);

Expand All @@ -124,11 +128,11 @@
}
}

if ($countAttributes > 0) {

Check warning on line 131 in src/Classifier.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.1-ubuntu-latest

Escaped Mutant for Mutator "GreaterThan": --- Original +++ New @@ @@ continue; } } - if ($countAttributes > 0) { + if ($countAttributes >= 0) { $attributes = $reflection->getAttributes(); $attributes = array_map(static fn(ReflectionAttribute $attribute) => $attribute->getName(), $attributes); if (count(array_intersect($this->attributes, $attributes)) !== $countAttributes) {
$attributes = $reflection->getAttributes();
$attributes = array_map(
static fn(ReflectionAttribute $attribute) => $attribute->getName(),
$attributes
$attributes,
);

if (count(array_intersect($this->attributes, $attributes)) !== $countAttributes) {
Expand Down
4 changes: 1 addition & 3 deletions tests/Support/Attributes/AuthorAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
use Attribute;

#[Attribute]
class AuthorAttribute
{
}
class AuthorAttribute {}
4 changes: 1 addition & 3 deletions tests/Support/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
use Yiisoft\Classifier\Tests\Support\Attributes\AuthorAttribute;

#[AuthorAttribute]
class Author
{
}
class Author {}
4 changes: 1 addition & 3 deletions tests/Support/AuthorPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@
use Yiisoft\Classifier\Tests\Support\Interfaces\PostInterface;

#[AuthorAttribute]
class AuthorPost implements PostInterface
{
}
class AuthorPost implements PostInterface {}
4 changes: 1 addition & 3 deletions tests/Support/Dir1/UserInDir1.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use Yiisoft\Classifier\Tests\Support\Interfaces\UserInterface;

class UserInDir1 implements UserInterface
{
}
class UserInDir1 implements UserInterface {}
4 changes: 1 addition & 3 deletions tests/Support/Dir2/UserInDir2.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use Yiisoft\Classifier\Tests\Support\Interfaces\UserInterface;

class UserInDir2 implements UserInterface
{
}
class UserInDir2 implements UserInterface {}
4 changes: 1 addition & 3 deletions tests/Support/Interfaces/PostInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace Yiisoft\Classifier\Tests\Support\Interfaces;

interface PostInterface
{
}
interface PostInterface {}
4 changes: 1 addition & 3 deletions tests/Support/Interfaces/UserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace Yiisoft\Classifier\Tests\Support\Interfaces;

interface UserInterface
{
}
interface UserInterface {}
4 changes: 1 addition & 3 deletions tests/Support/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use Yiisoft\Classifier\Tests\Support\Interfaces\PostInterface;

class Post implements PostInterface
{
}
class Post implements PostInterface {}
4 changes: 1 addition & 3 deletions tests/Support/PostUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
use Yiisoft\Classifier\Tests\Support\Interfaces\PostInterface;
use Yiisoft\Classifier\Tests\Support\Interfaces\UserInterface;

class PostUser implements UserInterface, PostInterface
{
}
class PostUser implements UserInterface, PostInterface {}
4 changes: 1 addition & 3 deletions tests/Support/SuperSuperUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace Yiisoft\Classifier\Tests\Support;

class SuperSuperUser extends SuperUser
{
}
class SuperSuperUser extends SuperUser {}
4 changes: 1 addition & 3 deletions tests/Support/SuperUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace Yiisoft\Classifier\Tests\Support;

class SuperUser extends User implements UserSubInterface
{
}
class SuperUser extends User implements UserSubInterface {}
4 changes: 1 addition & 3 deletions tests/Support/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use Yiisoft\Classifier\Tests\Support\Interfaces\UserInterface;

class User implements UserInterface
{
}
class User implements UserInterface {}
4 changes: 1 addition & 3 deletions tests/Support/UserSubInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use Yiisoft\Classifier\Tests\Support\Interfaces\UserInterface;

interface UserSubInterface extends UserInterface
{
}
interface UserSubInterface extends UserInterface {}
4 changes: 1 addition & 3 deletions tests/Support/UserSubclass.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace Yiisoft\Classifier\Tests\Support;

class UserSubclass implements UserSubInterface
{
}
class UserSubclass implements UserSubInterface {}