Skip to content

Commit fa71ffa

Browse files
authored
[Optimization] Update stat analyse level (#42)
* check unused code * move level * fix some errors * fix some errors * remove trait "InteractsWithResponse" * up * up * fix test * Add normalizer * use denormalizer in gitlab ci client * Add env var has different type exception * fix comments * use normalizer in bitbucket client * use normalizer in bitbucket client * up comments * fix issue * fix test * fix issue * add EvaluatorCrashedException * check * add exception to contract * Revert "use normalizer in bitbucket client" This reverts commit 32021c1. * Revert "use normalizer in bitbucket client" This reverts commit 165cc90. * Revert "use denormalizer in gitlab ci client" This reverts commit d1c1ed4 * Revert "Add normalizer" This reverts commit edcb1ed. * add test * add gitlab mr schema * refactor rule constructor to instantiator * add exception * clean * clean * fix some issues * add exception * check notifications config fields * fix issue * fix issue * fix issue * Add bitbucket pr schema * fix issue * fix issue * Add context logger * fix tests * fix tests * update str * Implements JsonSerializable for better logging * log event id * up lang * fix issue * fix issues * fix issue * fix issue * fix issue * rename method * metrics for logs * add test * add tests * add test * add test * add comments * remove method * add tests * refactor context logger * Move rule collection to domain * Move linterFactory && runnerFactory to Application * ref app factory * up context logger * update changelog and version * fix lint * fix * actualize "make env" * fix lint * update context logger * update changelog * add test * set ConditionEvaluatorNotFound as final * add test for ClientGuzzleWrapper
1 parent e0aceb0 commit fa71ffa

File tree

145 files changed

+2502
-726
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+2502
-726
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ This file contains changelogs.
44

55
[View all Releases](https://github.com/ArtARTs36/php-merge-request-linter/releases)
66

7+
## [v0.12.0 (2023-05-21)](https://github.com/ArtARTs36/php-merge-request-linter/compare/0.11.1..0.12.0)
8+
9+
### Added
10+
* Add logs for HTTP Client
11+
* Validate BitBucket PR data
12+
13+
## Changed
14+
* Update PHPStan level to 9
15+
16+
[💾 Assets](https://github.com/ArtARTs36/php-merge-request-linter/releases/tag/0.12.0)
17+
18+
-----------------------------------------------------------------
19+
720
## [v0.11.1 (2023-03-17)](https://github.com/ArtARTs36/php-merge-request-linter/compare/0.11.0..0.11.1)
821

922
### Added

Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FROM php:8.1
22

3+
RUN apt update && apt install -y zip
4+
35
COPY --from=composer:2.4.0 /usr/bin/composer /usr/bin/composer
46

57
COPY ./ /app/

Makefile

+13-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ endif
66
.PHONY: docs
77

88
env:
9-
echo "MR_LINTER_GITHUB_HTTP_TOKEN=token\nMR_LINTER_GITLAB_HTTP_TOKEN=token" > .env
9+
echo "MR_LINTER_GITHUB_HTTP_TOKEN=token\nMR_LINTER_GITLAB_HTTP_TOKEN=token\n" > .env
10+
echo "E2E_MR_LINTER_GITHUB_HTTP_TOKEN=token\nE2E_MR_LINTER_GITLAB_HTTP_TOKEN=token" >> .env
11+
echo "E2E_MR_LINTER_BITBUCKET_APP_USER=token\nE2E_MR_LINTER_BITBUCKET_APP_PASSWORD=token\n" >> .env
1012

1113
# usage as `make try MR_ID=1`
1214
try:
@@ -97,12 +99,22 @@ lint-docker: docker-build
9799
--entrypoint "composer" \
98100
artarts36/merge-request-linter "lint"
99101

102+
lint-fix-docker: docker-build
103+
docker run \
104+
--volume ./:/app/ \
105+
--env-file .env \
106+
--entrypoint "composer" \
107+
artarts36/merge-request-linter "lint-fix"
108+
100109
stat-analyse-docker: docker-build
101110
docker run \
102111
--env-file .env \
103112
--entrypoint "composer" \
104113
artarts36/merge-request-linter "stat-analyse"
105114

115+
test-e2e:
116+
composer test-e2e
117+
106118
test-e2e-docker: docker-build
107119
docker run \
108120
--env-file .env \

composer.json

+12-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
{
77
"url": "https://github.com/ArtARTs36/docs-retriever",
88
"type": "git"
9+
},
10+
{
11+
"url": "https://github.com/ArtARTs36/php-context-logger",
12+
"type": "git"
913
}
1014
],
1115
"require": {
1216
"php": "^8.1",
13-
"artarts36/str": "^2.2.1",
17+
"artarts36/str": "^2.3.0",
1418
"symfony/console": "^4.0 | ^5.0 | ^6.0",
1519
"guzzlehttp/psr7": "^2",
1620
"artarts36/local-file-system": "^0.1.2",
@@ -27,13 +31,14 @@
2731
"guzzlehttp/promises": "^1.5",
2832
"league/commonmark": "^2.3",
2933
"psr/clock": "^1.0",
30-
"twig/twig": "^3.5"
34+
"twig/twig": "^3.5",
35+
"artarts36/context-logger": "^0.1.0"
3136
},
3237
"require-dev": {
3338
"phpunit/phpunit": "^9.5",
3439
"jetbrains/phpstorm-attributes": "^1.0",
3540
"artarts36/php-cs-fixer-good-fixers": "^0.1.2",
36-
"phpstan/phpstan": "^1.2",
41+
"phpstan/phpstan": "^1.10",
3742
"qossmic/deptrac-shim": "^1.0",
3843
"artarts36/array-file-system": "^0.1.0",
3944
"artarts36/docs-retriever": "dev-dev"
@@ -63,14 +68,17 @@
6368
"lint": [
6469
"php-cs-fixer fix --dry-run --verbose --diff --ansi"
6570
],
71+
"lint-fix": [
72+
"php-cs-fixer fix --verbose --diff --ansi"
73+
],
6674
"test": [
6775
"./vendor/bin/phpunit -v --coverage-text --colors=always --configuration phpunit.xml"
6876
],
6977
"test-coverage": [
7078
"XDEBUG_MODE=coverage ./vendor/bin/phpunit -v --coverage-text --colors=always --configuration phpunit.xml --coverage-clover ./coverage.xml"
7179
],
7280
"stat-analyse": [
73-
"./vendor/bin/phpstan analyse -l 8 src --memory-limit 2G"
81+
"./vendor/bin/phpstan analyse src --memory-limit 2G"
7482
],
7583
"mr-lint": [
7684
"./bin/mr-linter lint"

composer.lock

+64-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/Builder/ConfigJsonSchema/RuleSchemaGenerator.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
use ArtARTs36\MergeRequestLinter\Application\Rule\Rules\CustomRule;
66
use ArtARTs36\MergeRequestLinter\Application\Rule\Rules\DefaultRules;
7-
use ArtARTs36\MergeRequestLinter\Shared\Reflector\Reflector;
87
use ArtARTs36\MergeRequestLinter\DocBuilder\ConfigJsonSchema\Schema\JsonSchema;
9-
use ArtARTs36\MergeRequestLinter\Infrastructure\Contracts\Rule\RuleConstructorFinder;
10-
use ArtARTs36\MergeRequestLinter\Infrastructure\Rule\Constructor\ConstructorFinder;
8+
use ArtARTs36\MergeRequestLinter\Shared\Contracts\Instantiator\InstantiatorFinder;
9+
use ArtARTs36\MergeRequestLinter\Shared\Instantiator\Finder;
10+
use ArtARTs36\MergeRequestLinter\Shared\Reflector\Reflector;
1111
use ArtARTs36\Str\Facade\Str;
1212

1313
class RuleSchemaGenerator
@@ -21,7 +21,7 @@ class RuleSchemaGenerator
2121
];
2222

2323
public function __construct(
24-
private RuleConstructorFinder $constructorFinder = new ConstructorFinder(),
24+
private InstantiatorFinder $constructorFinder = new Finder(),
2525
) {
2626
//
2727
}
@@ -66,10 +66,12 @@ public function generate(JsonSchema $jsonSchema): array
6666
}
6767

6868
if ($paramType->isGeneric()) {
69-
if ($paramType->isGenericOfObject()) {
69+
$generic = $paramType->getObjectGeneric();
70+
71+
if ($generic !== null) {
7072
$genericProps = [];
7173

72-
foreach (Reflector::mapProperties($paramType->generic) as $property) {
74+
foreach (Reflector::mapProperties($generic) as $property) {
7375
$genericProps[$property->name] = [
7476
'type' => JsonType::to($property->type->class ?? $property->type->name->value),
7577
];

docs/Builder/RulesPageBuilder.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
use ArtARTs36\MergeRequestLinter\Application\Rule\Rules\CustomRule;
66
use ArtARTs36\MergeRequestLinter\Application\Rule\Rules\DefaultRules;
77
use ArtARTs36\MergeRequestLinter\DocBuilder\ConfigJsonSchema\JsonType;
8-
use ArtARTs36\MergeRequestLinter\Infrastructure\Contracts\Rule\RuleConstructorFinder;
9-
use ArtARTs36\MergeRequestLinter\Infrastructure\Rule\Constructor\ConstructorFinder;
108
use ArtARTs36\MergeRequestLinter\Infrastructure\Text\Renderer\TwigRenderer;
9+
use ArtARTs36\MergeRequestLinter\Shared\Contracts\Instantiator\InstantiatorFinder;
1110
use ArtARTs36\MergeRequestLinter\Shared\DataStructure\ArrayMap;
11+
use ArtARTs36\MergeRequestLinter\Shared\Instantiator\Finder;
1212
use ArtARTs36\MergeRequestLinter\Shared\Reflector\ClassSummary;
1313

1414
class RulesPageBuilder
@@ -18,7 +18,7 @@ class RulesPageBuilder
1818
protected string $dir = __DIR__ . '/../../src/Application/Rule/Rules';
1919

2020
public function __construct(
21-
private RuleConstructorFinder $ruleConstructorFinder = new ConstructorFinder(),
21+
private InstantiatorFinder $ruleConstructorFinder = new Finder(),
2222
) {
2323
//
2424
}

phpstan.neon

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 9
3+
featureToggles:
4+
bleedingEdge: true

src/Application/Condition/Evaluators/Composite/AllEvaluator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AllEvaluator extends CompositeEvaluator
1515
public function evaluate(EvaluatingSubject $subject): bool
1616
{
1717
foreach ($subject->interface(Collection::class) as $index => $value) {
18-
$name = sprintf('%s[%s]', $subject->name(), (string) $index);
18+
$name = sprintf('%s[%s]', $subject->name(), '' . $index);
1919

2020
foreach ($this->value as $evaluator) {
2121
if (! $evaluator->evaluate($this->subjectFactory->createForValue($name, $value))) {

src/Application/Condition/Evaluators/Composite/AnyEvaluator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AnyEvaluator extends CompositeEvaluator
1515
public function evaluate(EvaluatingSubject $subject): bool
1616
{
1717
foreach ($subject->interface(Collection::class) as $index => $value) {
18-
$name = sprintf('%s[%s]', $subject->name(), (string) $index);
18+
$name = sprintf('%s[%s]', $subject->name(), '' . $index);
1919

2020
foreach ($this->value as $evaluator) {
2121
if ($evaluator->evaluate($this->subjectFactory->createForValue($name, $value))) {

src/Application/Condition/Evaluators/Strings/MatchEvaluator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace ArtARTs36\MergeRequestLinter\Application\Condition\Evaluators\Strings;
44

5-
use ArtARTs36\MergeRequestLinter\Application\Condition\Exceptions\InvalidEvaluatorValueException;
5+
use ArtARTs36\MergeRequestLinter\Application\Condition\Exceptions\EvaluatorCrashedException;
66
use ArtARTs36\MergeRequestLinter\Domain\Condition\EvaluatingSubject;
77
use ArtARTs36\Str\Exceptions\InvalidRegexException;
88
use ArtARTs36\Str\Facade\Str;
@@ -19,7 +19,7 @@ protected function doEvaluate(EvaluatingSubject $subject): bool
1919
try {
2020
return ! empty(Str::match($subject->interface(\ArtARTs36\Str\Str::class), $this->value));
2121
} catch (InvalidRegexException $e) {
22-
throw new InvalidEvaluatorValueException($e->getMessage(), previous: $e);
22+
throw new EvaluatorCrashedException($e->getMessage(), previous: $e);
2323
}
2424
}
2525
}

src/Application/Condition/Exceptions/InvalidEvaluatorValueException.php renamed to src/Application/Condition/Exceptions/EvaluatorCrashedException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use ArtARTs36\MergeRequestLinter\Shared\Exceptions\MergeRequestLinterException;
66

7-
class InvalidEvaluatorValueException extends MergeRequestLinterException
7+
final class EvaluatorCrashedException extends MergeRequestLinterException
88
{
99
//
1010
}

src/Application/Linter/Linter.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace ArtARTs36\MergeRequestLinter\Application\Linter;
44

5-
use ArtARTs36\MergeRequestLinter\Application\Condition\Exceptions\InvalidEvaluatorValueException;
5+
use ArtARTs36\MergeRequestLinter\Application\Condition\Exceptions\EvaluatorCrashedException;
66
use ArtARTs36\MergeRequestLinter\Domain\Linter\LintFinishedEvent;
77
use ArtARTs36\MergeRequestLinter\Domain\Linter\LintResult;
88
use ArtARTs36\MergeRequestLinter\Domain\Linter\LintStartedEvent;
@@ -24,9 +24,9 @@
2424
class Linter implements \ArtARTs36\MergeRequestLinter\Domain\Linter\Linter
2525
{
2626
public function __construct(
27-
protected Rules $rules,
27+
protected Rules $rules,
2828
protected EventDispatcherInterface $events,
29-
private readonly MetricManager $metrics,
29+
private readonly MetricManager $metrics,
3030
) {
3131
//
3232
}
@@ -59,7 +59,7 @@ public function run(MergeRequest $request): LintResult
5959
} else {
6060
$this->events->dispatch(new RuleWasFailedEvent($rule->getName()));
6161
}
62-
} catch (InvalidEvaluatorValueException $e) {
62+
} catch (EvaluatorCrashedException $e) {
6363
$notes[] = new LintNote(sprintf('[%s] Invalid condition value: %s', $rule->getName(), $e->getMessage()));
6464

6565
$this->events->dispatch(new RuleFatalEndedEvent($rule->getName()));

src/Infrastructure/Linter/LinterFactory.php renamed to src/Application/Linter/LinterFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace ArtARTs36\MergeRequestLinter\Infrastructure\Linter;
3+
namespace ArtARTs36\MergeRequestLinter\Application\Linter;
44

55
use ArtARTs36\MergeRequestLinter\Domain\Linter\Linter;
66
use ArtARTs36\MergeRequestLinter\Domain\Rule\Rules;

0 commit comments

Comments
 (0)