Skip to content

Commit

Permalink
Enhancement: Executed rector PHP 8.2 set
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarStark committed Sep 16, 2024
1 parent 8ad09c9 commit 83a0d03
Show file tree
Hide file tree
Showing 44 changed files with 97 additions and 389 deletions.
7 changes: 2 additions & 5 deletions public/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
exit("This script cannot be run from the CLI. Run it from a browser.\n");
}

if (!in_array(@$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::1',
))) {
if (!in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) {
header('HTTP/1.0 403 Forbidden');
exit('This script is only accessible from localhost.');
}

require_once dirname(__FILE__).'/../app/SymfonyRequirements.php';
require_once __DIR__.'/../app/SymfonyRequirements.php';

$symfonyRequirements = new SymfonyRequirements();

Expand Down
4 changes: 1 addition & 3 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};
return fn(array $context) => new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
13 changes: 1 addition & 12 deletions src/Api/Issue/GithubIssueApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,8 @@

class GithubIssueApi implements IssueApi
{
private $resultPager;
private $issueCommentApi;
private $issueApi;
private $searchApi;
private $botUsername;

public function __construct(ResultPager $resultPager, Comments $issueCommentApi, Issue $issueApi, Search $searchApi, string $botUsername)
public function __construct(private readonly ResultPager $resultPager, private readonly Comments $issueCommentApi, private readonly Issue $issueApi, private readonly Search $searchApi, private readonly string $botUsername)
{
$this->resultPager = $resultPager;
$this->issueCommentApi = $issueCommentApi;
$this->issueApi = $issueApi;
$this->searchApi = $searchApi;
$this->botUsername = $botUsername;
}

public function open(Repository $repository, string $title, string $body, array $labels)
Expand Down
28 changes: 2 additions & 26 deletions src/Api/Label/GithubLabelApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,8 @@ class GithubLabelApi implements LabelApi
*/
private $labelCache = [];

/**
* @var Labels
*/
private $labelsApi;

/**
* @var ResultPager
*/
private $resultPager;

/**
* @var CacheInterface
*/
private $cache;

/**
* @var LoggerInterface
*/
private $logger;

public function __construct(Labels $labelsApi, ResultPager $resultPager, CacheInterface $cache, LoggerInterface $logger)
public function __construct(private readonly Labels $labelsApi, private readonly ResultPager $resultPager, private readonly CacheInterface $cache, private readonly LoggerInterface $logger)
{
$this->labelsApi = $labelsApi;
$this->resultPager = $resultPager;
$this->cache = $cache;
$this->logger = $logger;
}

public function getIssueLabels($issueNumber, Repository $repository): array
Expand Down Expand Up @@ -146,7 +122,7 @@ public function getComponentLabelsForRepository(Repository $repository): array
$item->expiresAfter(86400);
$componentLabels = [];
foreach ($labels as $label) {
if ('dddddd' === strtolower($label['color'])) {
if ('dddddd' === strtolower((string) $label['color'])) {
$componentLabels[] = $label['name'];
}
}
Expand Down
14 changes: 1 addition & 13 deletions src/Api/Milestone/GithubMilestoneApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,13 @@
*/
class GithubMilestoneApi implements MilestoneApi
{
/**
* @var Milestones
*/
private $milestonesApi;

/**
* @var Issue
*/
private $issuesApi;

/**
* @var string[][]
*/
private $cache = [];

public function __construct(Milestones $milestonesApi, Issue $issuesApi)
public function __construct(private readonly Milestones $milestonesApi, private readonly Issue $issuesApi)
{
$this->milestonesApi = $milestonesApi;
$this->issuesApi = $issuesApi;
}

private function getMilestones(Repository $repository): array
Expand Down
7 changes: 1 addition & 6 deletions src/Api/PullRequest/GithubPullRequestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@
*/
class GithubPullRequestApi implements PullRequestApi
{
private $pullRequest;
private $search;

public function __construct(PullRequest $pullRequest, Search $search)
public function __construct(private readonly PullRequest $pullRequest, private readonly Search $search)
{
$this->pullRequest = $pullRequest;
$this->search = $search;
}

public function show(Repository $repository, $number): array
Expand Down
13 changes: 1 addition & 12 deletions src/Api/Status/GitHubStatusApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,9 @@ class GitHubStatusApi implements StatusApi

private $labelToStatus = [];

/**
* @var LabelApi
*/
private $labelsApi;
/**
* @var LoggerInterface
*/
private $logger;

public function __construct(LabelApi $labelsApi, LoggerInterface $logger)
public function __construct(private readonly LabelApi $labelsApi, private readonly LoggerInterface $logger)
{
$this->labelsApi = $labelsApi;
$this->labelToStatus = array_flip(self::$statusToLabel);
$this->logger = $logger;
}

/**
Expand Down
7 changes: 1 addition & 6 deletions src/Api/Workflow/GithubWorkflowApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@
*/
class GithubWorkflowApi implements WorkflowApi
{
private ResultPager $resultPager;
private WorkflowRuns $workflowApi;

public function __construct(ResultPager $resultPager, WorkflowRuns $workflowApi)
public function __construct(private readonly ResultPager $resultPager, private readonly WorkflowRuns $workflowApi)
{
$this->resultPager = $resultPager;
$this->workflowApi = $workflowApi;
}

public function approveWorkflowsForPullRequest(Repository $repository, string $headRepository, string $headBranch): void
Expand Down
4 changes: 1 addition & 3 deletions src/Command/ListTaskCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
class ListTaskCommand extends Command
{
protected static $defaultName = 'app:task:list';
private $repository;

public function __construct(TaskRepository $repository)
public function __construct(private readonly TaskRepository $repository)
{
parent::__construct();
$this->repository = $repository;
}

protected function configure()
Expand Down
13 changes: 1 addition & 12 deletions src/Command/PingStaleIssuesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,9 @@ class PingStaleIssuesCommand extends Command

protected static $defaultName = 'app:issue:ping-stale';

private $repositoryProvider;
private $issueApi;
private $scheduler;
private $commentGenerator;
private $labelApi;

public function __construct(RepositoryProvider $repositoryProvider, IssueApi $issueApi, TaskScheduler $scheduler, StaleIssueCommentGenerator $commentGenerator, LabelApi $labelApi)
public function __construct(private readonly RepositoryProvider $repositoryProvider, private readonly IssueApi $issueApi, private readonly TaskScheduler $scheduler, private readonly StaleIssueCommentGenerator $commentGenerator, private readonly LabelApi $labelApi)
{
parent::__construct();
$this->repositoryProvider = $repositoryProvider;
$this->issueApi = $issueApi;
$this->scheduler = $scheduler;
$this->commentGenerator = $commentGenerator;
$this->labelApi = $labelApi;
}

protected function configure()
Expand Down
8 changes: 1 addition & 7 deletions src/Command/RunTaskCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@
class RunTaskCommand extends Command
{
protected static $defaultName = 'app:task:run';
private $repository;
private $taskRunner;
private $logger;

public function __construct(TaskRepository $repository, TaskRunner $taskRunner, LoggerInterface $logger)
public function __construct(private readonly TaskRepository $repository, private readonly TaskRunner $taskRunner, private readonly LoggerInterface $logger)
{
parent::__construct();
$this->repository = $repository;
$this->taskRunner = $taskRunner;
$this->logger = $logger;
}

protected function configure()
Expand Down
42 changes: 11 additions & 31 deletions src/Entity/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,6 @@ class Task
*/
private $id;

/**
* @var string
*
* @ORM\Column(type="string")
*/
private $repositoryFullName;

/**
* @var int
*
* @ORM\Column(type="integer")
*/
private $number;

/**
* @var int
*
* @ORM\Column(type="integer")
*/
private $action;

/**
* @var \DateTimeImmutable
*
Expand All @@ -67,19 +46,20 @@ class Task
*/
private $updatedAt;

/**
* @var \DateTimeImmutable
*
public function __construct(/**
* @ORM\Column(type="string")
*/
private string $repositoryFullName, /**
* @ORM\Column(type="integer")
*/
private int $number, /**
* @ORM\Column(type="integer")
*/
private int $action, /**
* @ORM\Column(type="datetime_immutable")
*/
private $verifyAfter;

public function __construct(string $repositoryFullName, int $number, int $action, \DateTimeImmutable $verifyAfter)
private \DateTimeImmutable $verifyAfter)
{
$this->repositoryFullName = $repositoryFullName;
$this->number = $number;
$this->action = $action;
$this->verifyAfter = $verifyAfter;
$this->createdAt = new \DateTimeImmutable();
}

Expand Down
7 changes: 1 addition & 6 deletions src/Event/GitHubEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ class GitHubEvent extends Event
{
protected $responseData = [];

private $data;
private $repository;

public function __construct(array $data, Repository $repository)
public function __construct(private readonly array $data, private readonly Repository $repository)
{
$this->data = $data;
$this->repository = $repository;
}

public function getData()
Expand Down
31 changes: 9 additions & 22 deletions src/Model/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,15 @@
*/
class Repository
{
/**
* @var string
*/
private $vendor;

/**
* @var string
*/
private $name;

/**
* The webhook secret used by GitHub.
*
* @var string|null
*/
private $secret;

public function __construct(string $vendor, string $name, string $secret = null)
public function __construct(
private readonly string $vendor,
private readonly string $name,
/**
* The webhook secret used by GitHub.
*/
private readonly ?string $secret = null
)
{
$this->vendor = $vendor;
$this->name = $name;
$this->secret = $secret;
}

public function getVendor(): string
Expand All @@ -54,7 +41,7 @@ public function getNeedsReviewUrl(): string
'https://github.com/%s/%s/labels/%s',
$this->getVendor(),
$this->getName(),
rawurlencode(GitHubStatusApi::getNeedsReviewLabel())
rawurlencode((string) GitHubStatusApi::getNeedsReviewLabel())
);
}

Expand Down
13 changes: 3 additions & 10 deletions src/Service/GitHubRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,8 @@
*/
class GitHubRequestHandler
{
private $dispatcher;
private $repositoryProvider;
private $logger;

public function __construct(EventDispatcher $dispatcher, RepositoryProvider $repositoryProvider, LoggerInterface $logger)
public function __construct(private readonly EventDispatcher $dispatcher, private readonly RepositoryProvider $repositoryProvider, private readonly LoggerInterface $logger)
{
$this->dispatcher = $dispatcher;
$this->repositoryProvider = $repositoryProvider;
$this->logger = $logger;
}

/**
Expand All @@ -38,7 +31,7 @@ public function handle(Request $request)
throw new BadRequestHttpException('Invalid JSON body!');
}

$repositoryFullName = isset($data['repository']['full_name']) ? $data['repository']['full_name'] : null;
$repositoryFullName = $data['repository']['full_name'] ?? null;
if (empty($repositoryFullName)) {
throw new BadRequestHttpException('No repository name!');
}
Expand Down Expand Up @@ -94,6 +87,6 @@ private function authenticate($hash, $key, $data)
throw new \RuntimeException('"hash" extension is needed to check request signature.');
}

return hash_equals($hash, 'sha1='.hash_hmac('sha1', $data, $key));
return hash_equals($hash, 'sha1='.hash_hmac('sha1', (string) $data, (string) $key));
}
}
Loading

0 comments on commit 83a0d03

Please sign in to comment.