diff --git a/component/admin/src/Controller/DisplayController.php b/component/admin/src/Controller/DisplayController.php index c707276..98e6b0f 100644 --- a/component/admin/src/Controller/DisplayController.php +++ b/component/admin/src/Controller/DisplayController.php @@ -24,7 +24,7 @@ class DisplayController extends BaseController { - public function display($cachable = false, $urlparams = false) + public function display($cachable = false, $urlparams = []) { $input = $this->input; $view = $input->getCmd('view', 'blocklist'); @@ -32,7 +32,7 @@ public function display($cachable = false, $urlparams = false) $pluginInstalled = $this->checkWhetherPluginInstalled(); if (!$pluginInstalled) { - return; + return $this; } $this->warnIfAdminUserExists(); $this->warnIfHtAccessNotWorking(); @@ -43,7 +43,7 @@ public function display($cachable = false, $urlparams = false) $this->warnIfUnblockLinksNeedLiveSite(); } $input->set('view', $view); - parent::display($cachable); + return parent::display($cachable); } public function warnIfAdminUserExists() diff --git a/component/admin/src/Controller/HtblockController.php b/component/admin/src/Controller/HtblockController.php index 233c5ab..47028a9 100644 --- a/component/admin/src/Controller/HtblockController.php +++ b/component/admin/src/Controller/HtblockController.php @@ -119,5 +119,6 @@ public function cancel($key = null) $this->setRedirect( Route::_('index.php?option=com_bfstop&view=htblocklist', false) ); + return true; } } diff --git a/component/admin/src/Model/HtblockModel.php b/component/admin/src/Model/HtblockModel.php index 5e67af1..01f104f 100644 --- a/component/admin/src/Model/HtblockModel.php +++ b/component/admin/src/Model/HtblockModel.php @@ -17,7 +17,7 @@ class HtblockModel extends AdminModel { public function getItem($pk = null) { - return array('ipaddress' => '0.0.0.0'); + return (object) array('ipaddress' => '0.0.0.0'); } public function getForm($data = array(), $loadData = true) diff --git a/component/admin/src/View/Settings/HtmlView.php b/component/admin/src/View/Settings/HtmlView.php index 4c582f6..ce933dd 100644 --- a/component/admin/src/View/Settings/HtmlView.php +++ b/component/admin/src/View/Settings/HtmlView.php @@ -87,6 +87,6 @@ protected function addToolbar() } ToolbarHelper::cancel('settings.cancel'); ToolbarHelper::custom('settings.testNotify', 'preview', '', - 'COM_BFSTOP_TEST_NOTIFICATION', false, false); + 'COM_BFSTOP_TEST_NOTIFICATION', false); } } diff --git a/component/site/src/Controller/DisplayController.php b/component/site/src/Controller/DisplayController.php index b969063..12d17f9 100644 --- a/component/site/src/Controller/DisplayController.php +++ b/component/site/src/Controller/DisplayController.php @@ -14,8 +14,8 @@ class DisplayController extends BaseController { - public function display($cachable = false, $urlparams = false) + public function display($cachable = false, $urlparams = []) { - parent::display($cachable, $urlparams); + return parent::display($cachable, $urlparams); } } diff --git a/library/src/Helper/DnsHelper.php b/library/src/Helper/DnsHelper.php index cc61799..8f2a9a0 100644 --- a/library/src/Helper/DnsHelper.php +++ b/library/src/Helper/DnsHelper.php @@ -105,7 +105,9 @@ public static function buildQuery($id, $name) /** * Reads the (possibly compressed) domain name at $offset of $packet. * - * @param int $next set to the offset after the name where it is stored + * @param string $packet + * @param int $offset + * @param int|null $next set to the offset after the name where it is stored * @return string|null null if the name is malformed */ private static function readName($packet, $offset, &$next) diff --git a/library/src/Helper/LoggerHelper.php b/library/src/Helper/LoggerHelper.php index 850871d..39e15e4 100644 --- a/library/src/Helper/LoggerHelper.php +++ b/library/src/Helper/LoggerHelper.php @@ -29,12 +29,9 @@ class LoggerHelper // disk (a visitor can make the plugin log by failing logins) public const MaxLogFileBytes = self::DefaultMaxSizeMB * 1048576; - private $maxBytes; - public function __construct($log_level, $maxBytes = self::MaxLogFileBytes) { $this->log_level = $log_level; - $this->maxBytes = $maxBytes; $priorities = Log::ALL; if ($log_level > self::Disabled) { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 78f3a71..bb285d2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -12,24 +12,6 @@ parameters: count: 1 path: component/admin/src/Controller/BlocklistController.php - - - message: '#^Default value of the parameter \#2 \$urlparams \(false\) of method Codeling\\Component\\Bfstop\\Administrator\\Controller\\DisplayController\:\:display\(\) is incompatible with type array\.$#' - identifier: parameter.defaultValue - count: 1 - path: component/admin/src/Controller/DisplayController.php - - - - message: '#^Method Codeling\\Component\\Bfstop\\Administrator\\Controller\\DisplayController\:\:display\(\) should return static\(Codeling\\Component\\Bfstop\\Administrator\\Controller\\DisplayController\) but empty return statement found\.$#' - identifier: return.empty - count: 1 - path: component/admin/src/Controller/DisplayController.php - - - - message: '#^Method Codeling\\Component\\Bfstop\\Administrator\\Controller\\DisplayController\:\:display\(\) should return static\(Codeling\\Component\\Bfstop\\Administrator\\Controller\\DisplayController\) but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: component/admin/src/Controller/DisplayController.php - - message: '#^Cannot call method purgeOlderThan\(\) on bool\|Joomla\\CMS\\MVC\\Model\\BaseDatabaseModel\.$#' identifier: method.nonObject @@ -48,12 +30,6 @@ parameters: count: 1 path: component/admin/src/Controller/HtblockController.php - - - message: '#^Method Codeling\\Component\\Bfstop\\Administrator\\Controller\\HtblockController\:\:cancel\(\) should return bool but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: component/admin/src/Controller/HtblockController.php - - message: '#^Cannot call method unblock\(\) on bool\|Joomla\\CMS\\MVC\\Model\\BaseDatabaseModel\.$#' identifier: method.nonObject @@ -102,12 +78,6 @@ parameters: count: 1 path: component/admin/src/Model/HtblockModel.php - - - message: '#^Method Codeling\\Component\\Bfstop\\Administrator\\Model\\HtblockModel\:\:getItem\(\) should return stdClass\|false but returns array\{ipaddress\: ''0\.0\.0\.0''\}\.$#' - identifier: return.type - count: 1 - path: component/admin/src/Model/HtblockModel.php - - message: '#^Call to an undefined method Joomla\\CMS\\Application\\CMSApplicationInterface\:\:getUserState\(\)\.$#' identifier: method.notFound @@ -264,12 +234,6 @@ parameters: count: 1 path: component/admin/src/View/Settings/HtmlView.php - - - message: '#^Parameter \#6 \$formId of static method Joomla\\CMS\\Toolbar\\ToolbarHelper\:\:custom\(\) expects string\|null, false given\.$#' - identifier: argument.type - count: 1 - path: component/admin/src/View/Settings/HtmlView.php - - message: '#^Call to an undefined method Joomla\\CMS\\Application\\CMSApplicationInterface\:\:getDocument\(\)\.$#' identifier: method.notFound @@ -294,18 +258,6 @@ parameters: count: 1 path: component/admin/src/View/Usernamestats/HtmlView.php - - - message: '#^Default value of the parameter \#2 \$urlparams \(false\) of method Codeling\\Component\\Bfstop\\Site\\Controller\\DisplayController\:\:display\(\) is incompatible with type array\.$#' - identifier: parameter.defaultValue - count: 1 - path: component/site/src/Controller/DisplayController.php - - - - message: '#^Method Codeling\\Component\\Bfstop\\Site\\Controller\\DisplayController\:\:display\(\) should return static\(Codeling\\Component\\Bfstop\\Site\\Controller\\DisplayController\) but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: component/site/src/Controller/DisplayController.php - - message: '#^Call to an undefined method Joomla\\CMS\\Application\\CMSApplicationInterface\:\:allowCache\(\)\.$#' identifier: method.notFound @@ -336,24 +288,6 @@ parameters: count: 1 path: library/src/Helper/ApiHelper.php - - - message: '#^Parameter &\$next by\-ref type of method Codeling\\Library\\Bfstop\\Helper\\DnsHelper\:\:readName\(\) expects int, \(float\|int\) given\.$#' - identifier: parameterByRef.type - count: 2 - path: library/src/Helper/DnsHelper.php - - - - message: '#^Parameter &\$next by\-ref type of method Codeling\\Library\\Bfstop\\Helper\\DnsHelper\:\:readName\(\) expects int, null given\.$#' - identifier: parameterByRef.type - count: 1 - path: library/src/Helper/DnsHelper.php - - - - message: '#^Property Codeling\\Library\\Bfstop\\Helper\\LoggerHelper\:\:\$maxBytes is never read, only written\.$#' - identifier: property.onlyWritten - count: 1 - path: library/src/Helper/LoggerHelper.php - - message: '#^Call to an undefined method Joomla\\Database\\QueryInterface\:\:returning\(\)\.$#' identifier: method.notFound diff --git a/tests/Integration/LoggerHelperTest.php b/tests/Integration/LoggerHelperTest.php index 0511115..5cf3f5a 100644 --- a/tests/Integration/LoggerHelperTest.php +++ b/tests/Integration/LoggerHelperTest.php @@ -105,28 +105,33 @@ private static function header() public function testPruneRemovesOldEntriesOnly() { + // each entry is built once: entry() reads the clock, so building the + // expected one again could land in the next second + $recent = self::entry(27, 'recent'); + $new = self::entry(0, 'new'); file_put_contents($this->file, self::header(). self::entry(40, 'ancient'). "continuation of the ancient entry\n". self::entry(29, 'old'). - self::entry(27, 'recent'). + $recent. "continuation of the recent entry\n". - self::entry(0, 'new')); + $new); $this->assertSame(2, LoggerHelper::pruneByAge(28)); $this->assertSame(self::header(). - self::entry(27, 'recent'). + $recent. "continuation of the recent entry\n". - self::entry(0, 'new'), + $new, file_get_contents($this->file)); } public function testPruneAlsoCoversThePreviousGeneration() { file_put_contents($this->rotated, self::header().self::entry(100, 'ancient')); - file_put_contents($this->file, self::header().self::entry(1, 'new')); + $new = self::entry(1, 'new'); + file_put_contents($this->file, self::header().$new); $this->assertSame(1, LoggerHelper::pruneByAge(28)); $this->assertSame(self::header(), file_get_contents($this->rotated)); - $this->assertSame(self::header().self::entry(1, 'new'), file_get_contents($this->file)); + $this->assertSame(self::header().$new, file_get_contents($this->file)); } public function testPruneWithoutAgeKeepsEverything()