|
| 1 | +<?php // lint >= 8.0 |
| 2 | + |
| 3 | +declare(strict_types = 1); |
| 4 | + |
| 5 | +namespace IssueBotArrayRegression; |
| 6 | + |
| 7 | +use function array_unique; |
| 8 | +use function array_values; |
| 9 | +use function PHPStan\Testing\assertType; |
| 10 | + |
| 11 | +class EvaluateCommand |
| 12 | +{ |
| 13 | + protected function execute(): int |
| 14 | + { |
| 15 | + $issueCache = new IssueCache(); |
| 16 | + |
| 17 | + foreach ($issueCache->getIssues() as $issue) { |
| 18 | + $deduplicatedExamples = []; |
| 19 | + foreach ($issue->getComments() as $comment) { |
| 20 | + foreach ($comment->getPlaygroundExamples() as $example) { |
| 21 | + if (isset($deduplicatedExamples[$example->getHash()])) { |
| 22 | + assertType('array{example: IssueBotArrayRegression\PlaygroundExample, users: non-empty-list<string>}', $deduplicatedExamples[$example->getHash()]); |
| 23 | + assertType('non-empty-list<string>', $deduplicatedExamples[$example->getHash()]['users']); |
| 24 | + $deduplicatedExamples[$example->getHash()]['users'][] = $comment->getAuthor(); |
| 25 | + $deduplicatedExamples[$example->getHash()]['users'] = array_values(array_unique($deduplicatedExamples[$example->getHash()]['users'])); |
| 26 | + continue; |
| 27 | + } |
| 28 | + $deduplicatedExamples[$example->getHash()] = [ |
| 29 | + 'example' => $example, |
| 30 | + 'users' => [$comment->getAuthor()], |
| 31 | + ]; |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + assertType('array<string, array{example: IssueBotArrayRegression\PlaygroundExample, users: non-empty-list<string>}>', $deduplicatedExamples); |
| 36 | + } |
| 37 | + |
| 38 | + return 1; |
| 39 | + } |
| 40 | + |
| 41 | +} |
| 42 | + |
| 43 | +class Comment |
| 44 | +{ |
| 45 | + |
| 46 | + /** |
| 47 | + * @param non-empty-list<PlaygroundExample> $playgroundExamples |
| 48 | + */ |
| 49 | + public function __construct( |
| 50 | + private string $author, |
| 51 | + private string $text, |
| 52 | + private array $playgroundExamples, |
| 53 | + ) |
| 54 | + { |
| 55 | + } |
| 56 | + |
| 57 | + public function getAuthor(): string |
| 58 | + { |
| 59 | + return $this->author; |
| 60 | + } |
| 61 | + |
| 62 | + public function getText(): string |
| 63 | + { |
| 64 | + return $this->text; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @return non-empty-list<PlaygroundExample> |
| 69 | + */ |
| 70 | + public function getPlaygroundExamples(): array |
| 71 | + { |
| 72 | + return $this->playgroundExamples; |
| 73 | + } |
| 74 | + |
| 75 | +} |
| 76 | + |
| 77 | + |
| 78 | +class Issue |
| 79 | +{ |
| 80 | + |
| 81 | + /** |
| 82 | + * @param Comment[] $comments |
| 83 | + */ |
| 84 | + public function __construct(private int $number, private array $comments) |
| 85 | + { |
| 86 | + } |
| 87 | + |
| 88 | + public function getNumber(): int |
| 89 | + { |
| 90 | + return $this->number; |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * @return Comment[] |
| 95 | + */ |
| 96 | + public function getComments(): array |
| 97 | + { |
| 98 | + return $this->comments; |
| 99 | + } |
| 100 | + |
| 101 | +} |
| 102 | + |
| 103 | +class IssueCache |
| 104 | +{ |
| 105 | + |
| 106 | + public function __construct() |
| 107 | + { |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * @return array<int, Issue> |
| 112 | + */ |
| 113 | + public function getIssues(): array |
| 114 | + { |
| 115 | + return []; |
| 116 | + } |
| 117 | + |
| 118 | +} |
| 119 | + |
| 120 | +class PlaygroundExample |
| 121 | +{ |
| 122 | + |
| 123 | + public function __construct( |
| 124 | + private string $url, |
| 125 | + private string $hash, |
| 126 | + ) |
| 127 | + { |
| 128 | + } |
| 129 | + |
| 130 | + public function getUrl(): string |
| 131 | + { |
| 132 | + return $this->url; |
| 133 | + } |
| 134 | + |
| 135 | + public function getHash(): string |
| 136 | + { |
| 137 | + return $this->hash; |
| 138 | + } |
| 139 | + |
| 140 | +} |
0 commit comments