Skip to content

Commit

Permalink
[TASK] drop PHP <8.2 compatibility
Browse files Browse the repository at this point in the history
* 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

Fixes: #13
  • Loading branch information
dkd-kaehm committed Feb 28, 2025
1 parent 518a8cf commit d57e8d4
Show file tree
Hide file tree
Showing 37 changed files with 570 additions and 564 deletions.
55 changes: 50 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,72 @@ on:
pull_request:
branches: [ main ]

env:
IS_ON_GITHUB_ACTIONS: 'true'
PHP_MIN: '8.2'

jobs:
analysis:
name: Static analysis
runs-on: ubuntu-latest
steps:
# Workaround for issue with actions/checkout "wrong PR commit checkout":
# See:
# ** https://github.com/actions/checkout/issues/299#issuecomment-677674415
# ** https://github.com/actions/checkout/issues/1359#issuecomment-1631503791
- name: Checkout current state of Pull Request
if: github.event_name == 'pull_request'
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Checkout current state of Branch
if: github.event_name == 'push'
uses: actions/checkout@v4
# End: Workaround for issue with actions/checkout...

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_MIN }}
coverage: pcov
tools: composer:v2

- name: Tests setup
run: |
composer tests:setup
- name: Check coding standards
run: |
composer t3:standards:fix -- --diff --verbose --dry-run --show-progress=none
- name: PHPStan
run: |
composer tests:phpstan -- --no-progress
- name: Rector
run: |
composer tests:rector-check -- --no-progress-bar
tests:
runs-on: ubuntu-latest
strategy:
matrix:
PHP: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
PHP: [ '8.2', '8.3', '8.4' ]

name: On PHP ${{ matrix.PHP }}
name: Tests on PHP ${{ matrix.PHP }}
steps:
# Workaround for issue with actions/checkout "wrong PR commit checkout":
# See:
# ** https://github.com/actions/checkout/issues/299#issuecomment-677674415
# ** https://github.com/actions/checkout/issues/1359#issuecomment-1631503791
- name: Checkout current state of Pull Request
if: github.event_name == 'pull_request'
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Checkout current state of Branch
if: github.event_name == 'push'
uses: actions/checkout@v3
uses: actions/checkout@v4
# End: Workaround for issue with actions/checkout...

- name: Setup PHP
Expand All @@ -53,7 +98,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Build PHAR
- name: Build PHAR
Expand Down
38 changes: 38 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

use TYPO3\CodingStandards\CsFixerConfig;

$config = CsFixerConfig::create();

if (getenv('IS_ON_GITHUB_ACTIONS') === 'true') {
$config = $config->setHideProgress(true);
}

$config
->addRules(
[
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => false,
'import_functions' => true,
],
'ordered_imports' => [
'imports_order' => ['class', 'function', 'const'],
'sort_algorithm' => 'alpha'
],
'general_phpdoc_annotation_remove' => [
'annotations' => [
'author', 'autor',
'copyright',
]
],
],
)
->getFinder()
->exclude([
'.Build'
])
->in(__DIR__);
return $config;
10 changes: 10 additions & 0 deletions Build/Test/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
includes:
- %rootDir%/../phpstan-phpunit/extension.neon

parameters:
level: max
treatPhpDocTypesAsCertain: false

paths:
- %currentWorkingDirectory%/Classes
- %currentWorkingDirectory%/Tests
22 changes: 11 additions & 11 deletions Build/Test/phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
bootstrap="../../.Build/vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="false"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
requireCoverageMetadata="false"
>
<coverage processUncoveredFiles="false">
<include>
<directory suffix=".php">../../Classes/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="php-solr-explain-unit-tests">
<directory suffix="TestCase.php">../../Tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">../../Classes/</directory>
</include>
</source>
</phpunit>
9 changes: 4 additions & 5 deletions Classes/Domain/Result/Document/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

use ArrayObject;

/**
* @template-extends ArrayObject<int, Document>
*/
class Collection extends ArrayObject
{
/**
* @param $offset
* @return Document
*/
public function getDocument($offset): Document
public function getDocument(int $offset): ?Document
{
return $this->offsetGet($offset);
}
Expand Down
25 changes: 6 additions & 19 deletions Classes/Domain/Result/Document/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,37 @@

class Document
{
/**
* @var Collection
*/
protected $fieldCollection;
protected Collection $fieldCollection;

/**
* @var string
*/
protected $rawExplainData;
protected string $rawExplainData;

public function __construct()
{
$this->fieldCollection = new Collection();
}

/**
* @param Field $field
*/
public function addField(Field $field)
public function addField(Field $field): void
{
$this->fieldCollection->offsetSet($field->getName(), $field);
}

/**
* @return Collection
* @noinspection PhpUnused
*/
public function getFields(): Collection
{
return $this->fieldCollection;
}

/**
* @param string
* @return Field
*/
public function getFieldByName(string $fieldName): Field
public function getFieldByName(string $fieldName): ?Field
{
return $this->fieldCollection->offsetGet($fieldName);
}

/**
* @param string $rawExplainData
*/
public function setRawExplainData(string $rawExplainData)
public function setRawExplainData(string $rawExplainData): void
{
$this->rawExplainData = $rawExplainData;
}
Expand Down
3 changes: 3 additions & 0 deletions Classes/Domain/Result/Document/Field/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@

use ArrayObject;

/**
* @template-extends ArrayObject<string, Field>
*/
class Collection extends ArrayObject {}
38 changes: 10 additions & 28 deletions Classes/Domain/Result/Document/Field/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,53 @@

class Field
{
/**
* @var string
*/
protected $name;
protected string $name;

/**
* @var mixed
*/
protected $value;
protected mixed $value;

/**
* @var int
*/
protected $type;
protected int $type;

/**
* @param string $name
*/
public function setName(string $name)
public function setName(string $name): void
{
$this->name = $name;
}

/**
* @return string
*/
public function getName(): string
{
return $this->name;
}

/**
* @param int $type
* @noinspection PhpUnused
*/
public function setType(int $type)
public function setType(int $type): void
{
$this->type = $type;
}

/**
* @return int
* @noinspection PhpUnused
*/
public function getType(): int
{
return $this->type;
}

/**
* @param mixed $value
*/
public function setValue($value)
public function setValue(mixed $value): void
{
$this->value = $value;
}

/**
* @return mixed
*/
public function getValue()
public function getValue(): mixed
{
return $this->value;
}

/**
* @boolean
* @noinspection PhpUnused
*/
public function isMultiValue(): bool
{
Expand Down
18 changes: 3 additions & 15 deletions Classes/Domain/Result/Explanation/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,10 @@
*/
class Content
{
/**
* @var string
*/
protected $content;
public function __construct(
protected string $content,
) {}

/**
* @param string $content
*/
public function __construct(string $content)
{
$this->content = $content;
}

/**
* @return string
*/
public function getContent(): string
{
return $this->content;
Expand Down
Loading

0 comments on commit d57e8d4

Please # to comment.