Skip to content

Commit f367f37

Browse files
committed
use types for arguments and return values
1 parent 98b259d commit f367f37

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+426
-550
lines changed

rector.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44

55
use Rector\Config\RectorConfig;
66
use Rector\Set\ValueObject\LevelSetList;
7+
use Rector\Set\ValueObject\SetList;
78
use Rector\Symfony\Set\SymfonyLevelSetList;
89
use Rector\Symfony\Set\SymfonySetList;
910

1011
return static function (RectorConfig $rectorConfig): void {
1112
$rectorConfig->symfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml');
1213

1314
$rectorConfig->sets([
14-
LevelSetList::UP_TO_PHP_74
15+
// LevelSetList::UP_TO_PHP_74,
16+
SetList::TYPE_DECLARATION
1517
]);
1618

17-
$rectorConfig->sets([
18-
SymfonyLevelSetList::UP_TO_SYMFONY_54,
19-
SymfonySetList::SYMFONY_CODE_QUALITY,
20-
SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
21-
]);
19+
// $rectorConfig->sets([
20+
// SymfonyLevelSetList::UP_TO_SYMFONY_54,
21+
// SymfonySetList::SYMFONY_CODE_QUALITY,
22+
// SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION
23+
// ]);
24+
2225
};

src/Command/DeleteRepoCommand.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
use App\Entity\LanguageStatsEntity;
66
use App\Entity\TranslationUpdateEntity;
77
use App\Services\Git\GitException;
8+
use App\Services\Git\GitNoRemoteException;
9+
use App\Services\GitHub\GitHubServiceException;
10+
use App\Services\GitLab\GitLabServiceException;
811
use App\Services\Repository\RepositoryManager;
912
use Doctrine\ORM\EntityManager;
1013
use Doctrine\ORM\EntityManagerInterface;
@@ -50,9 +53,12 @@ protected function configure(): void
5053
* @param OutputInterface $output
5154
* @return int
5255
*
53-
* @throws OptimisticLockException
54-
* @throws ORMException
5556
* @throws GitException
57+
* @throws ORMException
58+
* @throws OptimisticLockException
59+
* @throws GitHubServiceException
60+
* @throws GitLabServiceException
61+
* @throws GitNoRemoteException
5662
*/
5763
protected function execute(InputInterface $input, OutputInterface $output): int
5864
{

src/Command/EditRepoCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9393
* @throws ORMException
9494
* @throws OptimisticLockException
9595
*/
96-
protected function editRepo(RepositoryEntity $repo, $property, $value): int {
96+
protected function editRepo(RepositoryEntity $repo, string $property, string $value): int {
9797

9898
switch($property) {
9999
case 'giturl':
@@ -136,7 +136,7 @@ protected function editRepo(RepositoryEntity $repo, $property, $value): int {
136136
return Command::SUCCESS;
137137
}
138138

139-
protected function showValue(RepositoryEntity $repo, $property): int
139+
protected function showValue(RepositoryEntity $repo, string $property): int
140140
{
141141
switch($property) {
142142
case 'giturl':

src/Command/ShowInfoCommand.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class ShowInfoCommand extends Command
2727
protected static $defaultName = 'dokuwiki:showInfo';
2828
protected static $defaultDescription = 'Show status for maintenance for all or a specific repo, or basic info for all';
2929

30-
public function __construct(RepositoryEntityRepository $repositoryEntityRepository, TranslationUpdateEntityRepository $translationUpdateEntityRepository, RepositoryManager $repositoryManager, ParameterBagInterface $parameterBag)
30+
public function __construct(RepositoryEntityRepository $repositoryEntityRepository,
31+
TranslationUpdateEntityRepository $translationUpdateEntityRepository,
32+
RepositoryManager $repositoryManager, ParameterBagInterface $parameterBag)
3133
{
3234
$this->repositoryEntityRepository = $repositoryEntityRepository;
3335
$this->translationUpdateEntityRepository = $translationUpdateEntityRepository;
@@ -102,18 +104,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int
102104
* @param bool $newline Whether to add a newline
103105
* @return void
104106
*/
105-
private function writeJustified(OutputInterface $output, int $length, string $message, bool $newline = false)
107+
private function writeJustified(OutputInterface $output, int $length, string $message, bool $newline = false): void
106108
{
107109
$output->write(sprintf("%-{$length}s", $message), $newline);
108110
}
109111

110112
/**
111113
* @param OutputInterface $output
112114
* @param RepositoryEntity[] $repositories
113-
* @param $type
115+
* @param string|null $type
114116
* @return void
115117
*/
116-
private function showStatusInfo(OutputInterface $output, array $repositories, $type): void
118+
private function showStatusInfo(OutputInterface $output, array $repositories, ?string $type): void
117119
{
118120
// header
119121
$dashLine = str_repeat('-', 35 - 1) . ' '
@@ -216,7 +218,7 @@ private function showStatusInfo(OutputInterface $output, array $repositories, $t
216218
* @param RepositoryEntity[] $repositories
217219
* @return void
218220
*/
219-
private function showBasicInfoRepositories(OutputInterface $output, array $repositories)
221+
private function showBasicInfoRepositories(OutputInterface $output, array $repositories): void
220222
{
221223
// Table
222224
// header
@@ -253,7 +255,7 @@ private function showBasicInfoRepositories(OutputInterface $output, array $repos
253255
$output->writeln('found ' . $countTotal . ' repositories');
254256
}
255257

256-
private function showExtendedInfoRepository(OutputInterface $output, RepositoryEntity $repoEntity, bool $showMore){
258+
private function showExtendedInfoRepository(OutputInterface $output, RepositoryEntity $repoEntity, bool $showMore): void {
257259
//list
258260
try {
259261
$dashLine = str_repeat('-', 30 - 1) . ' '

src/Command/UpdateCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class UpdateCommand extends Command {
2626
protected static $defaultName = 'dokuwiki:updateGit';
2727
protected static $defaultDescription = 'Update local git repositories (and eventually the fork) and send pending translations';
2828

29-
public function __construct(TranslationUpdateEntityRepository $translationUpdateEntityRepository, RepositoryManager $repositoryManager, ParameterBagInterface $parameterBag, LoggerInterface $logger) {
29+
public function __construct(TranslationUpdateEntityRepository $translationUpdateEntityRepository,
30+
RepositoryManager $repositoryManager, ParameterBagInterface $parameterBag,
31+
LoggerInterface $logger) {
3032
$this->repositoryManager = $repositoryManager;
3133
$this->translationUpdateEntityRepository = $translationUpdateEntityRepository;
3234
$this->parameterBag = $parameterBag;
@@ -71,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7173
* @throws OptimisticLockException
7274
* @throws TransportExceptionInterface
7375
*/
74-
private function runUpdateOfRepositories() {
76+
private function runUpdateOfRepositories(): void {
7577
$repositories = $this->repositoryManager->getRepositoriesToUpdate();
7678
foreach($repositories as $repository) {
7779
$repository->update();
@@ -83,7 +85,7 @@ private function runUpdateOfRepositories() {
8385
* @throws OptimisticLockException
8486
* @throws TransportExceptionInterface
8587
*/
86-
private function processPendingTranslations() {
88+
private function processPendingTranslations(): void {
8789
$updates = $this->translationUpdateEntityRepository->getPendingTranslationUpdates();
8890

8991
foreach ($updates as $update) {
@@ -123,7 +125,7 @@ private function lock() {
123125
return false;
124126
}
125127

126-
private function unlock() {
128+
private function unlock(): void {
127129
unlink($this->getLockFilePath());
128130
}
129131

src/Controller/DefaultController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public function index(Request $request, LanguageManager $languageManager, Reposi
6363
* @throws NonUniqueResultException
6464
*/
6565
public function show(Request $request, LanguageManager $languageManager, RepositoryEntityRepository $repoEntityRepo,
66-
LanguageNameEntityRepository $langNameEntityRepo) {
66+
LanguageNameEntityRepository $langNameEntityRepo): Response
67+
{
6768
$data = [];
6869
$data['repository'] = $repoEntityRepo->getCoreTranslation();
6970
$data['currentLanguage'] = $languageManager->getLanguage($request);

src/Controller/ExtensionController.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public function __construct(RepositoryEntityRepository $repositoryRepository,
5656
* @throws OptimisticLockException
5757
* @throws TransportExceptionInterface
5858
*/
59-
public function index(Request $request, $type, DokuWikiRepositoryAPI $api, MailService $mailer) {
59+
public function index(Request $request, string $type, DokuWikiRepositoryAPI $api, MailService $mailer): Response
60+
{
6061
$data = [];
6162

6263
$repository = new RepositoryEntity();
@@ -96,7 +97,7 @@ public function index(Request $request, $type, DokuWikiRepositoryAPI $api, MailS
9697
* @throws TransportExceptionInterface
9798
* @throws OptimisticLockException
9899
*/
99-
private function addExtension(RepositoryEntity $repository, DokuWikiRepositoryAPI $api, MailService $mailer) {
100+
private function addExtension(RepositoryEntity $repository, DokuWikiRepositoryAPI $api, MailService $mailer): void {
100101
$api->mergeExtensionInfo($repository);
101102
$repository->setLastUpdate(0);
102103
$repository->setState(RepositoryEntity::STATE_WAITING_FOR_APPROVAL);
@@ -115,7 +116,7 @@ private function addExtension(RepositoryEntity $repository, DokuWikiRepositoryAP
115116
);
116117
}
117118

118-
private function generateActivationKey(RepositoryEntity $repository) {
119+
private function generateActivationKey(RepositoryEntity $repository): string {
119120
return md5($repository->getType() . ':' . $repository->getName() . time());
120121
}
121122

@@ -130,7 +131,8 @@ private function generateActivationKey(RepositoryEntity $repository) {
130131
* @throws NonUniqueResultException
131132
* @throws ORMException
132133
*/
133-
public function activate($type, $name, $key) {
134+
public function activate(string $type, string $name, string $key): RedirectResponse
135+
{
134136
$data = [];
135137
try {
136138
$repository = $this->repositoryRepository->getRepositoryByNameAndActivationKey($type, $name, $key);
@@ -158,7 +160,7 @@ public function activate($type, $name, $key) {
158160
*
159161
* @throws NonUniqueResultException
160162
*/
161-
public function show(Request $request, $type, $name, LanguageManager $languageManager) {
163+
public function show(Request $request, string $type, string $name, LanguageManager $languageManager): Response {
162164
$data = [];
163165

164166
try {
@@ -190,7 +192,7 @@ public function show(Request $request, $type, $name, LanguageManager $languageMa
190192
* @throws OptimisticLockException
191193
* @throws TransportExceptionInterface
192194
*/
193-
public function settings(Request $request, $type, $name, MailerInterface $mailer) {
195+
public function settings(Request $request, string $type, string $name, MailerInterface $mailer): Response {
194196
$data = [];
195197

196198
try {
@@ -229,7 +231,7 @@ public function settings(Request $request, $type, $name, MailerInterface $mailer
229231
* @throws OptimisticLockException
230232
* @throws TransportExceptionInterface
231233
*/
232-
private function createAndSentEditKey(RepositoryEntity $repository, MailerInterface $mailer) {
234+
private function createAndSentEditKey(RepositoryEntity $repository, MailerInterface $mailer): void {
233235
$repository->setActivationKey($this->generateActivationKey($repository));
234236
$this->entityManager->flush();
235237

@@ -257,7 +259,8 @@ private function createAndSentEditKey(RepositoryEntity $repository, MailerInterf
257259
* @throws ORMException
258260
* @throws OptimisticLockException
259261
*/
260-
public function edit(Request $request, $type, $name, $key, RepositoryManager $repositoryManager) {
262+
public function edit(Request $request, string $type, string $name, string $key, RepositoryManager $repositoryManager): Response
263+
{
261264
$options = [];
262265
$param = [];
263266
$data = [];
@@ -302,7 +305,7 @@ public function edit(Request $request, $type, $name, $key, RepositoryManager $re
302305
* @throws ORMException
303306
* @throws OptimisticLockException
304307
*/
305-
private function updateExtension(RepositoryEntity $repositoryEntity, $originalValues, RepositoryManager $repositoryManager) {
308+
private function updateExtension(RepositoryEntity $repositoryEntity, array $originalValues, RepositoryManager $repositoryManager): void {
306309
$repositoryEntity->setLastUpdate(0);
307310
$repositoryEntity->setErrorCount(0); //save of edit form resets error count on purpose
308311
$repositoryEntity->setActivationKey('');

src/Controller/TranslationController.php

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Controller;
44

55
use App\Entity\LanguageNameEntity;
6+
use App\Services\GitHub\GitHubServiceException;
67
use Doctrine\ORM\EntityManager;
78
use Doctrine\ORM\EntityManagerInterface;
89
use Doctrine\ORM\Exception\ORMException;
@@ -55,8 +56,9 @@ public function __construct(RepositoryManager $repositoryManager, LanguageManage
5556
* @throws NoResultException
5657
* @throws ORMException
5758
* @throws OptimisticLockException
59+
* @throws GitHubServiceException
5860
*/
59-
public function save(Request $request, UserTranslationValidatorFactory $validatorFactory) {
61+
public function save(Request $request, UserTranslationValidatorFactory $validatorFactory): Response {
6062
if ($request->getMethod() !== 'POST') {
6163
return $this->redirectToRoute('dokuwiki_translator_homepage');
6264
}
@@ -137,8 +139,9 @@ public function save(Request $request, UserTranslationValidatorFactory $validato
137139
* @return UserTranslationValidator
138140
*/
139141
protected function getUserTranslationValidator(array $defaultTranslation, array $previousTranslation,
140-
array $userTranslation, $author, $authorEmail,
141-
UserTranslationValidatorFactory $validatorFactory) {
142+
array $userTranslation, string $author, string $authorEmail,
143+
UserTranslationValidatorFactory $validatorFactory): UserTranslationValidator
144+
{
142145
return $validatorFactory->getInstance($defaultTranslation, $previousTranslation,
143146
$userTranslation, $author, $authorEmail);
144147
}
@@ -148,8 +151,10 @@ protected function getUserTranslationValidator(array $defaultTranslation, array
148151
*
149152
* @param Request $request
150153
* @return RedirectResponse|Response
154+
*
155+
* @throws GitHubServiceException
151156
*/
152-
public function translateCore(Request $request) {
157+
public function translateCore(Request $request): Response {
153158
return $this->translate($request, RepositoryEntity::TYPE_CORE, 'dokuwiki');
154159
}
155160

@@ -160,8 +165,10 @@ public function translateCore(Request $request) {
160165
* @param string $type
161166
* @param string $name
162167
* @return RedirectResponse|Response
168+
*
169+
* @throws GitHubServiceException
163170
*/
164-
public function translateExtension(Request $request, $type, $name) {
171+
public function translateExtension(Request $request, string $type, string $name): Response {
165172
return $this->translate($request, $type, $name);
166173
}
167174

@@ -177,8 +184,10 @@ public function translateExtension(Request $request, $type, $name) {
177184
* - (string) authorMail
178185
* @param FormInterface|null $captchaForm
179186
* @return RedirectResponse|Response
187+
*
188+
* @throws GitHubServiceException
180189
*/
181-
private function translate(Request $request, $type, $name, array $userInput = [], $captchaForm = null) {
190+
private function translate(Request $request, string $type, string $name, array $userInput = [], $captchaForm = null): Response {
182191
$data = [];
183192
$param = [];
184193
$language = $this->getLanguage($request);
@@ -244,13 +253,13 @@ private function translate(Request $request, $type, $name, array $userInput = []
244253
return $this->render('translate/translate.html.twig', $data);
245254
}
246255

247-
private function getCaptchaForm() {
256+
private function getCaptchaForm(): FormInterface {
248257
return $this->createFormBuilder()
249258
->add('captcha', CaptchaType::class)
250259
->getForm();
251260
}
252261

253-
private function prepareLanguages($language, $repositoryEntity, array $userTranslation) {
262+
private function prepareLanguages(string $language, RepositoryEntity $repositoryEntity, array $userTranslation): array {
254263
$repository = $this->repositoryManager->getRepository($repositoryEntity);
255264

256265
$defaultTranslation = $repository->getLanguage('en');
@@ -266,18 +275,20 @@ private function prepareLanguages($language, $repositoryEntity, array $userTrans
266275
/**
267276
* @return LanguageNameEntityRepository
268277
*/
269-
private function getLanguageNameEntityRepository() {
278+
private function getLanguageNameEntityRepository(): LanguageNameEntityRepository {
270279
return $this->entityManager->getRepository(LanguageNameEntity::class);
271280
}
272281

273282
/**
274283
* Get information about the open pull requests of the given language
275284
*
276-
* @param $repositoryEntity
277-
* @param $languageNameEntity
285+
* @param RepositoryEntity $repositoryEntity
286+
* @param LanguageNameEntity $languageNameEntity
278287
* @return array with string listURL and int count
288+
*
289+
* @throws GitHubServiceException
279290
*/
280-
private function getOpenPRListInfo($repositoryEntity, $languageNameEntity) {
291+
private function getOpenPRListInfo(RepositoryEntity $repositoryEntity, LanguageNameEntity $languageNameEntity): array {
281292
$repository = $this->repositoryManager->getRepository($repositoryEntity);
282293
return $repository->getOpenPRListInfo($languageNameEntity);
283294
}
@@ -287,11 +298,12 @@ private function getOpenPRListInfo($repositoryEntity, $languageNameEntity) {
287298
*
288299
* @return Response
289300
*/
290-
public function thanks() {
301+
public function thanks(): Response
302+
{
291303
return $this->render('translate/thanks.html.twig');
292304
}
293305

294-
private function getLanguage($request) {
306+
private function getLanguage(Request $request): string {
295307
return $this->languageManager->getLanguage($request);
296308
}
297309
}

0 commit comments

Comments
 (0)