Skip to content

Commit 2a07a55

Browse files
committed
fix sa errors
1 parent 3a6c562 commit 2a07a55

File tree

7 files changed

+40
-13
lines changed

7 files changed

+40
-13
lines changed

phpstan.dist.neon

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ parameters:
77
containerXmlPath: var/cache/test/App_KernelTestDebugContainer.xml
88
doctrine:
99
ormRepositoryClass: App\Repository\AbstractRepository
10-
objectManagerLoader: tests/phpstan-bootstrap.php
10+
objectManagerLoader: tests/phpstan-bootstrap.php
11+
ignoreErrors:
12+
-
13+
message: '#Variable \$[a-zA-Z0-9]+ might not be defined\.#'
14+
# identifier: variable.undefined // Available in phpstan 1.11.0
15+
path: src/GraphQLRequest/*

src/Factory/Model/GitHubPullRequestFactory.php

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ protected function getDefaults(): array
5858
];
5959
}
6060

61+
/** @param GitHubUrlData|Proxy<GitHubUrlData> $urlData */
6162
public function fromUrlData(GitHubUrlData|Proxy $urlData, string $title = '[ci] run sa tools'): self
6263
{
6364
return $this->addState([

src/Factory/Model/GitHubUrlDataFactory.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
*/
4343
class GitHubUrlDataFactory extends ModelFactory
4444
{
45+
/** @return array<string, string|int|TypeEnum> */
4546
#[\Override]
4647
protected function getDefaults(): array
4748
{
@@ -53,19 +54,20 @@ protected function getDefaults(): array
5354
'uri' => sprintf('https://github.com/%s/%s/%s/%s',
5455
$owner,
5556
$repository,
56-
TypeEnum::PULL_REQUEST === $type ? 'pulls' : 'issues',
57+
TypeEnum::PULL_REQUEST === $type ? 'pulls' : 'issues', // @phpstan-ignore-line
5758
$id
5859
),
5960
];
6061
}
6162

6263
public function asIssue(): self
6364
{
65+
/** @var string $uri */
6466
$uri = $this->getDefaults()['uri'];
6567

6668
return $this->addState([
6769
'type' => TypeEnum::ISSUE,
68-
'uri' => str_replace(TypeEnum::PULL_REQUEST->value, TypeEnum::ISSUE->value, (string) $uri),
70+
'uri' => str_replace(TypeEnum::PULL_REQUEST->value, TypeEnum::ISSUE->value, $uri),
6971
]);
7072
}
7173

src/Factory/TaskFactory.php

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function withName(string $name): self
6262
return $this->addState(['name' => $name]);
6363
}
6464

65+
/** @param TodoList|Proxy<TodoList> $todoList */
6566
public function forTodoList(TodoList|Proxy $todoList): self
6667
{
6768
return $this->addState(['todoList' => $todoList]);

src/Factory/TodoListFactory.php

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Factory;
44

55
use App\Entity\TodoList;
6+
use App\Entity\User;
67
use App\Repository\TodoListRepository;
78
use Zenstruck\Foundry\ModelFactory;
89
use Zenstruck\Foundry\Proxy;
@@ -54,6 +55,12 @@ protected function getDefaults(): array
5455
];
5556
}
5657

58+
/** @param User|Proxy<User> $user */
59+
public function withOwner(User|Proxy $user): self
60+
{
61+
return $this->addState(['owner' => $user]);
62+
}
63+
5764
#[\Override]
5865
protected static function getClass(): string
5966
{

src/Service/TaskService.php

+19-7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public function __construct(
3232
}
3333

3434
/**
35+
* @param GitHubUrlData|GitHubUrlData[] $urlData
36+
*
3537
* @return array<int, GitHubIssue|GitHubPullRequest>
3638
*
3739
* @throws HttpClientException
@@ -78,9 +80,9 @@ public function getGitHubDataFromUrl(GitHubUrlData|array $urlData, string $owner
7880
return $match;
7981
});
8082

81-
if (null === $result) {
82-
continue;
83-
}
83+
// if (null === $result) {
84+
// continue;
85+
// }
8486

8587
$objects[] = new GitHubPullRequest(
8688
uri: $result->uri,
@@ -99,9 +101,9 @@ public function getGitHubDataFromUrl(GitHubUrlData|array $urlData, string $owner
99101
return $match;
100102
});
101103

102-
if (null === $result) {
103-
continue;
104-
}
104+
// if (null === $result) {
105+
// continue;
106+
// }
105107

106108
$objects[] = new GitHubIssue(
107109
uri: $result->uri,
@@ -161,13 +163,23 @@ private function createQueryContent(array $urls): string
161163
]);
162164
}
163165

166+
/**
167+
* @param string $templatePath The absolute path to the template with filename and extension
168+
* @param array<string, mixed> $parameters array of variables used in the template
169+
* where the "key" is the variable name and the "value" is the value of the variable
170+
* in the template
171+
*/
164172
private function getTemplate(string $templatePath, array $parameters): string
165173
{
166174
ob_start();
167175
extract($parameters, \EXTR_SKIP);
168176
include $templatePath;
169177

170-
return ob_get_clean();
178+
if (false === $template = ob_get_clean()) {
179+
throw new \RuntimeException('Ooops! somethign went wrong trying to generate the template.');
180+
}
181+
182+
return $template;
171183
}
172184

173185
/**

tests/Functional/Service/TaskServiceTest.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ final class TaskServiceTest extends FunctionalTestCase
2020
{
2121
private const string ISSUE_FRAGMENT = 'fragment issue on Issue';
2222
private const string PULL_FRAGMENT = 'fragment pr on PullRequest';
23-
24-
private Security|MockObject $mockSecurity;
25-
private EncryptorService|MockObject $mockEncryptor;
23+
private MockObject&Security $mockSecurity;
24+
private EncryptorService&MockObject $mockEncryptor;
2625
private MockResponse $mockResponse;
2726

2827
#[\Override]

0 commit comments

Comments
 (0)