Skip to content
New issue

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

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

Already on GitHub? # to your account

Enhancement: Executed rector PHP 8.2 set #244

Merged
merged 2 commits into from
Sep 17, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
with:
php-version: 8.3
coverage: none
tools: php-cs-fixer:3.42, cs2pr
tools: php-cs-fixer:3.64, cs2pr

- name: Checkout code
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ doctrine:
mappings:
App:
is_bundle: false
type: annotation
type: attribute
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
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']);
20 changes: 7 additions & 13 deletions src/Api/Issue/GithubIssueApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@

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

public function open(Repository $repository, string $title, string $body, array $labels)
Expand Down
36 changes: 8 additions & 28 deletions src/Api/Label/GithubLabelApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,14 @@ class GithubLabelApi implements LabelApi
*
* @var array<array-key, array<array-key, bool>>
*/
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)
{
$this->labelsApi = $labelsApi;
$this->resultPager = $resultPager;
$this->cache = $cache;
$this->logger = $logger;
private array $labelCache = [];

public function __construct(
private readonly Labels $labelsApi,
private readonly ResultPager $resultPager,
private readonly CacheInterface $cache,
private readonly LoggerInterface $logger,
) {
}

public function getIssueLabels($issueNumber, Repository $repository): array
Expand Down
24 changes: 7 additions & 17 deletions src/Api/Milestone/GithubMilestoneApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,15 @@
*/
class GithubMilestoneApi implements MilestoneApi
{
/**
* @var Milestones
*/
private $milestonesApi;

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

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

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

private function getMilestones(Repository $repository): array
Expand All @@ -48,7 +38,7 @@ private function getMilestones(Repository $repository): array
return $this->cache[$key];
}

public function updateMilestone(Repository $repository, int $issueNumber, string $milestoneName)
public function updateMilestone(Repository $repository, int $issueNumber, string $milestoneName): void
{
$milestoneNumber = null;
foreach ($this->getMilestones($repository) as $milestone) {
Expand Down Expand Up @@ -77,7 +67,7 @@ public function exists(Repository $repository, string $milestoneName): bool
return false;
}

private function getCacheKey(Repository $repository)
private function getCacheKey(Repository $repository): string
{
return sprintf('%s_%s', $repository->getVendor(), $repository->getName());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Milestone/MilestoneApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
interface MilestoneApi
{
public function updateMilestone(Repository $repository, int $issueNumber, string $milestoneName);
public function updateMilestone(Repository $repository, int $issueNumber, string $milestoneName): void;

public function exists(Repository $repository, string $milestoneName): bool;
}
2 changes: 1 addition & 1 deletion src/Api/Milestone/NullMilestoneApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class NullMilestoneApi implements MilestoneApi
{
public function updateMilestone(Repository $repository, int $issueNumber, string $milestoneName)
public function updateMilestone(Repository $repository, int $issueNumber, string $milestoneName): void
{
}

Expand Down
13 changes: 5 additions & 8 deletions src/Api/PullRequest/GithubPullRequestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,18 @@
*/
class GithubPullRequestApi implements PullRequestApi
{
private $pullRequest;
private $search;

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

public function show(Repository $repository, $number): array
{
return (array) $this->pullRequest->show($repository->getVendor(), $repository->getName(), $number);
}

public function updateTitle(Repository $repository, $number, string $title, string $body = null): void
public function updateTitle(Repository $repository, $number, string $title, ?string $body = null): void
{
$params = ['title' => $title];

Expand Down
2 changes: 1 addition & 1 deletion src/Api/PullRequest/NullPullRequestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function show(Repository $repository, $number): array
return [];
}

public function updateTitle(Repository $repository, $number, string $title, string $body = null): void
public function updateTitle(Repository $repository, $number, string $title, ?string $body = null): void
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Api/PullRequest/PullRequestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface PullRequestApi
{
public function show(Repository $repository, $number): array;

public function updateTitle(Repository $repository, $number, string $title, string $body = null): void;
public function updateTitle(Repository $repository, $number, string $title, ?string $body = null): void;

public function getAuthorCount(Repository $repository, string $author): int;
}
25 changes: 8 additions & 17 deletions src/Api/Status/GitHubStatusApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,27 @@

class GitHubStatusApi implements StatusApi
{
private static $statusToLabel = [
private static array $statusToLabel = [
Status::NEEDS_REVIEW => 'Status: Needs Review',
Status::NEEDS_WORK => 'Status: Needs Work',
Status::WORKS_FOR_ME => 'Status: Works for me',
Status::REVIEWED => 'Status: Reviewed',
];

private $labelToStatus = [];
private array $labelToStatus;

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

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

/**
* @param int $issueNumber The GitHub issue number
* @param string|null $newStatus A Status::* constant
*/
public function setIssueStatus($issueNumber, ?string $newStatus, Repository $repository)
public function setIssueStatus(int $issueNumber, ?string $newStatus, Repository $repository): void
{
if (null !== $newStatus && !isset(self::$statusToLabel[$newStatus])) {
throw new \InvalidArgumentException(sprintf('Invalid status "%s"', $newStatus));
Expand Down Expand Up @@ -92,7 +83,7 @@ public function getIssueStatus($issueNumber, Repository $repository): ?string
return null;
}

public static function getNeedsReviewLabel()
public static function getNeedsReviewLabel(): string
{
return self::$statusToLabel[Status::NEEDS_REVIEW];
}
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Status/NullStatusApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
*/
class NullStatusApi implements StatusApi
{
public function getIssueStatus($issueNumber, Repository $repository): ?string
public function getIssueStatus(int $issueNumber, Repository $repository): ?string
{
return null;
}

public function setIssueStatus($issueNumber, ?string $newStatus, Repository $repository)
public function setIssueStatus(int $issueNumber, ?string $newStatus, Repository $repository): void
{
}
}
11 changes: 4 additions & 7 deletions src/Api/Status/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
*/
final class Status
{
public const NEEDS_REVIEW = 'needs_review';

public const NEEDS_WORK = 'needs_work';

public const WORKS_FOR_ME = 'works_for_me';

public const REVIEWED = 'reviewed';
public const string NEEDS_REVIEW = 'needs_review';
public const string NEEDS_WORK = 'needs_work';
public const string WORKS_FOR_ME = 'works_for_me';
public const string REVIEWED = 'reviewed';
}
4 changes: 2 additions & 2 deletions src/Api/Status/StatusApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
interface StatusApi
{
public function getIssueStatus($issueNumber, Repository $repository): ?string;
public function getIssueStatus(int $issueNumber, Repository $repository): ?string;

public function setIssueStatus($issueNumber, ?string $newStatus, Repository $repository);
public function setIssueStatus(int $issueNumber, ?string $newStatus, Repository $repository): void;
}
11 changes: 4 additions & 7 deletions src/Api/Workflow/GithubWorkflowApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
*/
class GithubWorkflowApi implements WorkflowApi
{
private ResultPager $resultPager;
private WorkflowRuns $workflowApi;

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

public function approveWorkflowsForPullRequest(Repository $repository, string $headRepository, string $headBranch): void
Expand Down
11 changes: 5 additions & 6 deletions src/Command/ListTaskCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@
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()
{
$this->addOption('number', null, InputOption::VALUE_REQUIRED, 'The issue number we are interested in', null);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var mixed|null $number */
$number = $input->getOption('number');
Expand Down Expand Up @@ -61,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
$io->newLine();

return 0;
return Command::SUCCESS;
}

private function actionToString(int $action): string
Expand Down
Loading