Skip to content

Commit 14891b7

Browse files
authored
Merge pull request #455 from kbsali/rector
Improve code base with Rector
2 parents 5a38b69 + 40d6497 commit 14891b7

File tree

133 files changed

+584
-564
lines changed

Some content is hidden

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

133 files changed

+584
-564
lines changed

.docker/PHP-Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:8.3-fpm
1+
FROM php:7.4-fpm
22

33
RUN apt-get update
44
RUN apt-get --yes --no-install-recommends install \
@@ -32,7 +32,7 @@ RUN docker-php-ext-install -j$(nproc) \
3232
COPY build/php/opcache.ini /usr/local/etc/php/conf.d/
3333
COPY build/php/custom.ini /usr/local/etc/php/conf.d/
3434

35-
RUN pecl install xdebug-3.4.0 && docker-php-ext-enable xdebug
35+
RUN pecl install xdebug-3.1.6 && docker-php-ext-enable xdebug
3636

3737
RUN php --version
3838

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
operating-system: ["ubuntu-latest"]
16-
php: ["7.4", "8.0", "8.1", "8.2", "8.3", "8.4", "8.5"]
16+
php: ["7.4", "8.0", "8.1", "8.2", "8.3", "8.4", "8.5", "8.6"]
1717

1818
steps:
1919
- name: Checkout
@@ -93,7 +93,7 @@ jobs:
9393
fail-fast: false
9494
matrix:
9595
operating-system: ["ubuntu-latest"]
96-
php: ["8.3"]
96+
php: ["7.4"]
9797
tool: ["phpstan", "code-coverage", "code-style"]
9898

9999
steps:
@@ -121,7 +121,7 @@ jobs:
121121

122122
- name: Run tests with coverage-clover
123123
if: ${{ matrix.tool == 'code-coverage' }}
124-
run: composer run phpunit -- --coverage-clover .phpunit.cache/clover.xml
124+
run: composer run phpunit -- -c tests/phpunit-coverage.xml.dist --coverage-clover .phpunit.cache/clover.xml
125125

126126
- name: Upload coverage reports to Codecov
127127
if: ${{ matrix.tool == 'code-coverage' }}

.phpstan.neon

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ parameters:
55
- src/
66
- tests/
77

8-
scanDirectories:
9-
- vendor
10-
118
treatPhpDocTypesAsCertain: false
129

1310
ignoreErrors:

.rector.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
return \Rector\Config\RectorConfig::configure()
6+
->withPaths([
7+
__DIR__ . '/src',
8+
__DIR__ . '/tests',
9+
])
10+
// uncomment to reach your current PHP version
11+
//->withPhpSets()
12+
->withPhp74Sets()
13+
->withPhpVersion(70400)
14+
->withSets([
15+
\Rector\Set\ValueObject\SetList::CODE_QUALITY,
16+
\Rector\Set\ValueObject\SetList::DEAD_CODE,
17+
\Art4\RectorBcLibrary\Set::BC_TYPE_DECLARATION,
18+
])
19+
->withSkip([
20+
\Rector\DeadCode\Rector\PropertyProperty\RemoveNullPropertyInitializationRector::class,
21+
])
22+
;

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030
"psr/http-factory": "^1.0"
3131
},
3232
"require-dev": {
33+
"art4/rector-bc-library": "^1.0",
3334
"behat/behat": "^3.14",
3435
"friendsofphp/php-cs-fixer": "^3.68",
3536
"guzzlehttp/psr7": "^2",
3637
"php-mock/php-mock-phpunit": "^2.13",
3738
"phpstan/phpstan": "^2.1",
38-
"phpunit/phpunit": "^9.5 || ^10.5 || ^11.2 || ^12.0.9"
39+
"phpunit/phpunit": "^9.5 || ^10.5 || ^11.2 || ^12.0.9",
40+
"rector/rector": "^2.3"
3941
},
4042
"autoload": {
4143
"psr-4": {
@@ -59,9 +61,10 @@
5961
],
6062
"behat": "behat --config tests/Behat/behat.yml",
6163
"codestyle": "php-cs-fixer fix",
62-
"coverage": "phpunit --coverage-html=\".phpunit.cache/code-coverage\"",
64+
"coverage": "phpunit -c tests/phpunit-coverage.xml.dist --coverage-html=\".phpunit.cache/code-coverage\"",
6365
"phpstan": "phpstan analyze --memory-limit 512M --configuration .phpstan.neon",
64-
"phpunit": "phpunit",
66+
"phpunit": "phpunit -c phpunit.xml.dist",
67+
"rector": "rector -c .rector.php",
6568
"test": [
6669
"@phpstan",
6770
"@phpunit",

docker-compose.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ services:
77
- 8111:80
88
depends_on:
99
- redmine-dev
10+
- redmine-6-1
11+
- redmine-6-0
12+
- redmine-5-1
1013
volumes:
1114
- ./:/var/www/project/ # Location of the project for php-fpm. Note this should be the same for NGINX.*
1215

1316
redmine-dev:
1417
image: redmine:6.1.0
18+
user: "33:33"
1519
ports:
1620
- "3000:3000"
1721
environment:
@@ -28,6 +32,7 @@ services:
2832

2933
redmine-6-1:
3034
image: redmine:6.1.0
35+
user: "33:33"
3136
ports:
3237
- "5061:3000"
3338
environment:
@@ -41,6 +46,7 @@ services:
4146

4247
redmine-6-0:
4348
image: redmine:6.0.7
49+
user: "33:33"
4450
ports:
4551
- "5060:3000"
4652
environment:
@@ -54,7 +60,7 @@ services:
5460

5561
redmine-5-1:
5662
image: redmine:5.1.10
57-
user: "1000:1000"
63+
user: "33:33"
5864
ports:
5965
- "5051:3000"
6066
environment:

phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
displayDetailsOnTestsThatTriggerWarnings="true"
1616
>
1717
<coverage />
18+
<php>
19+
<ini name="error_reporting" value="E_ALL" />
20+
<ini name="display_errors" value="1" />
21+
</php>
1822
<source>
1923
<include>
2024
<directory suffix=".php">src/Redmine/</directory>

src/Redmine/Api/AbstractApi.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ abstract class AbstractApi implements Api
2828
*/
2929
protected $client;
3030

31-
/**
32-
* @var HttpClient
33-
*/
34-
private $httpClient;
31+
private \Redmine\Http\HttpClient $httpClient;
3532

3633
/**
3734
* @var Response
@@ -73,7 +70,7 @@ final protected function getHttpClient(): HttpClient
7370

7471
final public function getLastResponse(): Response
7572
{
76-
return $this->lastResponse !== null ? $this->lastResponse : HttpFactory::makeResponse(0, '', '');
73+
return ($this->lastResponse instanceof Response) ? $this->lastResponse : HttpFactory::makeResponse(0, '', '');
7774
}
7875

7976
/**
@@ -300,7 +297,7 @@ protected function retrieveAll($endpoint, array $params = [])
300297
*/
301298
protected function retrieveData(string $endpoint, array $params = []): array
302299
{
303-
if (empty($params)) {
300+
if ($params === []) {
304301
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeRequest(
305302
'GET',
306303
strval($endpoint),
@@ -366,7 +363,7 @@ protected function retrieveData(string $endpoint, array $params = []): array
366363
$offset += $realLimit;
367364

368365
if (
369-
empty($newDataSet)
366+
$newDataSet === []
370367
|| !isset($newDataSet['limit'])
371368
|| (
372369
isset($newDataSet['offset'])

src/Redmine/Api/CustomField.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
class CustomField extends AbstractApi
1717
{
1818
/**
19-
* @var array<mixed>
19+
* @var null|array<mixed>
2020
*/
21-
private $customFields = [];
21+
private ?array $customFields = null;
2222

2323
/**
2424
* @var null|array<int,string>
2525
*/
26-
private $customFieldNames = null;
26+
private ?array $customFieldNames = null;
2727

2828
/**
2929
* List custom fields.
@@ -83,7 +83,7 @@ final public function listNames(): array
8383
*/
8484
public function all(array $params = [])
8585
{
86-
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::list()` instead.', E_USER_DEPRECATED);
86+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::list()` instead.', E_USER_DEPRECATED);
8787

8888
try {
8989
$this->customFields = $this->list($params);
@@ -92,7 +92,7 @@ public function all(array $params = [])
9292
return false;
9393
}
9494

95-
if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
95+
if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) {
9696
$e = $e->getPrevious();
9797
}
9898

@@ -115,7 +115,7 @@ public function all(array $params = [])
115115
*/
116116
public function listing($forceUpdate = false, array $params = [])
117117
{
118-
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);
118+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNames()` instead.', E_USER_DEPRECATED);
119119

120120
return $this->doListing($forceUpdate, $params);
121121
}
@@ -133,7 +133,7 @@ public function listing($forceUpdate = false, array $params = [])
133133
*/
134134
public function getIdByName($name, array $params = [])
135135
{
136-
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);
136+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNames()` instead.', E_USER_DEPRECATED);
137137

138138
$arr = $this->doListing(false, $params);
139139

@@ -151,7 +151,7 @@ public function getIdByName($name, array $params = [])
151151
*/
152152
private function doListing(bool $forceUpdate, array $params): array
153153
{
154-
if (empty($this->customFields) || $forceUpdate) {
154+
if ($forceUpdate || $this->customFields === null) {
155155
$this->customFields = $this->list($params);
156156
}
157157

src/Redmine/Api/Group.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
class Group extends AbstractApi
2323
{
2424
/**
25-
* @var array<mixed>
25+
* @var null|array<mixed>
2626
*/
27-
private $groups = [];
27+
private ?array $groups = null;
2828

2929
/**
3030
* @var null|array<int,string>
3131
*/
32-
private $groupNames = null;
32+
private ?array $groupNames = null;
3333

3434
/**
3535
* List groups.
@@ -85,7 +85,7 @@ final public function listNames(): array
8585
*/
8686
public function all(array $params = [])
8787
{
88-
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . __CLASS__ . '::list()` instead.', E_USER_DEPRECATED);
88+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.4.0, use `' . self::class . '::list()` instead.', E_USER_DEPRECATED);
8989

9090
try {
9191
$this->groups = $this->list($params);
@@ -94,7 +94,7 @@ public function all(array $params = [])
9494
return false;
9595
}
9696

97-
if ($e instanceof UnexpectedResponseException && $e->getPrevious() !== null) {
97+
if ($e instanceof UnexpectedResponseException && $e->getPrevious() instanceof \Throwable) {
9898
$e = $e->getPrevious();
9999
}
100100

@@ -116,9 +116,9 @@ public function all(array $params = [])
116116
*/
117117
public function listing($forceUpdate = false)
118118
{
119-
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . __CLASS__ . '::listNames()` instead.', E_USER_DEPRECATED);
119+
@trigger_error('`' . __METHOD__ . '()` is deprecated since v2.7.0, use `' . self::class . '::listNames()` instead.', E_USER_DEPRECATED);
120120

121-
if (empty($this->groups) || $forceUpdate) {
121+
if ($forceUpdate || $this->groups === null) {
122122
$this->groups = $this->list();
123123
}
124124
$ret = [];

0 commit comments

Comments
 (0)