Skip to content

Commit

Permalink
Apply PHP 7.1 and PHP 7.2 features (tomasnorre#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored and tomasnorre committed Dec 7, 2019
1 parent 717c86f commit 8dfe249
Show file tree
Hide file tree
Showing 63 changed files with 337 additions and 219 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ nbproject
.Build
composer.lock
.php_cs.cache

var/log
10 changes: 6 additions & 4 deletions Classes/Api/CrawlerApi.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace AOE\Crawler\Api;

/***************************************************************
Expand Down Expand Up @@ -82,7 +84,7 @@ public function __construct()
* @param int $id
* @throws \Exception
*/
public function overwriteSetId(int $id)
public function overwriteSetId(int $id): void
{
$this->findCrawler()->setID = $id;
}
Expand All @@ -93,7 +95,7 @@ public function overwriteSetId(int $id)
*
* @param array $allowedConfigurations
*/
public function setAllowedConfigurations(array $allowedConfigurations)
public function setAllowedConfigurations(array $allowedConfigurations): void
{
$this->allowedConfigurations = $allowedConfigurations;
}
Expand Down Expand Up @@ -142,7 +144,7 @@ protected function findCrawler()
*
* @param int $uid uid
*/
public function addPageToQueue($uid)
public function addPageToQueue($uid): void
{
$uid = intval($uid);
//non timed elements will be added with timestamp 0
Expand Down Expand Up @@ -179,7 +181,7 @@ protected function filterUnallowedConfigurations($configurations)
* @throws \Exception
* @return void
*/
public function addPageToQueueTimed($uid, $time)
public function addPageToQueueTimed($uid, $time): void
{
$uid = intval($uid);
$time = intval($time);
Expand Down
4 changes: 3 additions & 1 deletion Classes/Backend/BackendModule.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace AOE\Crawler\Backend;

/***************************************************************
Expand Down Expand Up @@ -741,7 +743,7 @@ protected function processOverviewAction()

try {
$this->handleProcessOverviewActions();
} catch (\Exception $e) {
} catch (\Throwable $e) {
$this->addErrorMessage($e->getMessage());
}

Expand Down
3 changes: 2 additions & 1 deletion Classes/Command/BuildQueueCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace AOE\Crawler\Command;

/***************************************************************
Expand Down Expand Up @@ -115,7 +116,7 @@ protected function configure(): void
* $ typo3 crawler:buildQueue --page 7 --depth 0 --conf defaultConfiguration --mode queue --number 4
*
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): void
{
$mode = $input->getOption('mode');

Expand Down
3 changes: 2 additions & 1 deletion Classes/Command/FlushQueueCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace AOE\Crawler\Command;

/***************************************************************
Expand Down Expand Up @@ -85,7 +86,7 @@ protected function configure(): void
* $ typo3 crawler:flushQueue --mode pending
*
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): void
{
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);

Expand Down
5 changes: 3 additions & 2 deletions Classes/Command/ProcessQueueCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace AOE\Crawler\Command;

/***************************************************************
Expand Down Expand Up @@ -45,7 +46,7 @@ class ProcessQueueCommand extends Command
public const CLI_STATUS_ABORTED = 4; //instance didn't finish
public const CLI_STATUS_POLLABLE_PROCESSED = 8;

protected function configure()
protected function configure(): void
{
$this->setHelp(
'Crawler Command - Crawling the URLs from the queue' . chr(10) . chr(10) .
Expand Down Expand Up @@ -112,7 +113,7 @@ public function execute(InputInterface $input, OutputInterface $output)
try {
// Run process:
$result = $crawlerController->CLI_run($countInARun, $sleepTime, $sleepAfterFinish);
} catch (\Exception $e) {
} catch (\Throwable $e) {
$output->writeln('<warning>' . get_class($e) . ': ' . $e->getMessage() . '</warning>');
$result = self::CLI_STATUS_ABORTED;
}
Expand Down
2 changes: 2 additions & 0 deletions Classes/Configuration/ExtensionConfigurationProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace AOE\Crawler\Configuration;

/***************************************************************
Expand Down
1 change: 1 addition & 0 deletions Classes/ContextMenu/ItemProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace AOE\Crawler\ContextMenu;

/***************************************************************
Expand Down
40 changes: 21 additions & 19 deletions Classes/Controller/CrawlerController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace AOE\Crawler\Controller;

/***************************************************************
Expand Down Expand Up @@ -214,7 +216,7 @@ public function getAccessMode()
/**
* @param string $accessMode
*/
public function setAccessMode($accessMode)
public function setAccessMode($accessMode): void
{
$this->accessMode = $accessMode;
}
Expand All @@ -225,7 +227,7 @@ public function setAccessMode($accessMode)
* @param bool $disabled (optional, defaults to true)
* @return void
*/
public function setDisabled($disabled = true)
public function setDisabled($disabled = true): void
{
if ($disabled) {
GeneralUtility::writeFile($this->processFilename, '');
Expand All @@ -251,7 +253,7 @@ public function getDisabled()
*
* @return void
*/
public function setProcessFilename($filenameWithPath)
public function setProcessFilename($filenameWithPath): void
{
$this->processFilename = $filenameWithPath;
}
Expand Down Expand Up @@ -294,7 +296,7 @@ public function __construct()
$this->extensionSettings['processLimit'] = MathUtility::forceIntegerInRange($this->extensionSettings['processLimit'], 1, 99, 1);
$this->maximumUrlsToCompile = MathUtility::forceIntegerInRange($this->extensionSettings['maxCompileUrls'], 1, 1000000000, 10000);
}

/**
* @return BackendUserAuthentication
*/
Expand All @@ -312,7 +314,7 @@ private function getBackendUser()
* @param array $extensionSettings
* @return void
*/
public function setExtensionSettings(array $extensionSettings)
public function setExtensionSettings(array $extensionSettings): void
{
$this->extensionSettings = $extensionSettings;
}
Expand Down Expand Up @@ -591,7 +593,7 @@ public function getUrlsForPageId($pageId)
$pidOnlyList = implode(',', GeneralUtility::trimExplode(',', $subCfg['pidsOnly'], true));

// process configuration if it is not page-specific or if the specific page is the current page:
if (!strcmp($subCfg['pidsOnly'], '') || GeneralUtility::inList($pidOnlyList, $pageId)) {
if (!strcmp((string) $subCfg['pidsOnly'], '') || GeneralUtility::inList($pidOnlyList, $pageId)) {

// Explode, process etc.:
$res[$key] = [];
Expand Down Expand Up @@ -800,7 +802,7 @@ public function expandParameters($paramArray, $pid)
$subparts = GeneralUtility::trimExplode(';', $pV);
$subpartParams = [];
foreach ($subparts as $spV) {
list($pKey, $pVal) = GeneralUtility::trimExplode(':', $spV);
[$pKey, $pVal] = GeneralUtility::trimExplode(':', $spV);
$subpartParams[$pKey] = $pVal;
}

Expand All @@ -809,8 +811,8 @@ public function expandParameters($paramArray, $pid)
$lookUpPid = isset($subpartParams['_PID']) ? intval($subpartParams['_PID']) : intval($pid);
$recursiveDepth = isset($subpartParams['_RECURSIVE']) ? intval($subpartParams['_RECURSIVE']) : 0;
$pidField = isset($subpartParams['_PIDFIELD']) ? trim($subpartParams['_PIDFIELD']) : 'pid';
$where = isset($subpartParams['_WHERE']) ? $subpartParams['_WHERE'] : '';
$addTable = isset($subpartParams['_ADDTABLE']) ? $subpartParams['_ADDTABLE'] : '';
$where = $subpartParams['_WHERE'] ?? '';
$addTable = $subpartParams['_ADDTABLE'] ?? '';

$fieldName = $subpartParams['_FIELD'] ? $subpartParams['_FIELD'] : 'uid';
if ($fieldName === 'uid' || $GLOBALS['TCA'][$subpartParams['_TABLE']]['columns'][$fieldName]) {
Expand All @@ -824,7 +826,7 @@ public function expandParameters($paramArray, $pid)
} else {
$pidArray = [(string)$lookUpPid];
}

$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class));
Expand Down Expand Up @@ -915,7 +917,7 @@ public function compileUrls($paramArray, array $urls)
$newUrls = [];
foreach ($urls as $url) {
foreach ($valueSet as $val) {
$newUrls[] = $url . (strcmp($val, '') ? '&' . rawurlencode($varName) . '=' . rawurlencode($val) : '');
$newUrls[] = $url . (strcmp((string) $val, '') ? '&' . rawurlencode($varName) . '=' . rawurlencode((string) $val) : '');

if (count($newUrls) > $this->maximumUrlsToCompile) {
break;
Expand Down Expand Up @@ -1046,9 +1048,9 @@ public function getLogEntriesForSetId($set_id, $filter = '', $doFlush = false, $
* @param string $where SQL related filter for the entries which should be removed
* @return void
*/
protected function flushQueue($where = '')
protected function flushQueue($where = ''): void
{
$realWhere = strlen($where) > 0 ? $where : '1=1';
$realWhere = strlen((string) $where) > 0 ? $where : '1=1';

$queryBuilder = $this->getQueryBuilder($this->tableName);

Expand Down Expand Up @@ -1091,7 +1093,7 @@ protected function flushQueue($where = '')
* @param integer $schedule Time at which to activate
* @return void
*/
public function addQueueEntry_callBack($setId, $params, $callBack, $page_id = 0, $schedule = 0)
public function addQueueEntry_callBack($setId, $params, $callBack, $page_id = 0, $schedule = 0): void
{
if (!is_array($params)) {
$params = [];
Expand Down Expand Up @@ -1252,7 +1254,7 @@ protected function getDuplicateRowsIfExist($tstamp, $fieldArray)
;

$statement = $queryBuilder->execute();

while ($row = $statement->fetch()) {
$rows[] = $row['qid'];
}
Expand Down Expand Up @@ -1537,7 +1539,7 @@ public function expandExcludeString($excludeString)
$excludeParts = GeneralUtility::trimExplode(',', $excludeString);

foreach ($excludeParts as $excludePart) {
list($pid, $depth) = GeneralUtility::trimExplode('+', $excludePart);
[$pid, $depth] = GeneralUtility::trimExplode('+', $excludePart);

// default is "page only" = "depth=0"
if (empty($depth)) {
Expand Down Expand Up @@ -1819,7 +1821,7 @@ public function CLI_run($countInARun, $sleepTime, $sleepAfterFinish)
*
* @return void
*/
public function CLI_runHooks()
public function CLI_runHooks(): void
{
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['cli_hooks'] ?? [] as $objRef) {
$hookObj = GeneralUtility::makeInstance($objRef);
Expand Down Expand Up @@ -2007,7 +2009,7 @@ public function CLI_buildProcessId()
*
* @param string $msg the message
*/
public function CLI_debug($msg)
public function CLI_debug($msg): void
{
if ((int)$this->extensionSettings['processDebug']) {
echo $msg . "\n";
Expand All @@ -2022,7 +2024,7 @@ public function CLI_debug($msg)
*
* @return void
*/
public function cleanUpOldQueueEntries()
public function cleanUpOldQueueEntries(): void
{
$processedAgeInSeconds = $this->extensionSettings['cleanUpProcessedAge'] * 86400; // 24*60*60 Seconds in 24 hours
$scheduledAgeInSeconds = $this->extensionSettings['cleanUpScheduledAge'] * 86400;
Expand Down
1 change: 1 addition & 0 deletions Classes/CrawlStrategy/CallbackExecutionStrategy.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace AOE\Crawler\CrawlStrategy;

/*
Expand Down
1 change: 1 addition & 0 deletions Classes/CrawlStrategy/GuzzleExecutionStrategy.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace AOE\Crawler\CrawlStrategy;

/*
Expand Down
3 changes: 2 additions & 1 deletion Classes/CrawlStrategy/SubProcessExecutionStrategy.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace AOE\Crawler\CrawlStrategy;

/*
Expand Down Expand Up @@ -39,7 +40,7 @@ class SubProcessExecutionStrategy implements LoggerAwareInterface
*/
protected $extensionSettings;

public function __construct(ExtensionConfigurationProvider $configurationProvider = null)
public function __construct(?ExtensionConfigurationProvider $configurationProvider = null)
{
$configurationProvider = $configurationProvider ?? GeneralUtility::makeInstance(ExtensionConfigurationProvider::class);
$settings = $configurationProvider->getExtensionConfiguration();
Expand Down
Loading

0 comments on commit 8dfe249

Please sign in to comment.