Skip to content

Adding return type hints #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Service/GitHubRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public function handle(Request $request)
$this->logger->debug(sprintf('Handling from repository %s', $repositoryFullName));

$repository = $this->repositoryProvider->getRepository($repositoryFullName);

if (!$repository) {
throw new PreconditionFailedHttpException(sprintf('Unsupported repository "%s".', $repositoryFullName));
}
Expand Down
7 changes: 5 additions & 2 deletions src/Service/RepositoryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ public function __construct(array $repositories)
}
}

public function getRepository($repositoryName)
public function getRepository(string $repositoryName): ?Repository
{
$repository = strtolower($repositoryName);

return $this->repositories[$repository] ?? null;
}

public function getAllRepositories()
/**
* @return Repository[]
*/
public function getAllRepositories(): array
{
return array_values($this->repositories);
}
Expand Down
12 changes: 10 additions & 2 deletions src/Service/TaskHandler/CloseDraftHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Api\PullRequest\PullRequestApi;
use App\Entity\Task;
use App\Service\RepositoryProvider;
use Psr\Log\LoggerInterface;

/**
* @author Tobias Nyholm <[email protected]>
Expand All @@ -17,19 +18,26 @@ class CloseDraftHandler implements TaskHandlerInterface
private $issueApi;
private $repositoryProvider;
private $pullRequestApi;
private $logger;

public function __construct(PullRequestApi $pullRequestApi, IssueApi $issueApi, RepositoryProvider $repositoryProvider)
public function __construct(PullRequestApi $pullRequestApi, IssueApi $issueApi, RepositoryProvider $repositoryProvider, LoggerInterface $logger)
{
$this->issueApi = $issueApi;
$this->repositoryProvider = $repositoryProvider;
$this->pullRequestApi = $pullRequestApi;
$this->logger = $logger;
}

public function handle(Task $task): void
{
$repository = $this->repositoryProvider->getRepository($task->getRepositoryFullName());
$pr = $this->pullRequestApi->show($repository, $task->getNumber());
if (!$repository) {
$this->logger->error(sprintf('RepositoryProvider returned nothing for "%s" ', $task->getRepositoryFullName()));

return;
}

$pr = $this->pullRequestApi->show($repository, $task->getNumber());
if ($pr['draft'] ?? false) {
$this->issueApi->close($repository, $task->getNumber());
}
Expand Down
6 changes: 1 addition & 5 deletions tests/Controller/WebhookControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ public function setup()
$statusApi = self::$container->get(StatusApi::class);

// the labels need to be off this issue for one test to pass
$statusApi->setIssueStatus(
2,
null,
$repository->getRepository('carsonbot-playground/symfony')
);
$statusApi->setIssueStatus(2, null, $repository->getRepository('carsonbot-playground/symfony'));
}

/**
Expand Down
5 changes: 3 additions & 2 deletions tests/Service/TaskHandler/CloseDraftHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Service\RepositoryProvider;
use App\Service\TaskHandler\CloseDraftHandler;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;

class CloseDraftHandlerTest extends TestCase
{
Expand All @@ -29,7 +30,7 @@ public function testHandleStillInDraft()

$repoProvider = new RepositoryProvider(['carsonbot-playground/symfony' => []]);

$handler = new CloseDraftHandler($prApi, $issueApi, $repoProvider);
$handler = new CloseDraftHandler($prApi, $issueApi, $repoProvider, new NullLogger());
$handler->handle(new Task('carsonbot-playground/symfony', 4711, Task::ACTION_CLOSE_DRAFT, new \DateTimeImmutable()));
}

Expand All @@ -49,7 +50,7 @@ public function testHandleNotDraft()

$repoProvider = new RepositoryProvider(['carsonbot-playground/symfony' => []]);

$handler = new CloseDraftHandler($prApi, $issueApi, $repoProvider);
$handler = new CloseDraftHandler($prApi, $issueApi, $repoProvider, new NullLogger());
$handler->handle(new Task('carsonbot-playground/symfony', 4711, Task::ACTION_CLOSE_DRAFT, new \DateTimeImmutable()));
}
}