From 739d883ccbf3b9c0515d399d7acb6ee5159318fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20K=C3=A4hm?= Date: Fri, 27 Oct 2023 00:52:09 +0200 Subject: [PATCH] [TASK] Drop PHP 7.2 + 7.3 support --- .editorconfig | 72 ++++++++++++++++ .github/workflows/ci.yml | 2 +- Build/phar.sh | 4 +- Classes/Domain/Result/Parser.php | 86 ++++++------------- Classes/Domain/Result/Result.php | 68 +++------------ .../Domain/Result/Timing/ItemCollection.php | 13 +-- Classes/Domain/Result/Timing/Timing.php | 46 ++-------- Tests/Domain/AbstractSolrTestCase.php | 15 ++-- .../AbstractExplanationTestCase.php | 10 +-- .../Result/Explanation/Nodes/MaxTestCase.php | 3 +- .../SummarizeFieldImpactsTestCase.php | 9 +- .../Visitors/SummarizeLeafImpactsTestCase.php | 19 ++-- Tests/Domain/Result/ParserTestCase.php | 2 + Tests/Domain/Result/Timing/ItemTestCase.php | 19 ++-- composer.json | 71 +++++++-------- 15 files changed, 182 insertions(+), 257 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9ddd933 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,72 @@ +# EditorConfig is awesome: http://EditorConfig.org +# TYPO3 Standard: https://github.com/TYPO3/coding-standards + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true + +# TS/JS-Files +[*.{ts,js}] +indent_size = 2 + +# JSON-Files +[*.json] +indent_style = tab + +# ReST-Files +[*.{rst,rst.txt}] +indent_size = 3 +max_line_length = 80 + +# YAML-Files +[*.{yaml,yml}] +indent_size = 2 + +# NEON-Files +[*.neon] +indent_size = 2 +indent_style = tab + +# package.json +[package.json] +indent_size = 2 + +# composer.json (Reason: git history in composer.json) +[composer.json] +indent_size = 2 +indent_style = space + +# TypoScript +[*.{typoscript,tsconfig}] +indent_size = 2 + +# XLF/XML-Files +[*.{xlf,xml}] +indent_style = tab + +# HTML-Files +[*.html] +indent_size = 2 +indent_style = tab + +# SQL-Files +[*.sql] +indent_style = tab +indent_size = 2 + +# .htaccess +[{_.htaccess,.htaccess}] +indent_style = tab + +# Bash scripts +[*.sh] +indent_style = space +indent_size = 2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c83202..d69e190 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - PHP: [ '7.2', '7.3', '7.4', '8.0' ] + PHP: [ '7.4', '8.0', '8.1', '8.2', '8.3' ] name: On PHP ${{ matrix.PHP }} steps: diff --git a/Build/phar.sh b/Build/phar.sh index 8b95b20..a8cc581 100755 --- a/Build/phar.sh +++ b/Build/phar.sh @@ -8,5 +8,5 @@ rm -fR .Build composer install --no-dev cd .. -wget https://github.com/clue/phar-composer/releases/download/v1.2.0/phar-composer-1.2.0.phar -O phar-composer -php phar-composer build "$ROOT_PATH/../php-solr-explain" \ No newline at end of file +wget https://github.com/clue/phar-composer/releases/download/v1.4.0/phar-composer-1.4.0.phar -O phar-composer +php phar-composer build "$ROOT_PATH/../php-solr-explain" diff --git a/Classes/Domain/Result/Parser.php b/Classes/Domain/Result/Parser.php index 6c9918a..e16f710 100644 --- a/Classes/Domain/Result/Parser.php +++ b/Classes/Domain/Result/Parser.php @@ -11,12 +11,13 @@ use DOMDocument; use DOMElement; use DOMNodeList; +use DOMText; use DOMXPath; class Parser { /** - * @var + * @var DOMNodeList|false */ protected $explainNodes; @@ -50,10 +51,6 @@ public function parse(string $xml): Result return $result; } - /** - * @param DOMXPath $resultXpath - * @return int - */ protected function extractCompleteResultCount(DOMXPath $resultXpath): int { $result = 0; @@ -66,10 +63,6 @@ protected function extractCompleteResultCount(DOMXPath $resultXpath): int return $result; } - /** - * @param DOMXPath $resultXpath - * @return int - */ protected function extractQueryTime(DOMXPath $resultXpath): int { $result = 0; @@ -82,10 +75,6 @@ protected function extractQueryTime(DOMXPath $resultXpath): int return $result; } - /** - * @param DOMXPath $resultXpath - * @return Collection - */ protected function extractDocumentCollection(DOMXPath $resultXpath): Collection { $result = new Collection(); @@ -95,8 +84,11 @@ protected function extractDocumentCollection(DOMXPath $resultXpath): Collection foreach ($documentNodes as $documentNode) { $document = new Document(); - /* @var DOMElement $documentNode */ + /* @var DOMElement|DOMText $documentNode */ foreach ($documentNode->childNodes as $fieldNode) { + if (!($fieldNode instanceof DOMElement)) { + continue; + } $this->extractDocumentFields($fieldNode, $document); } @@ -113,37 +105,31 @@ protected function extractDocumentCollection(DOMXPath $resultXpath): Collection /** * This method is used to extract the fields from the xml response * and attach them to the document object. - * - * @param $fieldNode - * @param Document $document */ - protected function extractDocumentFields($fieldNode, Document $document) + protected function extractDocumentFields(DOMElement $fieldNode, Document $document): void { - if ($fieldNode instanceof DOMElement) { - $field = new Field(); - - if ($fieldNode->nodeName == 'arr') { - //multivalue field - $value = []; - foreach ($fieldNode->childNodes as $singleField) { - $value[] = $singleField->textContent; - } - } else { - //single value field - $value = $fieldNode->textContent; + $field = new Field(); + + if ($fieldNode->nodeName == 'arr') { + //multivalue field + $value = []; + foreach ($fieldNode->childNodes as $singleField) { + $value[] = $singleField->textContent; } + } else { + //single value field + $value = $fieldNode->textContent; + } - $field->setValue($value); + $field->setValue($value); - $fieldName = $fieldNode->getAttribute('name'); - $field->setName($fieldName); + $fieldName = $fieldNode->getAttribute('name'); + $field->setName($fieldName); - $document->addField($field); - } + $document->addField($field); } /** - * @param DOMXPath $resultXPath * @return DOMNodeList|false a DOMNodeList containing all nodes matching * the given XPath expression. Any expression which does not return nodes * will return an empty DOMNodeList. The return is false if the expression @@ -158,12 +144,7 @@ protected function getExplainNodes(DOMXPath $resultXPath) return $this->explainNodes; } - /** - * @param DOMXPath $resultXPath - * @param - * @return string - */ - protected function extractExplainContent(DOMXPath $resultXPath, $documentCount): string + protected function extractExplainContent(DOMXPath $resultXPath, int $documentCount): string { $explainContent = ''; @@ -176,10 +157,6 @@ protected function extractExplainContent(DOMXPath $resultXPath, $documentCount): return $explainContent; } - /** - * @param DOMXPath $xpath - * @return Timing - */ protected function extractTiming(DOMXPath $xpath): Timing { $prepareItemCollection = new ItemCollection(); @@ -212,13 +189,9 @@ protected function extractTiming(DOMXPath $xpath): Timing } /** - * This method is used to build timing items from timing subnodes. - * - * @param DOMXPath $xpath - * @param string $nodeXPath - * @param ItemCollection $itemCollection + * This method is used to build timing items from timing sub-nodes. */ - protected function extractTimingSubNodes(DOMXPath $xpath, string $nodeXPath, ItemCollection $itemCollection) + protected function extractTimingSubNodes(DOMXPath $xpath, string $nodeXPath, ItemCollection $itemCollection): void { $nodes = $xpath->query($nodeXPath); @@ -238,11 +211,6 @@ protected function extractTimingSubNodes(DOMXPath $xpath, string $nodeXPath, Ite } } - /** - * @param DOMXPath $xpath - * @param string $path - * @return float - */ protected function getTimeFromNode(DOMXPath $xpath, string $path): float { $timeNode = $xpath->query($path); @@ -254,10 +222,6 @@ protected function getTimeFromNode(DOMXPath $xpath, string $path): float return $time; } - /** - * @param DOMXPath $xpath - * @return string - */ protected function extractParserName(DOMXPath $xpath): string { $result = ''; diff --git a/Classes/Domain/Result/Result.php b/Classes/Domain/Result/Result.php index fc88233..9208e24 100644 --- a/Classes/Domain/Result/Result.php +++ b/Classes/Domain/Result/Result.php @@ -7,115 +7,69 @@ class Result { - /** - * @var int - */ - protected $completeResultCount = 0; + protected int $completeResultCount = 0; - /** - * @var int - */ - protected $queryTime = 0; + protected int $queryTime = 0; - /** - * @var string - */ - protected $queryParser = ''; + protected string $queryParser = ''; - /** - * @var Collection - */ - protected $documentCollection; + protected ?Collection $documentCollection = null; - /** - * @var Timing - */ - protected $timing; + protected ?Timing $timing = null; - /** - * @param int $completeResultCount - * @return self - */ public function setCompleteResultCount(int $completeResultCount): Result { $this->completeResultCount = $completeResultCount; - return $this; } - /** - * @return int - */ public function getCompleteResultCount(): int { return $this->completeResultCount; } - /** - * @return int - */ public function getResultCount(): int { return $this->documentCollection->count(); } - /** - * @param int $queryTime - * @return self - */ public function setQueryTime(int $queryTime): Result { $this->queryTime = $queryTime; - return $this; } - /** - * @return int - */ public function getQueryTime(): int { return $this->queryTime; } - /** - * @param Collection $documentCollection - */ - public function setDocumentCollection(Collection $documentCollection) + public function setDocumentCollection(Collection $documentCollection): Result { $this->documentCollection = $documentCollection; + return $this; } - /** - * @return Collection - */ public function getDocumentCollection(): Collection { return $this->documentCollection; } - /** - * @param Timing $timing - */ - public function setTiming(Timing $timing) + public function setTiming(Timing $timing): Result { $this->timing = $timing; + return $this; } - /** - * @return Timing - */ public function getTiming(): ?Timing { return $this->timing; } - /** - * @param string $queryParser - */ - public function setQueryParser(string $queryParser) + public function setQueryParser(string $queryParser): Result { $this->queryParser = $queryParser; + return $this; } /** diff --git a/Classes/Domain/Result/Timing/ItemCollection.php b/Classes/Domain/Result/Timing/ItemCollection.php index 6626a0b..b7d86d0 100644 --- a/Classes/Domain/Result/Timing/ItemCollection.php +++ b/Classes/Domain/Result/Timing/ItemCollection.php @@ -10,25 +10,14 @@ */ class ItemCollection extends ArrayObject { - /** - * @var float - */ - protected $timeSpend = 0.0; + protected float $timeSpend = 0.0; - /** - * @param float $timeSpend - * @return self - */ public function setTimeSpend(float $timeSpend): ItemCollection { $this->timeSpend = $timeSpend; - return $this; } - /** - * @return float - */ public function getTimeSpend(): float { return $this->timeSpend; diff --git a/Classes/Domain/Result/Timing/Timing.php b/Classes/Domain/Result/Timing/Timing.php index 82c9cfd..1bda36a 100644 --- a/Classes/Domain/Result/Timing/Timing.php +++ b/Classes/Domain/Result/Timing/Timing.php @@ -7,74 +7,46 @@ */ class Timing { - /** - * @var ItemCollection - */ - protected $preparationItems; + protected ItemCollection $preparationItems; - /** - * @var ItemCollection - */ - protected $processingItems; + protected ItemCollection $processingItems; - /** - * @var float - */ - protected $timeSpend = 0.0; + protected float $timeSpend = 0.0; - /** - * @param ItemCollection $preparationItems - * @param ItemCollection $processingItems - */ public function __construct(ItemCollection $preparationItems, ItemCollection $processingItems) { $this->preparationItems = $preparationItems; $this->processingItems = $processingItems; } - /** - * @param float $timeSpend - */ - public function setTimeSpend(float $timeSpend) + public function setTimeSpend(float $timeSpend): Timing { $this->timeSpend = $timeSpend; + return $this; } - /** - * @return float - */ public function getTimeSpend(): float { return $this->timeSpend; } - /** - * @param ItemCollection $processingItems - */ - public function setProcessingItems(ItemCollection $processingItems) + public function setProcessingItems(ItemCollection $processingItems): Timing { $this->processingItems = $processingItems; + return $this; } - /** - * @return ItemCollection - */ public function getProcessingItems(): ItemCollection { return $this->processingItems; } - /** - * @param ItemCollection $preparationItems - */ - public function setPreparationItems(ItemCollection $preparationItems) + public function setPreparationItems(ItemCollection $preparationItems): Timing { $this->preparationItems = $preparationItems; + return $this; } - /** - * @return ItemCollection - */ public function getPreparationItems(): ItemCollection { return $this->preparationItems; diff --git a/Tests/Domain/AbstractSolrTestCase.php b/Tests/Domain/AbstractSolrTestCase.php index 2b51ad3..8df4c79 100644 --- a/Tests/Domain/AbstractSolrTestCase.php +++ b/Tests/Domain/AbstractSolrTestCase.php @@ -3,29 +3,24 @@ namespace ApacheSolrForTypo3\SolrExplain\Tests; use PHPUnit\Framework\TestCase; +use ReflectionClass; abstract class AbstractSolrTest extends TestCase { /** * Helper method to get the path of a "fixtures" folder that is relative to the current class folder. - * - * @return string */ - protected function getTestFixturePath() + protected function getTestFixturePath(): string { - $reflector = new \ReflectionClass(static::class); - $path = dirname($reflector->getFileName()) . '/Fixtures/'; - return $path; + $reflector = new ReflectionClass(static::class); + return dirname($reflector->getFileName()) . '/Fixtures/'; } /** * Helper method to get a content of a fixture that is located in the "fixtures" folder beside the * current testcase. - * - * @param $fixtureFilename - * @return string */ - protected function getFixtureContent($fixtureFilename) + protected function getFixtureContent(string $fixtureFilename): string { return file_get_contents($this->getTestFixturePath() . $fixtureFilename); } diff --git a/Tests/Domain/Result/Explanation/AbstractExplanationTestCase.php b/Tests/Domain/Result/Explanation/AbstractExplanationTestCase.php index 8c048fc..3f6905b 100644 --- a/Tests/Domain/Result/Explanation/AbstractExplanationTestCase.php +++ b/Tests/Domain/Result/Explanation/AbstractExplanationTestCase.php @@ -10,11 +10,7 @@ abstract class AbstractExplanationTestCase extends AbstractSolrTest { - /** - * @param $filename - * @return ExplainResult - */ - protected function getExplainFromFixture($filename) + protected function getExplainFromFixture(string $filename): ExplainResult { $fileContent = $this->getFixtureContent($filename . '.txt'); $content = new Content($fileContent); @@ -22,8 +18,6 @@ protected function getExplainFromFixture($filename) $parser = new Parser(); $parser->injectExplainResult(new ExplainResult()); - $explain = $parser->parse($content, $metaData); - - return $explain; + return $parser->parse($content, $metaData); } } diff --git a/Tests/Domain/Result/Explanation/Nodes/MaxTestCase.php b/Tests/Domain/Result/Explanation/Nodes/MaxTestCase.php index 34557e9..ec1f302 100644 --- a/Tests/Domain/Result/Explanation/Nodes/MaxTestCase.php +++ b/Tests/Domain/Result/Explanation/Nodes/MaxTestCase.php @@ -2,13 +2,14 @@ namespace ApacheSolrForTypo3\SolrExplain\Tests\Domain\Result\Explanation\Nodes; +use ApacheSolrForTypo3\SolrExplain\Domain\Result\Explanation\Nodes\Max; use ApacheSolrForTypo3\SolrExplain\Tests\Domain\Result\Explanation\AbstractExplanationTestCase; class MaxTestCase extends AbstractExplanationTestCase { public function testGetTieBreaker() { - $maxNode = new \ApacheSolrForTypo3\SolrExplain\Domain\Result\Explanation\Nodes\Max(); + $maxNode = new Max(); $maxNode->setContent('8.040816E-4 = (MATCH) max plus 0.7 times others of:'); self::assertEquals(0.7, $maxNode->getTieBreaker()); } diff --git a/Tests/Domain/Result/Explanation/Visitors/SummarizeFieldImpactsTestCase.php b/Tests/Domain/Result/Explanation/Visitors/SummarizeFieldImpactsTestCase.php index e324ccc..92dd69d 100644 --- a/Tests/Domain/Result/Explanation/Visitors/SummarizeFieldImpactsTestCase.php +++ b/Tests/Domain/Result/Explanation/Visitors/SummarizeFieldImpactsTestCase.php @@ -11,10 +11,7 @@ class SummarizeFieldImpactsTestCase extends AbstractExplanationTestCase { - /** - * @return ExplainResult - */ - protected function getExplain($filename) + protected function getExplain($filename): ExplainResult { $fileContent = $this->getFixtureContent($filename . '.txt'); $content = new Content($fileContent); @@ -22,9 +19,7 @@ protected function getExplain($filename) $parser = new Parser(); $parser->injectExplainResult(new ExplainResult()); - $explain = $parser->parse($content, $metaData); - - return $explain; + return $parser->parse($content, $metaData); } /** diff --git a/Tests/Domain/Result/Explanation/Visitors/SummarizeLeafImpactsTestCase.php b/Tests/Domain/Result/Explanation/Visitors/SummarizeLeafImpactsTestCase.php index a6ceb42..2bf89bc 100644 --- a/Tests/Domain/Result/Explanation/Visitors/SummarizeLeafImpactsTestCase.php +++ b/Tests/Domain/Result/Explanation/Visitors/SummarizeLeafImpactsTestCase.php @@ -1,19 +1,17 @@ getFixtureContent($filename . '.txt'); $content = new Content($fileContent); @@ -21,15 +19,10 @@ protected function getExplain($filename) $parser = new Parser(); $parser->injectExplainResult(new ExplainResult()); - $explain = $parser->parse($content, $metaData); - - return $explain; + return $parser->parse($content, $metaData); } - /** - * @return array - */ - public function leafSumFixtureNameDataProvider() + public function leafSumFixtureNameDataProvider(): array { return [ ['3.0.001'], @@ -73,7 +66,7 @@ public function leafSumFixtureNameDataProvider() } /** - * The sum for all leaf impacts in percetage should be 100%. + * The sum for all leaf impacts in percentage should be 100%. * * This testcase is used to test this for some fixture files. * diff --git a/Tests/Domain/Result/ParserTestCase.php b/Tests/Domain/Result/ParserTestCase.php index 2c43b5b..f2668cf 100644 --- a/Tests/Domain/Result/ParserTestCase.php +++ b/Tests/Domain/Result/ParserTestCase.php @@ -1,5 +1,7 @@ timingItem = new Item(); - } - /** * @test */ public function testSetTimeSpend() { - self::assertEquals(0.0, $this->timingItem->getTimeSpend()); - $this->timingItem->setTimeSpend(1.0); - self::assertEquals(1.0, $this->timingItem->getTimeSpend()); + $timingItem = new Item(); + self::assertEquals(0.0, $timingItem->getTimeSpend()); + $timingItem->setTimeSpend(1.0); + self::assertEquals(1.0, $timingItem->getTimeSpend()); } } diff --git a/composer.json b/composer.json index b3c8bf9..f2818f7 100644 --- a/composer.json +++ b/composer.json @@ -1,36 +1,37 @@ { - "name": "apache-solr-for-typo3/php-solr-explain", - "description": "PHP explain library for apache solr", - "license": "MIT", - "require": { - "php": ">=7.2.0", - "ext-dom": "*" - }, - "require-dev": { - "phpunit/phpunit": "^8 || ^9.5" - }, - "autoload": { - "psr-4": { - "ApacheSolrForTypo3\\SolrExplain\\": "Classes/" - } - }, - "autoload-dev": { - "ApacheSolrForTypo3\\SolrExplain\\Tests\\": "Tests/" - }, - "config": { - "optimize-autoloader": true, - "vendor-dir": ".Build/vendor", - "bin-dir": ".Build/bin" - }, - "authors": [ - { - "name": "Timo Hund", - "email": "timo.hund@dkd.de" - }, - { - "name": "Michael Klapper", - "email": "michael.klapper@aoemedia.de" - } - - ] -} \ No newline at end of file + "name": "apache-solr-for-typo3/php-solr-explain", + "description": "PHP explain library for apache solr", + "license": "MIT", + "require": { + "php": ">=7.4.0", + "ext-dom": "*" + }, + "require-dev": { + "phpunit/phpunit": "^8 || ^9.5" + }, + "autoload": { + "psr-4": { + "ApacheSolrForTypo3\\SolrExplain\\": "Classes/" + } + }, + "autoload-dev": { + "psr-4": { + "ApacheSolrForTypo3\\SolrExplain\\Tests\\": "Tests/" + } + }, + "config": { + "optimize-autoloader": true, + "vendor-dir": ".Build/vendor", + "bin-dir": ".Build/bin" + }, + "authors": [ + { + "name": "Timo Hund", + "email": "timo.hund@dkd.de" + }, + { + "name": "Michael Klapper", + "email": "michael.klapper@aoemedia.de" + } + ] +}