Skip to content

Commit 7d486d6

Browse files
committed
[TASK] drop PHP <8.2 compatibility
* applies max PHPStan level * applies rules from rector.php * applies TYPO3 coding standards as EXT:solr 13.0.x ### Github-Actions added for: * PHPStan * Rector * PHP CS
1 parent 518a8cf commit 7d486d6

37 files changed

+569
-564
lines changed

.github/workflows/ci.yml

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,71 @@ on:
88
pull_request:
99
branches: [ main ]
1010

11+
env:
12+
IS_ON_GITHUB_ACTIONS: 'true'
13+
PHP_MIN: '8.2'
14+
1115
jobs:
16+
analysis:
17+
runs-on: ubuntu-latest
18+
steps:
19+
# Workaround for issue with actions/checkout "wrong PR commit checkout":
20+
# See:
21+
# ** https://github.com/actions/checkout/issues/299#issuecomment-677674415
22+
# ** https://github.com/actions/checkout/issues/1359#issuecomment-1631503791
23+
- name: Checkout current state of Pull Request
24+
if: github.event_name == 'pull_request'
25+
uses: actions/checkout@v4
26+
with:
27+
ref: ${{ github.event.pull_request.head.sha }}
28+
- name: Checkout current state of Branch
29+
if: github.event_name == 'push'
30+
uses: actions/checkout@v4
31+
# End: Workaround for issue with actions/checkout...
32+
33+
- name: Setup PHP
34+
uses: shivammathur/setup-php@v2
35+
with:
36+
php-version: ${{ env.PHP_MIN }}
37+
coverage: pcov
38+
tools: composer:v2
39+
40+
- name: Tests setup
41+
run: |
42+
composer tests:setup
43+
44+
- name: Check coding standards
45+
run: |
46+
composer t3:standards:fix -- --diff --verbose --dry-run --show-progress=none
47+
48+
- name: PHPStan
49+
run: |
50+
composer tests:phpstan -- --no-progress
51+
52+
- name: Rector
53+
run: |
54+
composer tests:rector-check -- --no-progress-bar
55+
1256
tests:
1357
runs-on: ubuntu-latest
1458
strategy:
1559
matrix:
16-
PHP: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
60+
PHP: [ '8.2', '8.3', '8.4' ]
1761

18-
name: On PHP ${{ matrix.PHP }}
62+
name: Tests on PHP ${{ matrix.PHP }}
1963
steps:
2064
# Workaround for issue with actions/checkout "wrong PR commit checkout":
2165
# See:
2266
# ** https://github.com/actions/checkout/issues/299#issuecomment-677674415
2367
# ** https://github.com/actions/checkout/issues/1359#issuecomment-1631503791
2468
- name: Checkout current state of Pull Request
2569
if: github.event_name == 'pull_request'
26-
uses: actions/checkout@v3
70+
uses: actions/checkout@v4
2771
with:
2872
ref: ${{ github.event.pull_request.head.sha }}
2973
- name: Checkout current state of Branch
3074
if: github.event_name == 'push'
31-
uses: actions/checkout@v3
75+
uses: actions/checkout@v4
3276
# End: Workaround for issue with actions/checkout...
3377

3478
- name: Setup PHP
@@ -53,7 +97,7 @@ jobs:
5397
runs-on: ubuntu-latest
5498
steps:
5599
- name: Checkout repository
56-
uses: actions/checkout@v3
100+
uses: actions/checkout@v4
57101

58102
# Build PHAR
59103
- name: Build PHAR

.php-cs-fixer.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use TYPO3\CodingStandards\CsFixerConfig;
6+
7+
$config = CsFixerConfig::create();
8+
9+
if (getenv('IS_ON_GITHUB_ACTIONS') === 'true') {
10+
$config = $config->setHideProgress(true);
11+
}
12+
13+
$config
14+
->addRules(
15+
[
16+
'global_namespace_import' => [
17+
'import_classes' => true,
18+
'import_constants' => false,
19+
'import_functions' => true,
20+
],
21+
'ordered_imports' => [
22+
'imports_order' => ['class', 'function', 'const'],
23+
'sort_algorithm' => 'alpha'
24+
],
25+
'general_phpdoc_annotation_remove' => [
26+
'annotations' => [
27+
'author', 'autor',
28+
'copyright',
29+
]
30+
],
31+
],
32+
)
33+
->getFinder()
34+
->exclude([
35+
'.Build'
36+
])
37+
->in(__DIR__);
38+
return $config;

Build/Test/phpstan.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
includes:
2+
- %rootDir%/../phpstan-phpunit/extension.neon
3+
4+
parameters:
5+
level: max
6+
treatPhpDocTypesAsCertain: false
7+
8+
paths:
9+
- %currentWorkingDirectory%/Classes
10+
- %currentWorkingDirectory%/Tests

Build/Test/phpunit.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
35
bootstrap="../../.Build/vendor/autoload.php"
46
backupGlobals="false"
5-
backupStaticAttributes="false"
67
colors="true"
7-
convertErrorsToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
forceCoversAnnotation="false"
108
processIsolation="false"
119
stopOnError="false"
1210
stopOnFailure="false"
1311
stopOnIncomplete="false"
1412
stopOnSkipped="false"
15-
verbose="false"
13+
cacheDirectory=".phpunit.cache"
14+
backupStaticProperties="false"
15+
requireCoverageMetadata="false"
1616
>
17-
<coverage processUncoveredFiles="false">
18-
<include>
19-
<directory suffix=".php">../../Classes/</directory>
20-
</include>
21-
</coverage>
2217
<testsuites>
2318
<testsuite name="php-solr-explain-unit-tests">
2419
<directory suffix="TestCase.php">../../Tests/</directory>
2520
</testsuite>
2621
</testsuites>
22+
<source>
23+
<include>
24+
<directory suffix=".php">../../Classes/</directory>
25+
</include>
26+
</source>
2727
</phpunit>

Classes/Domain/Result/Document/Collection.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
use ArrayObject;
66

7+
/**
8+
* @template-extends ArrayObject<int, Document>
9+
*/
710
class Collection extends ArrayObject
811
{
9-
/**
10-
* @param $offset
11-
* @return Document
12-
*/
13-
public function getDocument($offset): Document
12+
public function getDocument(int $offset): ?Document
1413
{
1514
return $this->offsetGet($offset);
1615
}

Classes/Domain/Result/Document/Document.php

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,37 @@
77

88
class Document
99
{
10-
/**
11-
* @var Collection
12-
*/
13-
protected $fieldCollection;
10+
protected Collection $fieldCollection;
1411

15-
/**
16-
* @var string
17-
*/
18-
protected $rawExplainData;
12+
protected string $rawExplainData;
1913

2014
public function __construct()
2115
{
2216
$this->fieldCollection = new Collection();
2317
}
2418

25-
/**
26-
* @param Field $field
27-
*/
28-
public function addField(Field $field)
19+
public function addField(Field $field): void
2920
{
3021
$this->fieldCollection->offsetSet($field->getName(), $field);
3122
}
3223

3324
/**
34-
* @return Collection
25+
* @noinspection PhpUnused
3526
*/
3627
public function getFields(): Collection
3728
{
3829
return $this->fieldCollection;
3930
}
4031

41-
/**
42-
* @param string
43-
* @return Field
44-
*/
45-
public function getFieldByName(string $fieldName): Field
32+
public function getFieldByName(string $fieldName): ?Field
4633
{
4734
return $this->fieldCollection->offsetGet($fieldName);
4835
}
4936

5037
/**
5138
* @param string $rawExplainData
5239
*/
53-
public function setRawExplainData(string $rawExplainData)
40+
public function setRawExplainData(string $rawExplainData): void
5441
{
5542
$this->rawExplainData = $rawExplainData;
5643
}

Classes/Domain/Result/Document/Field/Collection.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44

55
use ArrayObject;
66

7+
/**
8+
* @template-extends ArrayObject<string, Field>
9+
*/
710
class Collection extends ArrayObject {}

Classes/Domain/Result/Document/Field/Field.php

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,71 +4,53 @@
44

55
class Field
66
{
7-
/**
8-
* @var string
9-
*/
10-
protected $name;
7+
protected string $name;
118

12-
/**
13-
* @var mixed
14-
*/
15-
protected $value;
9+
protected mixed $value;
1610

17-
/**
18-
* @var int
19-
*/
20-
protected $type;
11+
protected int $type;
2112

22-
/**
23-
* @param string $name
24-
*/
25-
public function setName(string $name)
13+
public function setName(string $name): void
2614
{
2715
$this->name = $name;
2816
}
2917

30-
/**
31-
* @return string
32-
*/
3318
public function getName(): string
3419
{
3520
return $this->name;
3621
}
3722

3823
/**
39-
* @param int $type
24+
* @noinspection PhpUnused
4025
*/
41-
public function setType(int $type)
26+
public function setType(int $type): void
4227
{
4328
$this->type = $type;
4429
}
4530

4631
/**
47-
* @return int
32+
* @noinspection PhpUnused
4833
*/
4934
public function getType(): int
5035
{
5136
return $this->type;
5237
}
5338

54-
/**
55-
* @param mixed $value
56-
*/
57-
public function setValue($value)
39+
public function setValue(mixed $value): void
5840
{
5941
$this->value = $value;
6042
}
6143

6244
/**
6345
* @return mixed
6446
*/
65-
public function getValue()
47+
public function getValue(): mixed
6648
{
6749
return $this->value;
6850
}
6951

7052
/**
71-
* @boolean
53+
* @noinspection PhpUnused
7254
*/
7355
public function isMultiValue(): bool
7456
{

Classes/Domain/Result/Explanation/Content.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,10 @@
2121
*/
2222
class Content
2323
{
24-
/**
25-
* @var string
26-
*/
27-
protected $content;
24+
public function __construct(
25+
protected string $content,
26+
) {}
2827

29-
/**
30-
* @param string $content
31-
*/
32-
public function __construct(string $content)
33-
{
34-
$this->content = $content;
35-
}
36-
37-
/**
38-
* @return string
39-
*/
4028
public function getContent(): string
4129
{
4230
return $this->content;

0 commit comments

Comments
 (0)