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: 4 additions & 23 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,20 @@

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
use Yiisoft\CodeStyle\ConfigBuilder;

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

return (new Config())
return ConfigBuilder::build()
->setRiskyAllowed(true)
->setParallelConfig(ParallelConfigFactory::detect())
->setRules([
'@PER-CS3.0' => true,
'no_unused_imports' => true,
'no_extra_blank_lines' => [
'tokens' => [
'curly_brace_block',
'extra',
],
],
'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,
],
'@Yiisoft/Core' => true,
'@Yiisoft/Core:risky' => true,
])
->setFinder($finder);
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
<a href="https://github.com/yiisoft" target="_blank">
<img src="https://yiisoft.github.io/docs/images/yii_logo.svg" height="100px" alt="Yii">
</a>
<h1 align="center">Yii _____</h1>
<h1 align="center">Yii Code Style</h1>
<br>
</p>

[![Latest Stable Version](https://poser.pugx.org/yiisoft/_____/v)](https://packagist.org/packages/yiisoft/_____)
[![Total Downloads](https://poser.pugx.org/yiisoft/_____/downloads)](https://packagist.org/packages/yiisoft/_____)
[![Build status](https://github.com/yiisoft/_____/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/yiisoft/_____/actions/workflows/build.yml?query=branch%3Amaster)
[![Code Coverage](https://codecov.io/gh/yiisoft/_____/branch/master/graph/badge.svg)](https://codecov.io/gh/yiisoft/_____)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2F_____%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/_____/master)
[![Static analysis](https://github.com/yiisoft/_____/actions/workflows/static.yml/badge.svg?branch=master)](https://github.com/yiisoft/_____/actions/workflows/static.yml?query=branch%3Amaster)
[![type-coverage](https://shepherd.dev/github/yiisoft/_____/coverage.svg)](https://shepherd.dev/github/yiisoft/_____)
[![psalm-level](https://shepherd.dev/github/yiisoft/_____/level.svg)](https://shepherd.dev/github/yiisoft/_____)
[![Latest Stable Version](https://poser.pugx.org/yiisoft/code-style/v)](https://packagist.org/packages/yiisoft/code-style)
[![Total Downloads](https://poser.pugx.org/yiisoft/code-style/downloads)](https://packagist.org/packages/yiisoft/code-style)
[![Build status](https://github.com/yiisoft/code-style/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/yiisoft/code-style/actions/workflows/build.yml?query=branch%3Amaster)
[![Code Coverage](https://codecov.io/gh/yiisoft/code-style/branch/master/graph/badge.svg)](https://codecov.io/gh/yiisoft/code-style)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fcode-style%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/code-style/master)
[![Static analysis](https://github.com/yiisoft/code-style/actions/workflows/static.yml/badge.svg?branch=master)](https://github.com/yiisoft/code-style/actions/workflows/static.yml?query=branch%3Amaster)
[![type-coverage](https://shepherd.dev/github/yiisoft/code-style/coverage.svg)](https://shepherd.dev/github/yiisoft/code-style)
[![psalm-level](https://shepherd.dev/github/yiisoft/code-style/level.svg)](https://shepherd.dev/github/yiisoft/code-style)

The package ...

Expand All @@ -26,7 +26,7 @@ The package ...
The package could be installed with [Composer](https://getcomposer.org):

```shell
composer require yiisoft/_____
composer require yiisoft/code-style
```

## General usage
Expand All @@ -40,7 +40,7 @@ for that. You may also check out other [Yii Community Resources](https://www.yii

## License

The Yii _____ is free software. It is released under the terms of the BSD License.
The Yii Code Style is free software. It is released under the terms of the BSD License.
Please see [`LICENSE`](./LICENSE.md) for more information.

Maintained by [Yii Software](https://www.yiiframework.com/).
Expand Down
19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "yiisoft/_____",
"name": "yiisoft/code-style",
"type": "library",
"description": "_____",
"description": "Code style tools rulesets collection",
"keywords": [
"_____"
"yii",
"code style"
],
"homepage": "https://www.yiiframework.com/",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/_____/issues?state=open",
"source": "https://github.com/yiisoft/_____",
"issues": "https://github.com/yiisoft/code-style/issues?state=open",
"source": "https://github.com/yiisoft/code-style",
"forum": "https://www.yiiframework.com/forum/",
"wiki": "https://www.yiiframework.com/wiki/",
"irc": "ircs://irc.libera.chat:6697/yii",
Expand All @@ -28,10 +29,10 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.1"
"php": "^8.1",
"friendsofphp/php-cs-fixer": "^3.92.5"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.89.1",
"maglnet/composer-require-checker": "^4.7.1",
"phpunit/phpunit": "^10.5.46",
"rector/rector": "^2.0.16",
Expand All @@ -41,12 +42,12 @@
},
"autoload": {
"psr-4": {
"Yiisoft\\_____\\": "src/"
"Yiisoft\\CodeStyle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Yiisoft\\_____\\Tests\\": "tests/"
"Yiisoft\\CodeStyle\\Tests\\": "tests/"
}
},
"config": {
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</php>

<testsuites>
<testsuite name="Yii _____ tests">
<testsuite name="Yii Code Style tests">
<directory>./tests</directory>
</testsuite>
</testsuites>
Expand Down
Empty file removed src/.gitkeep
Empty file.
23 changes: 23 additions & 0 deletions src/ConfigBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Yiisoft\CodeStyle;

use PhpCsFixer\Config;
use Yiisoft\CodeStyle\Sets\YiisoftCoreRiskySet;
use Yiisoft\CodeStyle\Sets\YiisoftCoreSet;

final class ConfigBuilder
{
public static function build(): Config
{
$config = (new Config());
$config->registerCustomRuleSets([
new YiisoftCoreSet(),
new YiisoftCoreRiskySet(),
]);

return $config;
}
}
34 changes: 34 additions & 0 deletions src/Sets/YiisoftCoreRiskySet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Yiisoft\CodeStyle\Sets;

use PhpCsFixer\RuleSet\RuleSetDefinitionInterface;

final class YiisoftCoreRiskySet implements RuleSetDefinitionInterface
{
public function getName(): string
{
return '@Yiisoft/Core:risky';
}

public function getRules(): array
{
return [

Check warning on line 18 in src/Sets/YiisoftCoreRiskySet.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ } public function getRules(): array { - return ['declare_strict_types' => true, 'native_function_invocation' => true, 'native_constant_invocation' => true]; + return ['native_function_invocation' => true, 'native_constant_invocation' => true]; } public function getDescription(): string {
'declare_strict_types' => true,

Check warning on line 19 in src/Sets/YiisoftCoreRiskySet.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "TrueValue": @@ @@ } public function getRules(): array { - return ['declare_strict_types' => true, 'native_function_invocation' => true, 'native_constant_invocation' => true]; + return ['declare_strict_types' => false, 'native_function_invocation' => true, 'native_constant_invocation' => true]; } public function getDescription(): string {
'native_function_invocation' => true,

Check warning on line 20 in src/Sets/YiisoftCoreRiskySet.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "TrueValue": @@ @@ } public function getRules(): array { - return ['declare_strict_types' => true, 'native_function_invocation' => true, 'native_constant_invocation' => true]; + return ['declare_strict_types' => true, 'native_function_invocation' => false, 'native_constant_invocation' => true]; } public function getDescription(): string {
'native_constant_invocation' => true,

Check warning on line 21 in src/Sets/YiisoftCoreRiskySet.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "TrueValue": @@ @@ } public function getRules(): array { - return ['declare_strict_types' => true, 'native_function_invocation' => true, 'native_constant_invocation' => true]; + return ['declare_strict_types' => true, 'native_function_invocation' => true, 'native_constant_invocation' => false]; } public function getDescription(): string {
];
}

public function getDescription(): string
{
return 'Rules recommended by ``Yiisoft`` team. Extends ``@PER-CS``';
}

public function isRisky(): bool
{
return true;
}
}
49 changes: 49 additions & 0 deletions src/Sets/YiisoftCoreSet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace Yiisoft\CodeStyle\Sets;

use PhpCsFixer\RuleSet\RuleSetDefinitionInterface;

final class YiisoftCoreSet implements RuleSetDefinitionInterface
{
public function getName(): string
{
return '@Yiisoft/Core';
}

public function getRules(): array
{
return [

Check warning on line 18 in src/Sets/YiisoftCoreSet.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ } public function getRules(): array { - return ['@PER-CS' => true, 'no_unused_imports' => true, 'no_extra_blank_lines' => ['tokens' => ['curly_brace_block', 'extra']], 'ordered_class_elements' => true, 'class_attributes_separation' => ['elements' => ['method' => 'one']], 'fully_qualified_strict_types' => ['import_symbols' => true], 'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true]]; + return ['no_unused_imports' => true, 'no_extra_blank_lines' => ['tokens' => ['curly_brace_block', 'extra']], 'ordered_class_elements' => true, 'class_attributes_separation' => ['elements' => ['method' => 'one']], 'fully_qualified_strict_types' => ['import_symbols' => true], 'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true]]; } public function getDescription(): string {
'@PER-CS' => true,

Check warning on line 19 in src/Sets/YiisoftCoreSet.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "TrueValue": @@ @@ } public function getRules(): array { - return ['@PER-CS' => true, 'no_unused_imports' => true, 'no_extra_blank_lines' => ['tokens' => ['curly_brace_block', 'extra']], 'ordered_class_elements' => true, 'class_attributes_separation' => ['elements' => ['method' => 'one']], 'fully_qualified_strict_types' => ['import_symbols' => true], 'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true]]; + return ['@PER-CS' => false, 'no_unused_imports' => true, 'no_extra_blank_lines' => ['tokens' => ['curly_brace_block', 'extra']], 'ordered_class_elements' => true, 'class_attributes_separation' => ['elements' => ['method' => 'one']], 'fully_qualified_strict_types' => ['import_symbols' => true], 'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true]]; } public function getDescription(): string {
'no_unused_imports' => true,

Check warning on line 20 in src/Sets/YiisoftCoreSet.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "TrueValue": @@ @@ } public function getRules(): array { - return ['@PER-CS' => true, 'no_unused_imports' => true, 'no_extra_blank_lines' => ['tokens' => ['curly_brace_block', 'extra']], 'ordered_class_elements' => true, 'class_attributes_separation' => ['elements' => ['method' => 'one']], 'fully_qualified_strict_types' => ['import_symbols' => true], 'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true]]; + return ['@PER-CS' => true, 'no_unused_imports' => false, 'no_extra_blank_lines' => ['tokens' => ['curly_brace_block', 'extra']], 'ordered_class_elements' => true, 'class_attributes_separation' => ['elements' => ['method' => 'one']], 'fully_qualified_strict_types' => ['import_symbols' => true], 'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true]]; } public function getDescription(): string {
'no_extra_blank_lines' => [

Check warning on line 21 in src/Sets/YiisoftCoreSet.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ } public function getRules(): array { - return ['@PER-CS' => true, 'no_unused_imports' => true, 'no_extra_blank_lines' => ['tokens' => ['curly_brace_block', 'extra']], 'ordered_class_elements' => true, 'class_attributes_separation' => ['elements' => ['method' => 'one']], 'fully_qualified_strict_types' => ['import_symbols' => true], 'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true]]; + return ['@PER-CS' => true, 'no_unused_imports' => true, 'no_extra_blank_lines' => [], 'ordered_class_elements' => true, 'class_attributes_separation' => ['elements' => ['method' => 'one']], 'fully_qualified_strict_types' => ['import_symbols' => true], 'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true]]; } public function getDescription(): string {
'tokens' => [

Check warning on line 22 in src/Sets/YiisoftCoreSet.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ } public function getRules(): array { - return ['@PER-CS' => true, 'no_unused_imports' => true, 'no_extra_blank_lines' => ['tokens' => ['curly_brace_block', 'extra']], 'ordered_class_elements' => true, 'class_attributes_separation' => ['elements' => ['method' => 'one']], 'fully_qualified_strict_types' => ['import_symbols' => true], 'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true]]; + return ['@PER-CS' => true, 'no_unused_imports' => true, 'no_extra_blank_lines' => ['tokens' => ['extra']], 'ordered_class_elements' => true, 'class_attributes_separation' => ['elements' => ['method' => 'one']], 'fully_qualified_strict_types' => ['import_symbols' => true], 'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true]]; } public function getDescription(): string {
'curly_brace_block',
'extra',
],
],
'ordered_class_elements' => true,

Check warning on line 27 in src/Sets/YiisoftCoreSet.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "TrueValue": @@ @@ } public function getRules(): array { - return ['@PER-CS' => true, 'no_unused_imports' => true, 'no_extra_blank_lines' => ['tokens' => ['curly_brace_block', 'extra']], 'ordered_class_elements' => true, 'class_attributes_separation' => ['elements' => ['method' => 'one']], 'fully_qualified_strict_types' => ['import_symbols' => true], 'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true]]; + return ['@PER-CS' => true, 'no_unused_imports' => true, 'no_extra_blank_lines' => ['tokens' => ['curly_brace_block', 'extra']], 'ordered_class_elements' => false, 'class_attributes_separation' => ['elements' => ['method' => 'one']], 'fully_qualified_strict_types' => ['import_symbols' => true], 'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true]]; } public function getDescription(): string {
'class_attributes_separation' => ['elements' => ['method' => 'one']],
'fully_qualified_strict_types' => [
'import_symbols' => true,
],
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => true,
],
];
}

public function getDescription(): string
{
return 'Rules recommended by ``Yiisoft`` team. Extends ``@PER-CS``.';
}

public function isRisky(): bool
{
return false;
}
}
Empty file removed tests/.gitkeep
Empty file.
31 changes: 31 additions & 0 deletions tests/ConfigBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Yiisoft\CodeStyle\Tests;

use PHPUnit\Framework\TestCase;
use Yiisoft\CodeStyle\ConfigBuilder;
use Yiisoft\CodeStyle\Sets\YiisoftCoreRiskySet;
use Yiisoft\CodeStyle\Sets\YiisoftCoreSet;

final class ConfigBuilderTest extends TestCase
{
public function testBuild(): void
{
$config = ConfigBuilder::build();
$customRuleSets = $config->getCustomRuleSets();

$this->assertCount(2, $customRuleSets);

$this->assertInstanceOf(YiisoftCoreSet::class, $customRuleSets[0]);
$this->assertNotEmpty($customRuleSets[0]->getRules());
$this->assertNotEmpty($customRuleSets[0]->getDescription());
$this->assertFalse($customRuleSets[0]->isRisky());

$this->assertInstanceOf(YiisoftCoreRiskySet::class, $customRuleSets[1]);
$this->assertNotEmpty($customRuleSets[1]->getRules());
$this->assertNotEmpty($customRuleSets[1]->getDescription());
$this->assertTrue($customRuleSets[1]->isRisky());
}
}