Skip to content

Commit fd42e91

Browse files
author
kaizen-ci
committed
[RuleDocGenerator] Split contracts package for production code (#3066)
1 parent 8504302 commit fd42e91

20 files changed

+457
-1
lines changed

Diff for: .gitattributes

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.gitattributes export-ignore
2+
.gitignore export-ignore
3+
phpunit.xml export-ignore
4+
*.md export-ignore
5+
tests export-ignore
6+
packages/composer-json-object/tests export-ignore
7+
packages/init/tests export-ignore
8+
packages/merge/tests export-ignore
9+
packages/release/tests export-ignore
10+
packages/split/tests export-ignore
11+
packages/testing/tests export-ignore

Diff for: .github/FUNDING.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
github: tomasvotruba
3+
custom: https://www.paypal.me/rectorphp

Diff for: .github/workflows/repo-lockdown.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# see https://github.com/dear-github/dear-github/issues/84#issuecomment-696475017
2+
name: 'Repo Lockdown'
3+
4+
on:
5+
pull_request: null
6+
7+
jobs:
8+
lockdown:
9+
runs-on: ubuntu-latest
10+
steps:
11+
-
12+
# see https://github.com/marketplace/actions/repo-lockdown
13+
uses: dessant/repo-lockdown@v2
14+
with:
15+
github-token: ${{ secrets.ACCESS_TOKEN }}
16+
pr-comment: |
17+
Hi, thank you for your contribution.
18+
19+
Unfortunately, this repository is read-only. It's a split from our main monorepo repository.
20+
21+
We'd like to kindly ask you to move the contribution there - https://github.com/symplify/symplify.
22+
23+
We'll check it, review it and give you feed back right way.
24+
25+
Thank you

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor
2+
composer.lock

Diff for: LICENSE

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
The MIT License
2+
---------------
3+
4+
Copyright (c) 2016 Tomas Votruba (https://tomasvotruba.com)
5+
6+
Permission is hereby granted, free of charge, to any person
7+
obtaining a copy of this software and associated documentation
8+
files (the "Software"), to deal in the Software without
9+
restriction, including without limitation the rights to use,
10+
copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the
12+
Software is furnished to do so, subject to the following
13+
conditions:
14+
15+
The above copyright notice and this permission notice shall be
16+
included in all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25+
OTHER DEALINGS IN THE SOFTWARE.

Diff for: README.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
init
1+
# Rule Doc Generator Contracts
2+
3+
Contracts for Rule Doc Generator. Useful for production code with minimum dependencies.
4+
5+
[![Downloads total](https://img.shields.io/packagist/dt/symplify/rule-doc-generator-contracts.svg?style=flat-square)](https://packagist.org/packages/symplify/rule-doc-generator-contracts/stats)
6+
7+
## Install
8+
9+
```bash
10+
composer require symplify/rule-doc-generator-contracts
11+
```
12+
13+
<br>
14+
15+
## Report Issues
16+
17+
In case you are experiencing a bug or want to request a new feature head over to the [Symplify monorepo issue tracker](https://github.com/symplify/symplify/issues)
18+
19+
## Contribute
20+
21+
The sources of this package are contained in the Symplify monorepo. We welcome contributions for this package on [symplify/symplify](https://github.com/symplify/symplify).

Diff for: composer.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "symplify/rule-doc-generator-contracts",
3+
"description": "Contracts for production code of RuleDocGenerator",
4+
"license": "MIT",
5+
"bin": [
6+
"bin/rule-doc-generator"
7+
],
8+
"require": {
9+
"php": ">=7.3"
10+
},
11+
"autoload": {
12+
"psr-4": {
13+
"Symplify\\RuleDocGenerator\\": "src"
14+
}
15+
},
16+
"extra": {
17+
"branch-alias": {
18+
"dev-main": "9.3-dev"
19+
}
20+
},
21+
"minimum-stability": "dev",
22+
"prefer-stable": true
23+
}

Diff for: src/Contract/Category/CategoryInfererInterface.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\RuleDocGenerator\Contract\Category;
6+
7+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
8+
9+
interface CategoryInfererInterface
10+
{
11+
public function infer(RuleDefinition $ruleDefinition): ?string;
12+
}

Diff for: src/Contract/CodeSampleInterface.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\RuleDocGenerator\Contract;
6+
7+
interface CodeSampleInterface
8+
{
9+
public function getGoodCode(): string;
10+
11+
public function getBadCode(): string;
12+
}

Diff for: src/Contract/ConfigurableRuleInterface.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\RuleDocGenerator\Contract;
6+
7+
interface ConfigurableRuleInterface
8+
{
9+
}

Diff for: src/Contract/DocumentedRuleInterface.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\RuleDocGenerator\Contract;
6+
7+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
8+
9+
interface DocumentedRuleInterface
10+
{
11+
public function getRuleDefinition(): RuleDefinition;
12+
}

Diff for: src/Contract/RuleCodeSamplePrinterInterface.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\RuleDocGenerator\Contract;
6+
7+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
8+
9+
interface RuleCodeSamplePrinterInterface
10+
{
11+
public function isMatch(string $class): bool;
12+
13+
/**
14+
* @return string[]
15+
*/
16+
public function print(CodeSampleInterface $codeSample, RuleDefinition $ruleDefinition): array;
17+
}

Diff for: src/Exception/PoorDocumentationException.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\RuleDocGenerator\Exception;
6+
7+
use Exception;
8+
9+
final class PoorDocumentationException extends Exception
10+
{
11+
}

Diff for: src/Exception/ShouldNotHappenException.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\RuleDocGenerator\Exception;
6+
7+
use Exception;
8+
9+
final class ShouldNotHappenException extends Exception
10+
{
11+
12+
}

Diff for: src/ValueObject/AbstractCodeSample.php

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\RuleDocGenerator\ValueObject;
6+
7+
use Symplify\RuleDocGenerator\Contract\CodeSampleInterface;
8+
use Symplify\SymplifyKernel\Exception\ShouldNotHappenException;
9+
10+
abstract class AbstractCodeSample implements CodeSampleInterface
11+
{
12+
/**
13+
* @var string
14+
*/
15+
private $goodCode;
16+
17+
/**
18+
* @var string
19+
*/
20+
private $badCode;
21+
22+
public function __construct(string $badCode, string $goodCode)
23+
{
24+
$badCode = trim($badCode);
25+
$goodCode = trim($goodCode);
26+
27+
if ($badCode === '') {
28+
throw new ShouldNotHappenException('Bad sample good code cannot be empty');
29+
}
30+
31+
if ($goodCode === $badCode) {
32+
$errorMessage = sprintf('Good and bad code cannot be identical: "%s"', $goodCode);
33+
throw new ShouldNotHappenException($errorMessage);
34+
}
35+
36+
$this->goodCode = $goodCode;
37+
$this->badCode = $badCode;
38+
}
39+
40+
public function getGoodCode(): string
41+
{
42+
return $this->goodCode;
43+
}
44+
45+
public function getBadCode(): string
46+
{
47+
return $this->badCode;
48+
}
49+
}

Diff for: src/ValueObject/CodeSample/CodeSample.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\RuleDocGenerator\ValueObject\CodeSample;
6+
7+
use Symplify\RuleDocGenerator\ValueObject\AbstractCodeSample;
8+
9+
final class CodeSample extends AbstractCodeSample
10+
{
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\RuleDocGenerator\ValueObject\CodeSample;
6+
7+
use Symplify\RuleDocGenerator\ValueObject\AbstractCodeSample;
8+
9+
final class ComposerJsonAwareCodeSample extends AbstractCodeSample
10+
{
11+
/**
12+
* @var string
13+
*/
14+
private $composerJson;
15+
16+
public function __construct(string $badCode, string $goodCode, string $composerJson)
17+
{
18+
parent::__construct($badCode, $goodCode);
19+
20+
$this->composerJson = $composerJson;
21+
}
22+
23+
public function getComposerJson(): string
24+
{
25+
return $this->composerJson;
26+
}
27+
}

Diff for: src/ValueObject/CodeSample/ConfiguredCodeSample.php

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\RuleDocGenerator\ValueObject\CodeSample;
6+
7+
use Rector\Core\Exception\Configuration\InvalidConfigurationException;
8+
use Symplify\RuleDocGenerator\Contract\CodeSampleInterface;
9+
use Symplify\RuleDocGenerator\ValueObject\AbstractCodeSample;
10+
11+
final class ConfiguredCodeSample extends AbstractCodeSample implements CodeSampleInterface
12+
{
13+
/**
14+
* @var array<string, mixed>
15+
*/
16+
private $configuration = [];
17+
18+
/**
19+
* @param array<string, mixed> $configuration
20+
*/
21+
public function __construct(string $badCode, string $goodCode, array $configuration)
22+
{
23+
if ($configuration === []) {
24+
$message = sprintf('Configuration cannot be empty. Look for "%s"', $badCode);
25+
throw new InvalidConfigurationException($message);
26+
}
27+
28+
$this->configuration = $configuration;
29+
30+
parent::__construct($badCode, $goodCode);
31+
}
32+
33+
/**
34+
* @return array<string, mixed>
35+
*/
36+
public function getConfiguration(): array
37+
{
38+
return $this->configuration;
39+
}
40+
}

Diff for: src/ValueObject/CodeSample/ExtraFileCodeSample.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\RuleDocGenerator\ValueObject\CodeSample;
6+
7+
use Symplify\RuleDocGenerator\ValueObject\AbstractCodeSample;
8+
9+
final class ExtraFileCodeSample extends AbstractCodeSample
10+
{
11+
/**
12+
* @var string
13+
*/
14+
private $extraFile;
15+
16+
public function __construct(string $badCode, string $goodCode, string $extraFile)
17+
{
18+
parent::__construct($badCode, $goodCode);
19+
20+
$this->extraFile = $extraFile;
21+
}
22+
23+
public function getExtraFile(): string
24+
{
25+
return $this->extraFile;
26+
}
27+
}

0 commit comments

Comments
 (0)