Skip to content

Commit

Permalink
[TASK] Replace Scrutinizer analysis by PHPStan :: Level 3
Browse files Browse the repository at this point in the history
  • Loading branch information
dkd-kaehm committed Aug 15, 2023
1 parent f16e4bd commit 640d234
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 125 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ jobs:
echo "Current Size of EXT:tika build Artefacts: " \
&& sudo du -sh $CI_BUILD_DIRECTORY/ \
&& sudo du -sh $CI_BUILD_DIRECTORY/*
-
name: Upload code coverage to Scrutinizer
run: |
ocular code-coverage:upload --format=php-clover coverage.unit.clover
ocular code-coverage:upload --format=php-clover coverage.integration.clover
publish:
name: Publish new version to TER
Expand Down
64 changes: 0 additions & 64 deletions .scrutinizer.yml

This file was deleted.

5 changes: 2 additions & 3 deletions Build/Test/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ export COMPOSER_NO_INTERACTION=1
# Install build tools
echo "Install build tools: "
if ! composer global require \
sclable/xml-lint \
scrutinizer/ocular
sclable/xml-lint
then
echo "The build tools(sclable/xml-lint, scrutinizer/ocular) could not be installed. Please fix this issue."
echo "The build tools(sclable/xml-lint) could not be installed. Please fix this issue."
exit 1
fi

Expand Down
16 changes: 16 additions & 0 deletions Build/Test/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
includes:
- %rootDir%/../phpstan-phpunit/extension.neon

parameters:
level: 3
treatPhpDocTypesAsCertain: false

bootstrapFiles:
- %rootDir%/../../apache-solr-for-typo3/solr/Build/Test/phpstan-constants.php

paths:
- %currentWorkingDirectory%/Classes
- %currentWorkingDirectory%/Tests

ignoreErrors:
- '#^Variable \$value on left side of \?\? always exists and is not nullable.#'
18 changes: 6 additions & 12 deletions Classes/Controller/Backend/PreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use Psr\Http\Message\ServerRequestInterface;
use Throwable;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
Expand All @@ -38,8 +37,6 @@
class PreviewController
{
/**
* @param ServerRequestInterface $request
* @return string|Response
* @throws ClientExceptionInterface
* @throws Throwable
*/
Expand All @@ -57,20 +54,20 @@ public function previewAction(ServerRequestInterface $request): ResponseInterfac

$tikaService = $this->getConfiguredTikaService();
$metadata = $tikaService->extractMetaData(
/** @scrutinizer ignore-type because checked in {@link \ApacheSolrForTypo3\Tika\ContextMenu\Preview::canHandle()} */
/** not real static-analysis error, because checked in {@link \ApacheSolrForTypo3\Tika\ContextMenu\Preview::canHandle()} */
$file
);
$content = $tikaService->extractText(
/** @scrutinizer ignore-type because checked in {@link \ApacheSolrForTypo3\Tika\ContextMenu\Preview::canHandle()} */
/** not real static-analysis error, because checked in {@link \ApacheSolrForTypo3\Tika\ContextMenu\Preview::canHandle()} */
$file
);

try {
$language = $tikaService->detectLanguageFromFile(
/** @scrutinizer ignore-type because checked in {@link \ApacheSolrForTypo3\Tika\ContextMenu\Preview::canHandle()} */
/** not real static-analysis error, because checked in {@link \ApacheSolrForTypo3\Tika\ContextMenu\Preview::canHandle()} */
$file
);
} catch (Throwable $e) {
} catch (Throwable) {
$language = 'not detectable';
}

Expand All @@ -85,10 +82,7 @@ public function previewAction(ServerRequestInterface $request): ResponseInterfac
return $response;
}

/**
* @return AppService|ServerService|SolrCellService
*/
protected function getConfiguredTikaService(): AbstractService
protected function getConfiguredTikaService(): AbstractService|AppService|ServerService|SolrCellService
{
return ServiceFactory::getConfiguredTika();
}
Expand All @@ -103,7 +97,7 @@ protected function getFileResourceFactory(): ResourceFactory
*/
protected function getInitializedPreviewView(): StandaloneView
{
/** @var $view StandaloneView */
/** @var StandaloneView $view */
$view = GeneralUtility::makeInstance(StandaloneView::class);
$templatePathAndFile = 'EXT:tika/Resources/Private/Templates/Backend/Preview.html';
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templatePathAndFile));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

use ApacheSolrForTypo3\Solr\Controller\Backend\Search\AbstractModuleController;
use ApacheSolrForTypo3\Solr\Domain\Site\Exception\UnexpectedTYPO3SiteInitializationException;
use ApacheSolrForTypo3\Tika\Service\Tika\AbstractService;
use ApacheSolrForTypo3\Tika\Service\Tika\AppService;
use ApacheSolrForTypo3\Tika\Service\Tika\ServerService;
use ApacheSolrForTypo3\Tika\Service\Tika\ServiceFactory;
Expand All @@ -46,7 +45,7 @@ class TikaControlPanelModuleController extends AbstractModuleController
{
protected array $tikaConfiguration = [];

protected AbstractService|AppService|ServerService|SolrCellService $tikaService;
protected ServerService|AppService|SolrCellService $tikaService;

/**
* Can be used in the test context to mock a {@link view}.
Expand All @@ -68,7 +67,7 @@ public function overwriteModuleTemplate(ModuleTemplate $moduleTemplate): void
$this->moduleTemplate = $moduleTemplate;
}

public function setTikaService(AbstractService $tikaService): void
public function setTikaService(ServerService|AppService|SolrCellService $tikaService): void
{
$this->tikaService = $tikaService;
}
Expand All @@ -80,8 +79,6 @@ public function setTikaService(AbstractService $tikaService): void
* @throws ExtensionConfigurationExtensionNotConfiguredException
* @throws ExtensionConfigurationPathDoesNotExistException
* @throws UnexpectedTYPO3SiteInitializationException
*
* @noinspection PhpUnused
*/
protected function initializeAction(): void
{
Expand Down Expand Up @@ -149,6 +146,7 @@ public function indexAction(): ResponseInterface

/**
* Starts the Tika server
*
* @noinspection PhpUnused
*/
public function startServerAction(): ResponseInterface
Expand All @@ -169,6 +167,7 @@ public function startServerAction(): ResponseInterface

/**
* Stops the Tika server
*
* @noinspection PhpUnused
*/
public function stopServerAction(): ResponseInterface
Expand Down
2 changes: 1 addition & 1 deletion Classes/Report/TikaStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ protected function getSolrCellConfigurationStatus(): Status
$solr = $this->getSolrConnectionFromTikaConfiguration();

// try to extract text & meta data
/** @var $query Query */
/** @var Query $query */
$query = GeneralUtility::makeInstance(Query::class);
$query->setExtractOnly(true);
$query->setFile(ExtensionManagementUtility::extPath('tika', 'ext_emconf.php'));
Expand Down
26 changes: 5 additions & 21 deletions Classes/Service/Extractor/AbstractExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LogLevel;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
use TYPO3\CMS\Core\Resource\Index\ExtractorInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand All @@ -34,27 +36,18 @@ abstract class AbstractExtractor implements ExtractorInterface, LoggerAwareInter
{
use LoggerAwareTrait;

/**
* @var array
*/
protected array $configuration;

/**
* Priority in handling extraction
*
* @var int
*/
protected int $priority = 0;

/**
* @var SizeValidator
*/
protected SizeValidator $fileSizeValidator;

/**
* Constructor
* @param array|null $extensionConfiguration
* @param SizeValidator|null $fileSizeValidator
* @throws ExtensionConfigurationPathDoesNotExistException
* @throws ExtensionConfigurationExtensionNotConfiguredException
*/
public function __construct(array $extensionConfiguration = null, SizeValidator $fileSizeValidator = null)
{
Expand All @@ -67,8 +60,6 @@ public function __construct(array $extensionConfiguration = null, SizeValidator

/**
* Returns an array of supported file types
*
* @return array
*/
public function getFileTypeRestrictions(): array
{
Expand All @@ -87,8 +78,6 @@ public function getDriverRestrictions(): array

/**
* Returns the data priority of the extraction Service.
*
* @return int
*/
public function getPriority(): int
{
Expand All @@ -97,8 +86,6 @@ public function getPriority(): int

/**
* Returns the execution priority of the extraction Service
*
* @return int
*/
public function getExecutionPriority(): int
{
Expand All @@ -107,16 +94,13 @@ public function getExecutionPriority(): int

/**
* Logs a message and optionally data to log file
*
* @param string $message Log message
* @param array $data Optional data
*/
protected function log(string $message, array $data = []): void
{
if (!$this->configuration['logging']) {
return;
}
$this->logger->/** @scrutinizer ignore-call */ log(
$this->logger->log(
LogLevel::DEBUG, // Previous value 0
$message,
$data
Expand Down
10 changes: 5 additions & 5 deletions Classes/Service/Tika/AppService.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function initializeService(): void
*/
public function getTikaVersion(): string
{
$tikaCommand = /** @scrutinizer ignore-type */ CommandUtility::getCommand('java')
$tikaCommand = CommandUtility::getCommand('java')
. ' -Dfile.encoding=UTF8' // forces UTF8 output
. $this->getAdditionalCommandOptions()
. ' -jar ' . escapeshellarg(FileUtility::getAbsoluteFilePath($this->configuration['tikaPath']))
Expand All @@ -80,7 +80,7 @@ public function extractText(FileInterface $file): string
{
$localTempFilePath = $file->getForLocalProcessing(false);
$tikaCommand = ShellUtility::getLanguagePrefix()
. /** @scrutinizer ignore-type */ CommandUtility::getCommand('java')
. CommandUtility::getCommand('java')
. ' -Dfile.encoding=UTF8' // forces UTF8 output
. $this->getAdditionalCommandOptions()
. ' -jar ' . escapeshellarg(FileUtility::getAbsoluteFilePath($this->configuration['tikaPath']))
Expand Down Expand Up @@ -111,7 +111,7 @@ public function extractMetaData(FileInterface $file): array
{
$localTempFilePath = $file->getForLocalProcessing(false);
$tikaCommand = ShellUtility::getLanguagePrefix()
. /** @scrutinizer ignore-type */ CommandUtility::getCommand('java')
. CommandUtility::getCommand('java')
. ' -Dfile.encoding=UTF8'
. $this->getAdditionalCommandOptions()
. ' -jar ' . escapeshellarg(FileUtility::getAbsoluteFilePath($this->configuration['tikaPath']))
Expand Down Expand Up @@ -177,7 +177,7 @@ public function detectLanguageFromString(string $input): string
protected function detectLanguageFromLocalFile(string $localFilePath): string
{
$tikaCommand = ShellUtility::getLanguagePrefix()
. /** @scrutinizer ignore-type */ CommandUtility::getCommand('java')
. CommandUtility::getCommand('java')
. ' -Dfile.encoding=UTF8'
. $this->getAdditionalCommandOptions()
. ' -jar ' . escapeshellarg(FileUtility::getAbsoluteFilePath($this->configuration['tikaPath']))
Expand Down Expand Up @@ -315,7 +315,7 @@ public function isAvailable(): bool
protected function getMimeTypeOutputFromTikaJar(): string
{
$tikaCommand = ShellUtility::getLanguagePrefix()
. /** @scrutinizer ignore-type */ CommandUtility::getCommand('java')
. CommandUtility::getCommand('java')
. ' -Dfile.encoding=UTF8'
. $this->getAdditionalCommandOptions()
. ' -jar ' . escapeshellarg(FileUtility::getAbsoluteFilePath($this->configuration['tikaPath']))
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Apache Tika for TYPO3

[![Build Status](https://github.com/TYPO3-Solr/ext-tika/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/TYPO3-Solr/ext-tika/actions?query=branch:release-10.0.x)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/TYPO3-Solr/ext-tika/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/TYPO3-Solr/ext-tika/?branch=main)
[![Code Coverage](https://scrutinizer-ci.com/g/TYPO3-Solr/ext-tika/badges/coverage.png?b=main)](https://scrutinizer-ci.com/g/TYPO3-Solr/ext-tika/?branch=main)
[![Latest Stable Version](https://poser.pugx.org/apache-solr-for-typo3/tika/v/stable)](https://packagist.org/packages/apache-solr-for-typo3/tika)
[![License](https://poser.pugx.org/apache-solr-for-typo3/tika/license)](https://packagist.org/packages/apache-solr-for-typo3/tika)
[![Total Downloads](http://poser.pugx.org/apache-solr-for-typo3/tika/downloads)](https://packagist.org/packages/apache-solr-for-typo3/tika)
Expand Down
2 changes: 1 addition & 1 deletion Tests/Integration/Service/Tika/AppServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function canParseMimeList(): void
{
$fixtureContent = file_get_contents(__DIR__ . '/Fixtures/mimeOut');

/** @var $service AppService|MockObject */
/** @var AppService|MockObject $service */
$service = $this->getMockBuilder(AppService::class)
->disableOriginalConstructor()
->onlyMethods(['getMimeTypeOutputFromTikaJar'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ protected function createDriverFixture(
array $driverConfiguration = [],
array $mockedDriverMethods = []
): LocalDriver {
/** @var LocalDriver $driver */
$mockedDriverMethods[] = 'isPathValid';
/** @var LocalDriver|MockObject $driver */
$driver = $this->getAccessibleMock(
LocalDriver::class,
$mockedDriverMethods,
Expand Down
Loading

0 comments on commit 640d234

Please sign in to comment.