Skip to content

Commit 34bebb4

Browse files
authored
First implementation (#1)
1 parent 8310bf8 commit 34bebb4

10 files changed

Lines changed: 163 additions & 44 deletions

.php-cs-fixer.dist.php

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,20 @@
22

33
declare(strict_types=1);
44

5-
use PhpCsFixer\Config;
65
use PhpCsFixer\Finder;
76
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
7+
use Yiisoft\CodeStyle\ConfigBuilder;
88

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

14-
return (new Config())
14+
return ConfigBuilder::build()
1515
->setRiskyAllowed(true)
1616
->setParallelConfig(ParallelConfigFactory::detect())
1717
->setRules([
18-
'@PER-CS3.0' => true,
19-
'no_unused_imports' => true,
20-
'no_extra_blank_lines' => [
21-
'tokens' => [
22-
'curly_brace_block',
23-
'extra',
24-
],
25-
],
26-
'ordered_class_elements' => true,
27-
'class_attributes_separation' => ['elements' => ['method' => 'one']],
28-
'declare_strict_types' => true,
29-
'native_function_invocation' => true,
30-
'native_constant_invocation' => true,
31-
'fully_qualified_strict_types' => [
32-
'import_symbols' => true
33-
],
34-
'global_namespace_import' => [
35-
'import_classes' => true,
36-
'import_constants' => true,
37-
'import_functions' => true,
38-
],
18+
'@Yiisoft/Core' => true,
19+
'@Yiisoft/Core:risky' => true,
3920
])
4021
->setFinder($finder);

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
<a href="https://github.com/yiisoft" target="_blank">
33
<img src="https://yiisoft.github.io/docs/images/yii_logo.svg" height="100px" alt="Yii">
44
</a>
5-
<h1 align="center">Yii _____</h1>
5+
<h1 align="center">Yii Code Style</h1>
66
<br>
77
</p>
88

9-
[![Latest Stable Version](https://poser.pugx.org/yiisoft/_____/v)](https://packagist.org/packages/yiisoft/_____)
10-
[![Total Downloads](https://poser.pugx.org/yiisoft/_____/downloads)](https://packagist.org/packages/yiisoft/_____)
11-
[![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)
12-
[![Code Coverage](https://codecov.io/gh/yiisoft/_____/branch/master/graph/badge.svg)](https://codecov.io/gh/yiisoft/_____)
13-
[![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)
14-
[![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)
15-
[![type-coverage](https://shepherd.dev/github/yiisoft/_____/coverage.svg)](https://shepherd.dev/github/yiisoft/_____)
16-
[![psalm-level](https://shepherd.dev/github/yiisoft/_____/level.svg)](https://shepherd.dev/github/yiisoft/_____)
9+
[![Latest Stable Version](https://poser.pugx.org/yiisoft/code-style/v)](https://packagist.org/packages/yiisoft/code-style)
10+
[![Total Downloads](https://poser.pugx.org/yiisoft/code-style/downloads)](https://packagist.org/packages/yiisoft/code-style)
11+
[![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)
12+
[![Code Coverage](https://codecov.io/gh/yiisoft/code-style/branch/master/graph/badge.svg)](https://codecov.io/gh/yiisoft/code-style)
13+
[![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)
14+
[![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)
15+
[![type-coverage](https://shepherd.dev/github/yiisoft/code-style/coverage.svg)](https://shepherd.dev/github/yiisoft/code-style)
16+
[![psalm-level](https://shepherd.dev/github/yiisoft/code-style/level.svg)](https://shepherd.dev/github/yiisoft/code-style)
1717

1818
The package ...
1919

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

2828
```shell
29-
composer require yiisoft/_____
29+
composer require yiisoft/code-style
3030
```
3131

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

4141
## License
4242

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

4646
Maintained by [Yii Software](https://www.yiiframework.com/).

composer.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
2-
"name": "yiisoft/_____",
2+
"name": "yiisoft/code-style",
33
"type": "library",
4-
"description": "_____",
4+
"description": "Code style tools rulesets collection",
55
"keywords": [
6-
"_____"
6+
"yii",
7+
"code style"
78
],
89
"homepage": "https://www.yiiframework.com/",
910
"license": "BSD-3-Clause",
1011
"support": {
11-
"issues": "https://github.com/yiisoft/_____/issues?state=open",
12-
"source": "https://github.com/yiisoft/_____",
12+
"issues": "https://github.com/yiisoft/code-style/issues?state=open",
13+
"source": "https://github.com/yiisoft/code-style",
1314
"forum": "https://www.yiiframework.com/forum/",
1415
"wiki": "https://www.yiiframework.com/wiki/",
1516
"irc": "ircs://irc.libera.chat:6697/yii",
@@ -28,10 +29,10 @@
2829
"minimum-stability": "dev",
2930
"prefer-stable": true,
3031
"require": {
31-
"php": "^8.1"
32+
"php": "^8.1",
33+
"friendsofphp/php-cs-fixer": "^3.92.5"
3234
},
3335
"require-dev": {
34-
"friendsofphp/php-cs-fixer": "^3.89.1",
3536
"maglnet/composer-require-checker": "^4.7.1",
3637
"phpunit/phpunit": "^10.5.46",
3738
"rector/rector": "^2.0.16",
@@ -41,12 +42,12 @@
4142
},
4243
"autoload": {
4344
"psr-4": {
44-
"Yiisoft\\_____\\": "src/"
45+
"Yiisoft\\CodeStyle\\": "src/"
4546
}
4647
},
4748
"autoload-dev": {
4849
"psr-4": {
49-
"Yiisoft\\_____\\Tests\\": "tests/"
50+
"Yiisoft\\CodeStyle\\Tests\\": "tests/"
5051
}
5152
},
5253
"config": {

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</php>
2020

2121
<testsuites>
22-
<testsuite name="Yii _____ tests">
22+
<testsuite name="Yii Code Style tests">
2323
<directory>./tests</directory>
2424
</testsuite>
2525
</testsuites>

src/.gitkeep

Whitespace-only changes.

src/ConfigBuilder.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yiisoft\CodeStyle;
6+
7+
use PhpCsFixer\Config;
8+
use Yiisoft\CodeStyle\Sets\YiisoftCoreRiskySet;
9+
use Yiisoft\CodeStyle\Sets\YiisoftCoreSet;
10+
11+
final class ConfigBuilder
12+
{
13+
public static function build(): Config
14+
{
15+
$config = (new Config());
16+
$config->registerCustomRuleSets([
17+
new YiisoftCoreSet(),
18+
new YiisoftCoreRiskySet(),
19+
]);
20+
21+
return $config;
22+
}
23+
}

src/Sets/YiisoftCoreRiskySet.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yiisoft\CodeStyle\Sets;
6+
7+
use PhpCsFixer\RuleSet\RuleSetDefinitionInterface;
8+
9+
final class YiisoftCoreRiskySet implements RuleSetDefinitionInterface
10+
{
11+
public function getName(): string
12+
{
13+
return '@Yiisoft/Core:risky';
14+
}
15+
16+
public function getRules(): array
17+
{
18+
return [
19+
'declare_strict_types' => true,
20+
'native_function_invocation' => true,
21+
'native_constant_invocation' => true,
22+
];
23+
}
24+
25+
public function getDescription(): string
26+
{
27+
return 'Rules recommended by ``Yiisoft`` team. Extends ``@PER-CS``';
28+
}
29+
30+
public function isRisky(): bool
31+
{
32+
return true;
33+
}
34+
}

src/Sets/YiisoftCoreSet.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yiisoft\CodeStyle\Sets;
6+
7+
use PhpCsFixer\RuleSet\RuleSetDefinitionInterface;
8+
9+
final class YiisoftCoreSet implements RuleSetDefinitionInterface
10+
{
11+
public function getName(): string
12+
{
13+
return '@Yiisoft/Core';
14+
}
15+
16+
public function getRules(): array
17+
{
18+
return [
19+
'@PER-CS' => true,
20+
'no_unused_imports' => true,
21+
'no_extra_blank_lines' => [
22+
'tokens' => [
23+
'curly_brace_block',
24+
'extra',
25+
],
26+
],
27+
'ordered_class_elements' => true,
28+
'class_attributes_separation' => ['elements' => ['method' => 'one']],
29+
'fully_qualified_strict_types' => [
30+
'import_symbols' => true,
31+
],
32+
'global_namespace_import' => [
33+
'import_classes' => true,
34+
'import_constants' => true,
35+
'import_functions' => true,
36+
],
37+
];
38+
}
39+
40+
public function getDescription(): string
41+
{
42+
return 'Rules recommended by ``Yiisoft`` team. Extends ``@PER-CS``.';
43+
}
44+
45+
public function isRisky(): bool
46+
{
47+
return false;
48+
}
49+
}

tests/.gitkeep

Whitespace-only changes.

tests/ConfigBuilderTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yiisoft\CodeStyle\Tests;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Yiisoft\CodeStyle\ConfigBuilder;
9+
use Yiisoft\CodeStyle\Sets\YiisoftCoreRiskySet;
10+
use Yiisoft\CodeStyle\Sets\YiisoftCoreSet;
11+
12+
final class ConfigBuilderTest extends TestCase
13+
{
14+
public function testBuild(): void
15+
{
16+
$config = ConfigBuilder::build();
17+
$customRuleSets = $config->getCustomRuleSets();
18+
19+
$this->assertCount(2, $customRuleSets);
20+
21+
$this->assertInstanceOf(YiisoftCoreSet::class, $customRuleSets[0]);
22+
$this->assertNotEmpty($customRuleSets[0]->getRules());
23+
$this->assertNotEmpty($customRuleSets[0]->getDescription());
24+
$this->assertFalse($customRuleSets[0]->isRisky());
25+
26+
$this->assertInstanceOf(YiisoftCoreRiskySet::class, $customRuleSets[1]);
27+
$this->assertNotEmpty($customRuleSets[1]->getRules());
28+
$this->assertNotEmpty($customRuleSets[1]->getDescription());
29+
$this->assertTrue($customRuleSets[1]->isRisky());
30+
}
31+
}

0 commit comments

Comments
 (0)