From 71d5282858cbb8d9f7b0ecb0423b954e6c7705bd Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 15:45:28 +0100 Subject: [PATCH 01/28] Refactor constructors and constants in AdminActivityLog controllers List of changes: - Replaced protected properties with private properties in constructors for enhanced encapsulation. - Updated constants to include the `string` type declaration for better clarity and type safety. - Removed redundant constructor and action docblocks to clean up the codebase. - Adjusted line formatting for improved readability. --- Controller/Adminhtml/Activity/Index.php | 13 ++----------- Controller/Adminhtml/Activity/Log.php | 16 +++------------- Controller/Adminhtml/Activity/Revert.php | 11 ++--------- Controller/Adminhtml/Login/Index.php | 10 +--------- 4 files changed, 8 insertions(+), 42 deletions(-) diff --git a/Controller/Adminhtml/Activity/Index.php b/Controller/Adminhtml/Activity/Index.php index af87360..94e2549 100644 --- a/Controller/Adminhtml/Activity/Index.php +++ b/Controller/Adminhtml/Activity/Index.php @@ -25,25 +25,16 @@ */ class Index extends Action { - /** - * @var string - */ - public const ADMIN_RESOURCE = 'MageOS_AdminActivityLog::activity'; + public const string ADMIN_RESOURCE = 'MageOS_AdminActivityLog::activity'; - /** - * Index constructor. - * @param Context $context - * @param PageFactory $resultPageFactory - */ public function __construct( Context $context, - protected readonly PageFactory $resultPageFactory + private readonly PageFactory $resultPageFactory ) { parent::__construct($context); } /** - * Index action * @return Page */ public function execute() diff --git a/Controller/Adminhtml/Activity/Log.php b/Controller/Adminhtml/Activity/Log.php index 90c2e5f..b434a1c 100644 --- a/Controller/Adminhtml/Activity/Log.php +++ b/Controller/Adminhtml/Activity/Log.php @@ -27,30 +27,20 @@ */ class Log extends Action { - /** - * Log constructor. - * @param Context $context - * @param RawFactory $resultRawFactory - * @param LayoutFactory $layoutFactory - */ public function __construct( Context $context, - protected readonly RawFactory $resultRawFactory, - protected readonly LayoutFactory $layoutFactory + private readonly RawFactory $resultRawFactory, + private readonly LayoutFactory $layoutFactory ) { parent::__construct($context); } /** - * view action * @return Raw */ public function execute() { - $content = $this->layoutFactory->create() - ->createBlock( - ActivityLogListing::class - ); + $content = $this->layoutFactory->create()->createBlock(ActivityLogListing::class); /** @var Raw $resultRaw */ $resultRaw = $this->resultRawFactory->create(); diff --git a/Controller/Adminhtml/Activity/Revert.php b/Controller/Adminhtml/Activity/Revert.php index c1abf3f..1b1d760 100644 --- a/Controller/Adminhtml/Activity/Revert.php +++ b/Controller/Adminhtml/Activity/Revert.php @@ -26,22 +26,15 @@ */ class Revert extends Action { - /** - * Revert constructor. - * @param Context $context - * @param JsonFactory $resultJsonFactory - * @param Processor $processor - */ public function __construct( Context $context, - protected readonly JsonFactory $resultJsonFactory, - protected readonly Processor $processor + private readonly JsonFactory $resultJsonFactory, + private readonly Processor $processor ) { parent::__construct($context); } /** - * Revert action * @return Json */ public function execute() diff --git a/Controller/Adminhtml/Login/Index.php b/Controller/Adminhtml/Login/Index.php index 0183fa7..05e18fc 100644 --- a/Controller/Adminhtml/Login/Index.php +++ b/Controller/Adminhtml/Login/Index.php @@ -25,16 +25,8 @@ */ class Index extends Action { - /** - * @var string - */ - public const ADMIN_RESOURCE = 'MageOS_AdminActivityLog::login_activity'; + public const string ADMIN_RESOURCE = 'MageOS_AdminActivityLog::login_activity'; - /** - * Index constructor. - * @param Context $context - * @param PageFactory $resultPageFactory - */ public function __construct( Context $context, protected readonly PageFactory $resultPageFactory From bb7accf8b0cee22b415277f7e848956b50fa5465 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 15:45:41 +0100 Subject: [PATCH 02/28] Refactor ClearLog class in AdminActivityLog module List of changes: - Updated the `DATE_FORMAT` constant to explicitly include the `string` type declaration. - Removed redundant constructor docblocks to simplify and clean up the code. - Improved code readability by adjusting formatting. --- Cron/ClearLog.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/Cron/ClearLog.php b/Cron/ClearLog.php index 55483be..5c1dd71 100644 --- a/Cron/ClearLog.php +++ b/Cron/ClearLog.php @@ -29,18 +29,9 @@ class ClearLog { /** * Default date format - * @var string */ - protected const DATE_FORMAT = 'Y-m-d H:i:s'; + protected const string DATE_FORMAT = 'Y-m-d H:i:s'; - /** - * ClearLog constructor. - * @param LoggerInterface $logger - * @param DateTime $dateTime - * @param Helper $helper - * @param ActivityRepositoryInterface $activityRepository - * @param LoginRepositoryInterface $loginRepository - */ public function __construct( protected readonly LoggerInterface $logger, protected readonly DateTime $dateTime, From 11c523a7f5d552b69a717766ffe56253650a54fb Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 15:53:04 +0100 Subject: [PATCH 03/28] Refactor Benchmark class in AdminActivityLog module List of changes: - Updated properties `$startTime` and `$endTime` to explicitly include `array` type declarations. - Replaced untyped method parameters with `string` type hints for `start`, `end`, and `reset` methods to enhance type safety. - Removed redundant constructor docblock for cleaner and simplified code. --- Helper/Benchmark.php | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/Helper/Benchmark.php b/Helper/Benchmark.php index 9995a14..1e8b96b 100644 --- a/Helper/Benchmark.php +++ b/Helper/Benchmark.php @@ -33,18 +33,13 @@ class Benchmark extends AbstractHelper /** * @var String[] Start time of execution */ - private $startTime = []; + private array $startTime = []; /** * @var String[] End time of execution */ - private $endTime = []; + private array $endTime = []; - /** - * Benchmark constructor. - * @param Context $context - * @param LoggerInterface $logger - */ public function __construct( Context $context, protected LoggerInterface $logger @@ -54,10 +49,8 @@ public function __construct( /** * log info about start time in millisecond - * @param $method - * @return void */ - public function start($method): void + public function start(string $method): void { $this->reset($method); if (self::BENCHMARK_ENABLE) { @@ -70,10 +63,8 @@ public function start($method): void /** * log info about end time and time diiference in millisecond - * @param $method - * @return void */ - public function end($method): void + public function end(string $method): void { if (self::BENCHMARK_ENABLE) { $this->endTime[$method] = round(microtime(true) * 1000); @@ -89,10 +80,8 @@ public function end($method): void /** * Reset start time and end time - * @param $method - * @return void */ - public function reset($method): void + public function reset(string $method): void { $this->startTime[$method] = 0; $this->endTime[$method] = 0; From 9f06d0a53e346f4fc1ea0c9acd6c6caf505e6549 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 15:59:31 +0100 Subject: [PATCH 04/28] Refactor and enhance type safety across AdminActivityLog module List of changes: - Added `#[\Override]` attribute to multiple `prepareDataSource` and other overridden methods for improved clarity on method overriding. - Updated class `Browser` to implement `\Stringable`, ensuring compatibility with string conversion functionality. - Refactored multiple properties in `Browser` class to include explicit type declarations (`string`, `?string`, `bool`) for enhanced type safety. - Applied return type declarations (`: bool`, `: string`, `: void`) across numerous methods in the `Browser` class for better consistency and readability. - Replaced occurrences of `strpos` with safer and more readable `str_contains` where applicable. - Marked `Escaper` property in `StatusColumn` as `readonly` for improved immutability. - Enhanced code readability by ensuring consistent formatting and reducing redundancies in several components. --- Helper/Browser.php | 155 +++++++++--------- .../Listing/Column/ActionTypeColumn.php | 1 + Ui/Component/Listing/Column/BrowserColumn.php | 1 + Ui/Component/Listing/Column/ItemColumn.php | 2 + .../Listing/Column/RevertStatusColumn.php | 1 + Ui/Component/Listing/Column/StatusColumn.php | 3 +- Ui/Component/Listing/Column/StoreColumn.php | 1 + .../Listing/Column/UserAgentColumn.php | 1 + Ui/Component/Listing/Column/ViewAction.php | 1 + 9 files changed, 83 insertions(+), 83 deletions(-) diff --git a/Helper/Browser.php b/Helper/Browser.php index 5245024..db2d938 100644 --- a/Helper/Browser.php +++ b/Helper/Browser.php @@ -21,7 +21,7 @@ * Class Browser * @package MageOS\AdminActivityLog\Helper */ -class Browser extends AbstractHelper +class Browser extends AbstractHelper implements \Stringable { /** * @var string @@ -33,20 +33,14 @@ class Browser extends AbstractHelper */ private $browser_name = ''; - /** - * @var string - */ - private $version = ''; + private ?string $version = ''; /** * @var string */ private $platform = ''; - /** - * @var string - */ - private $os = ''; + private string $os = ''; /** * @var bool @@ -73,10 +67,7 @@ class Browser extends AbstractHelper */ private $is_facebook = false; - /** - * @var string - */ - private $aol_version = ''; + private ?string $aol_version = ''; public const BROWSER_UNKNOWN = 'unknown'; public const VERSION_UNKNOWN = 'unknown'; @@ -185,7 +176,7 @@ public function __construct(Context $context) * Reset all properties * @return void */ - public function reset() + public function reset(): void { $this->agent = $_SERVER['HTTP_USER_AGENT'] ?? ""; $this->browser_name = self::BROWSER_UNKNOWN; @@ -205,7 +196,7 @@ public function reset() * @param string $browserName * @return bool True if the browser is the specified browser */ - public function isBrowser($browserName) + public function isBrowser($browserName): bool { return strcasecmp($this->browser_name, trim((string)$browserName)) === 0; } @@ -224,7 +215,7 @@ public function getBrowser() * @param $browser string The name of the Browser * @return void */ - public function setBrowser($browser) + public function setBrowser($browser): void { $this->browser_name = $browser; } @@ -243,7 +234,7 @@ public function getPlatform() * @param string $platform The name of the Platform * @return void */ - public function setPlatform($platform) + public function setPlatform($platform): void { $this->platform = $platform; } @@ -262,7 +253,7 @@ public function getVersion() * @param string $version The version of the Browser * @return void */ - public function setVersion($version) + public function setVersion($version): void { $this->version = preg_replace('/[^0-9,.,a-z,A-Z-]/', '', $version); } @@ -281,7 +272,7 @@ public function getAolVersion() * @param string $version The version of AOL * @return void */ - public function setAolVersion($version) + public function setAolVersion($version): void { $this->aol_version = preg_replace('/[^0-9,.,a-z,A-Z]/', '', $version); } @@ -336,7 +327,7 @@ public function isFacebook() * @param $isAol * @return void */ - public function setAol($isAol) + public function setAol($isAol): void { $this->is_aol = $isAol; } @@ -395,7 +386,7 @@ public function getUserAgent() * @param string $agent_string The value for the User Agent * @return void */ - public function setUserAgent($agent_string) + public function setUserAgent($agent_string): void { $this->reset(); $this->agent = $agent_string; @@ -407,16 +398,16 @@ public function setUserAgent($agent_string) * @return bool True if the browser is using chromeframe * @since 1.7 */ - public function isChromeFrame() + public function isChromeFrame(): bool { - return (strpos($this->agent, "chromeframe") !== false); + return (str_contains($this->agent, "chromeframe")); } /** * Returns a formatted string with a summary of the details of the browser. * @return string formatted string with a summary of the browser */ - public function __toString() + public function __toString(): string { $device = ($this->isMobile()) ? 'Mobile' : (($this->isTablet()) ? 'Tablet' : 'Desktop'); return "Browser Name: {$this->getBrowser()}
\n" . @@ -440,7 +431,7 @@ protected function determine() * Protected routine to determine the browser type * @return bool True if the browser was detected otherwise false */ - protected function checkBrowsers() + protected function checkBrowsers(): bool { return ( // well-known, well-used @@ -529,7 +520,7 @@ protected function checkBrowsers() * Determine if the user is using a BlackBerry (last updated 1.7) * @return bool True if the browser is the BlackBerry browser otherwise false */ - protected function checkBrowserBlackBerry() + protected function checkBrowserBlackBerry(): bool { if (stripos($this->agent, 'blackberry') !== false) { $aresult = explode("/", stristr($this->agent, "BlackBerry")); @@ -548,7 +539,7 @@ protected function checkBrowserBlackBerry() * Determine if the user is using an AOL User Agent (last updated 1.7) * @return bool True if the browser is from AOL otherwise false */ - protected function checkForAol() + protected function checkForAol(): bool { $this->setAol(false); $this->setAolVersion(self::VERSION_UNKNOWN); @@ -568,7 +559,7 @@ protected function checkForAol() * Determine if the browser is the GoogleBot or not (last updated 1.7) * @return bool True if the browser is the GoogletBot otherwise false */ - protected function checkBrowserGoogleBot() + protected function checkBrowserGoogleBot(): bool { if (stripos($this->agent, 'googlebot') !== false) { $aresult = explode('/', stristr($this->agent, 'googlebot')); @@ -587,7 +578,7 @@ protected function checkBrowserGoogleBot() * Determine if the browser is the YandexBot or not * @return bool True if the browser is the YandexBot otherwise false */ - protected function checkBrowserYandexBot() + protected function checkBrowserYandexBot(): bool { if (stripos($this->agent, 'YandexBot') !== false) { $aresult = explode('/', stristr($this->agent, 'YandexBot')); @@ -606,7 +597,7 @@ protected function checkBrowserYandexBot() * Determine if the browser is the YandexImageResizer or not * @return bool True if the browser is the YandexImageResizer otherwise false */ - protected function checkBrowserYandexImageResizerBot() + protected function checkBrowserYandexImageResizerBot(): bool { if (stripos($this->agent, 'YandexImageResizer') !== false) { $aresult = explode('/', stristr($this->agent, 'YandexImageResizer')); @@ -625,7 +616,7 @@ protected function checkBrowserYandexImageResizerBot() * Determine if the browser is the YandexCatalog or not * @return bool True if the browser is the YandexCatalog otherwise false */ - protected function checkBrowserYandexCatalogBot() + protected function checkBrowserYandexCatalogBot(): bool { if (stripos($this->agent, 'YandexCatalog') !== false) { $aresult = explode('/', stristr($this->agent, 'YandexCatalog')); @@ -644,7 +635,7 @@ protected function checkBrowserYandexCatalogBot() * Determine if the browser is the YandexNews or not * @return bool True if the browser is the YandexNews otherwise false */ - protected function checkBrowserYandexNewsBot() + protected function checkBrowserYandexNewsBot(): bool { if (stripos($this->agent, 'YandexNews') !== false) { $aresult = explode('/', stristr($this->agent, 'YandexNews')); @@ -663,7 +654,7 @@ protected function checkBrowserYandexNewsBot() * Determine if the browser is the YandexMetrika or not * @return bool True if the browser is the YandexMetrika otherwise false */ - protected function checkBrowserYandexMetrikaBot() + protected function checkBrowserYandexMetrikaBot(): bool { if (stripos($this->agent, 'YandexMetrika') !== false) { $aresult = explode('/', stristr($this->agent, 'YandexMetrika')); @@ -682,7 +673,7 @@ protected function checkBrowserYandexMetrikaBot() * Determine if the browser is the YandexDirect or not * @return bool True if the browser is the YandexDirect otherwise false */ - protected function checkBrowserYandexDirectBot() + protected function checkBrowserYandexDirectBot(): bool { if (stripos($this->agent, 'YandexDirect') !== false) { $aresult = explode('/', stristr($this->agent, 'YandexDirect')); @@ -701,7 +692,7 @@ protected function checkBrowserYandexDirectBot() * Determine if the browser is the YandexWebmaster or not * @return bool True if the browser is the YandexWebmaster otherwise false */ - protected function checkBrowserYandexWebmasterBot() + protected function checkBrowserYandexWebmasterBot(): bool { if (stripos($this->agent, 'YandexWebmaster') !== false) { $aresult = explode('/', stristr($this->agent, 'YandexWebmaster')); @@ -720,7 +711,7 @@ protected function checkBrowserYandexWebmasterBot() * Determine if the browser is the YandexFavicons or not * @return bool True if the browser is the YandexFavicons otherwise false */ - protected function checkBrowserYandexFaviconsBot() + protected function checkBrowserYandexFaviconsBot(): bool { if (stripos($this->agent, 'YandexFavicons') !== false) { $aresult = explode('/', stristr($this->agent, 'YandexFavicons')); @@ -739,7 +730,7 @@ protected function checkBrowserYandexFaviconsBot() * Determine if the browser is the YandexBlogs or not * @return bool True if the browser is the YandexBlogs otherwise false */ - protected function checkBrowserYandexBlogsBot() + protected function checkBrowserYandexBlogsBot(): bool { if (stripos($this->agent, 'YandexBlogs') !== false) { $aresult = explode('/', stristr($this->agent, 'YandexBlogs')); @@ -758,7 +749,7 @@ protected function checkBrowserYandexBlogsBot() * Determine if the browser is the YandexMedia or not * @return bool True if the browser is the YandexMedia otherwise false */ - protected function checkBrowserYandexMediaBot() + protected function checkBrowserYandexMediaBot(): bool { if (stripos($this->agent, 'YandexMedia') !== false) { $aresult = explode('/', stristr($this->agent, 'YandexMedia')); @@ -777,7 +768,7 @@ protected function checkBrowserYandexMediaBot() * Determine if the browser is the YandexVideo or not * @return bool True if the browser is the YandexVideo otherwise false */ - protected function checkBrowserYandexVideoBot() + protected function checkBrowserYandexVideoBot(): bool { if (stripos($this->agent, 'YandexVideo') !== false) { $aresult = explode('/', stristr($this->agent, 'YandexVideo')); @@ -796,7 +787,7 @@ protected function checkBrowserYandexVideoBot() * Determine if the browser is the YandexImages or not * @return bool True if the browser is the YandexImages otherwise false */ - protected function checkBrowserYandexImagesBot() + protected function checkBrowserYandexImagesBot(): bool { if (stripos($this->agent, 'YandexImages') !== false) { $aresult = explode('/', stristr($this->agent, 'YandexImages')); @@ -815,7 +806,7 @@ protected function checkBrowserYandexImagesBot() * Determine if the browser is the MSNBot or not (last updated 1.9) * @return bool True if the browser is the MSNBot otherwise false */ - protected function checkBrowserMSNBot() + protected function checkBrowserMSNBot(): bool { if (stripos($this->agent, "msnbot") !== false) { $aresult = explode("/", stristr($this->agent, "msnbot")); @@ -834,7 +825,7 @@ protected function checkBrowserMSNBot() * Determine if the browser is the BingBot or not (last updated 1.9) * @return bool True if the browser is the BingBot otherwise false */ - protected function checkBrowserBingBot() + protected function checkBrowserBingBot(): bool { if (stripos($this->agent, "bingbot") !== false) { $aresult = explode("/", stristr($this->agent, "bingbot")); @@ -853,7 +844,7 @@ protected function checkBrowserBingBot() * Determine if the browser is the W3C Validator or not (last updated 1.7) * @return bool True if the browser is the W3C Validator otherwise false */ - protected function checkBrowserW3CValidator() + protected function checkBrowserW3CValidator(): bool { if (stripos($this->agent, 'W3C-checklink') !== false) { $aresult = explode('/', stristr($this->agent, 'W3C-checklink')); @@ -885,7 +876,7 @@ protected function checkBrowserW3CValidator() * Determine if the browser is the Yahoo! Slurp Robot or not (last updated 1.7) * @return bool True if the browser is the Yahoo! Slurp Robot otherwise false */ - protected function checkBrowserSlurp() + protected function checkBrowserSlurp(): bool { if (stripos($this->agent, 'slurp') !== false) { $aresult = explode('/', stristr($this->agent, 'Slurp')); @@ -905,7 +896,7 @@ protected function checkBrowserSlurp() * Determine if the browser is Edge or not * @return bool True if the browser is Edge otherwise false */ - protected function checkBrowserEdge() + protected function checkBrowserEdge(): bool { if (stripos($this->agent, 'Edge/') !== false) { $aresult = explode('/', stristr($this->agent, 'Edge')); @@ -926,7 +917,7 @@ protected function checkBrowserEdge() * Determine if the browser is Internet Explorer or not (last updated 1.7) * @return bool True if the browser is Internet Explorer otherwise false */ - protected function checkBrowserInternetExplorer() + protected function checkBrowserInternetExplorer(): bool { // Test for IE11 if (stripos($this->agent, 'Trident/7.0; rv:11.0') !== false) { @@ -1026,7 +1017,7 @@ protected function checkBrowserInternetExplorer() * Determine if the browser is Opera or not (last updated 1.7) * @return bool True if the browser is Opera otherwise false */ - protected function checkBrowserOpera() + protected function checkBrowserOpera(): bool { if (stripos($this->agent, 'opera mini') !== false) { $resultant = stristr($this->agent, 'opera mini'); @@ -1092,7 +1083,7 @@ protected function checkBrowserOpera() * Determine if the browser is Chrome or not (last updated 1.7) * @return bool True if the browser is Chrome otherwise false */ - protected function checkBrowserChrome() + protected function checkBrowserChrome(): bool { if (stripos($this->agent, 'Chrome') !== false) { $aresult = explode('/', stristr($this->agent, 'Chrome')); @@ -1118,7 +1109,7 @@ protected function checkBrowserChrome() * Determine if the browser is WebTv or not (last updated 1.7) * @return bool True if the browser is WebTv otherwise false */ - protected function checkBrowserWebTv() + protected function checkBrowserWebTv(): bool { if (stripos($this->agent, 'webtv') !== false) { $aresult = explode('/', stristr($this->agent, 'webtv')); @@ -1136,7 +1127,7 @@ protected function checkBrowserWebTv() * Determine if the browser is NetPositive or not (last updated 1.7) * @return bool True if the browser is NetPositive otherwise false */ - protected function checkBrowserNetPositive() + protected function checkBrowserNetPositive(): bool { if (stripos($this->agent, 'NetPositive') !== false) { $aresult = explode('/', stristr($this->agent, 'NetPositive')); @@ -1154,7 +1145,7 @@ protected function checkBrowserNetPositive() * Determine if the browser is Galeon or not (last updated 1.7) * @return bool True if the browser is Galeon otherwise false */ - protected function checkBrowserGaleon() + protected function checkBrowserGaleon(): bool { if (stripos($this->agent, 'galeon') !== false) { $aresult = explode(' ', stristr($this->agent, 'galeon')); @@ -1172,7 +1163,7 @@ protected function checkBrowserGaleon() * Determine if the browser is Konqueror or not (last updated 1.7) * @return bool True if the browser is Konqueror otherwise false */ - protected function checkBrowserKonqueror() + protected function checkBrowserKonqueror(): bool { if (stripos($this->agent, 'Konqueror') !== false) { $aresult = explode(' ', stristr($this->agent, 'Konqueror')); @@ -1190,7 +1181,7 @@ protected function checkBrowserKonqueror() * Determine if the browser is iCab or not (last updated 1.7) * @return bool True if the browser is iCab otherwise false */ - protected function checkBrowserIcab() + protected function checkBrowserIcab(): bool { if (stripos($this->agent, 'icab') !== false) { $aversion = explode(' ', stristr(str_replace('/', ' ', $this->agent), 'icab')); @@ -1207,7 +1198,7 @@ protected function checkBrowserIcab() * Determine if the browser is OmniWeb or not (last updated 1.7) * @return bool True if the browser is OmniWeb otherwise false */ - protected function checkBrowserOmniWeb() + protected function checkBrowserOmniWeb(): bool { if (stripos($this->agent, 'omniweb') !== false) { $aresult = explode('/', stristr($this->agent, 'omniweb')); @@ -1223,7 +1214,7 @@ protected function checkBrowserOmniWeb() * Determine if the browser is Phoenix or not (last updated 1.7) * @return bool True if the browser is Phoenix otherwise false */ - protected function checkBrowserPhoenix() + protected function checkBrowserPhoenix(): bool { if (stripos($this->agent, 'Phoenix') !== false) { $aversion = explode('/', stristr($this->agent, 'Phoenix')); @@ -1240,7 +1231,7 @@ protected function checkBrowserPhoenix() * Determine if the browser is Firebird or not (last updated 1.7) * @return bool True if the browser is Firebird otherwise false */ - protected function checkBrowserFirebird() + protected function checkBrowserFirebird(): bool { if (stripos($this->agent, 'Firebird') !== false) { $aversion = explode('/', stristr($this->agent, 'Firebird')); @@ -1258,7 +1249,7 @@ protected function checkBrowserFirebird() * NOTE: (http://browser.netscape.com/ - Official support ended on March 1st, 2008) * @return bool True if the browser is Netscape Navigator 9+ otherwise false */ - protected function checkBrowserNetscapeNavigator9Plus() + protected function checkBrowserNetscapeNavigator9Plus(): bool { if (stripos($this->agent, 'Firefox') !== false && preg_match( '/Navigator\/([^ ]*)/i', @@ -1286,7 +1277,7 @@ protected function checkBrowserNetscapeNavigator9Plus() * Determine if the browser is Shiretoko or not (https://wiki.mozilla.org/Projects/shiretoko) (last updated 1.7) * @return bool True if the browser is Shiretoko otherwise false */ - protected function checkBrowserShiretoko() + protected function checkBrowserShiretoko(): bool { if (stripos($this->agent, 'Mozilla') !== false && preg_match( '/Shiretoko\/([^ ]*)/i', @@ -1304,7 +1295,7 @@ protected function checkBrowserShiretoko() * Determine if the browser is Ice Cat or not (http://en.wikipedia.org/wiki/GNU_IceCat) (last updated 1.7) * @return bool True if the browser is Ice Cat otherwise false */ - protected function checkBrowserIceCat() + protected function checkBrowserIceCat(): bool { if (stripos($this->agent, 'Mozilla') !== false && preg_match('/IceCat\/([^ ]*)/i', $this->agent, $matches)) { $this->setVersion($matches[1]); @@ -1318,11 +1309,11 @@ protected function checkBrowserIceCat() * Determine if the browser is Nokia or not (last updated 1.7) * @return bool True if the browser is Nokia otherwise false */ - protected function checkBrowserNokia() + protected function checkBrowserNokia(): bool { if (preg_match("/Nokia([^\/]+)\/([^ SP]+)/i", $this->agent, $matches)) { $this->setVersion($matches[2]); - if (stripos($this->agent, 'Series60') !== false || strpos($this->agent, 'S60') !== false) { + if (stripos($this->agent, 'Series60') !== false || str_contains($this->agent, 'S60')) { $this->setBrowser(self::BROWSER_NOKIA_S60); } else { $this->setBrowser(self::BROWSER_NOKIA); @@ -1337,7 +1328,7 @@ protected function checkBrowserNokia() * Determine if the browser is Firefox or not (last updated 1.7) * @return bool True if the browser is Firefox otherwise false */ - protected function checkBrowserFirefox() + protected function checkBrowserFirefox(): bool { if (stripos($this->agent, 'safari') === false) { if (preg_match("/Firefox[\/ \(]([^ ;\)]+)/i", $this->agent, $matches)) { @@ -1367,7 +1358,7 @@ protected function checkBrowserFirefox() * Determine if the browser is Firefox or not (last updated 1.7) * @return bool True if the browser is Firefox otherwise false */ - protected function checkBrowserIceweasel() + protected function checkBrowserIceweasel(): bool { if (stripos($this->agent, 'Iceweasel') !== false) { $aresult = explode('/', stristr($this->agent, 'Iceweasel')); @@ -1385,7 +1376,7 @@ protected function checkBrowserIceweasel() * Determine if the browser is Mozilla or not (last updated 1.7) * @return bool True if the browser is Mozilla otherwise false */ - protected function checkBrowserMozilla() + protected function checkBrowserMozilla(): bool { if (stripos($this->agent, 'mozilla') !== false && preg_match( '/rv:[0-9].[0-9][a-b]?/i', @@ -1424,7 +1415,7 @@ protected function checkBrowserMozilla() * Determine if the browser is Lynx or not (last updated 1.7) * @return bool True if the browser is Lynx otherwise false */ - protected function checkBrowserLynx() + protected function checkBrowserLynx(): bool { if (stripos($this->agent, 'lynx') !== false) { $aresult = explode('/', stristr($this->agent, 'Lynx')); @@ -1440,7 +1431,7 @@ protected function checkBrowserLynx() * Determine if the browser is Amaya or not (last updated 1.7) * @return bool True if the browser is Amaya otherwise false */ - protected function checkBrowserAmaya() + protected function checkBrowserAmaya(): bool { if (stripos($this->agent, 'amaya') !== false) { $aresult = explode('/', stristr($this->agent, 'Amaya')); @@ -1458,7 +1449,7 @@ protected function checkBrowserAmaya() * Determine if the browser is Safari or not (last updated 1.7) * @return bool True if the browser is Safari otherwise false */ - protected function checkBrowserSafari() + protected function checkBrowserSafari(): bool { if (stripos($this->agent, 'Safari') !== false && stripos($this->agent, 'iPhone') === false @@ -1481,7 +1472,7 @@ protected function checkBrowserSafari() * Check browser * @return bool */ - protected function checkBrowserSamsung() + protected function checkBrowserSamsung(): bool { if (stripos($this->agent, 'SamsungBrowser') !== false) { $aresult = explode('/', stristr($this->agent, 'SamsungBrowser')); @@ -1501,7 +1492,7 @@ protected function checkBrowserSamsung() * Check browser * @return bool */ - protected function checkBrowserSilk() + protected function checkBrowserSilk(): bool { if (stripos($this->agent, 'Silk') !== false) { $aresult = explode('/', stristr($this->agent, 'Silk')); @@ -1521,7 +1512,7 @@ protected function checkBrowserSilk() * Check browser * @return bool */ - protected function checkBrowserIframely() + protected function checkBrowserIframely(): bool { if (stripos($this->agent, 'Iframely') !== false) { $aresult = explode('/', stristr($this->agent, 'Iframely')); @@ -1541,7 +1532,7 @@ protected function checkBrowserIframely() * Check browser * @return bool */ - protected function checkBrowserCocoa() + protected function checkBrowserCocoa(): bool { if (stripos($this->agent, 'CocoaRestClient') !== false) { $aresult = explode('/', stristr($this->agent, 'CocoaRestClient')); @@ -1561,7 +1552,7 @@ protected function checkBrowserCocoa() * Detect if URL is loaded from FacebookExternalHit * @return bool True if it detects FacebookExternalHit otherwise false */ - protected function checkFacebookExternalHit() + protected function checkFacebookExternalHit(): bool { if (stristr($this->agent, 'FacebookExternalHit')) { $this->setRobot(); @@ -1575,7 +1566,7 @@ protected function checkFacebookExternalHit() * Detect if URL is being loaded from internal Facebook browser * @return bool True if it detects internal Facebook browser otherwise false */ - protected function checkForFacebookIos() + protected function checkForFacebookIos(): bool { if (stristr($this->agent, 'FBIOS')) { $this->setFacebook(); @@ -1588,7 +1579,7 @@ protected function checkForFacebookIos() * Detect Version for the Safari browser on iOS devices * @return bool True if it detects the version correctly otherwise false */ - protected function getSafariVersionOnIos() + protected function getSafariVersionOnIos(): bool { $aresult = explode('/', stristr($this->agent, 'Version')); if (isset($aresult[1])) { @@ -1603,7 +1594,7 @@ protected function getSafariVersionOnIos() * Detect Version for the Chrome browser on iOS devices * @return bool True if it detects the version correctly otherwise false */ - protected function getChromeVersionOnIos() + protected function getChromeVersionOnIos(): bool { $aresult = explode('/', stristr($this->agent, 'CriOS')); if (isset($aresult[1])) { @@ -1619,7 +1610,7 @@ protected function getChromeVersionOnIos() * Determine if the browser is iPhone or not (last updated 1.7) * @return bool True if the browser is iPhone otherwise false */ - protected function checkBrowseriPhone() + protected function checkBrowseriPhone(): bool { if (stripos($this->agent, 'iPhone') !== false) { $this->setVersion(self::VERSION_UNKNOWN); @@ -1637,7 +1628,7 @@ protected function checkBrowseriPhone() * Determine if the browser is iPad or not (last updated 1.7) * @return bool True if the browser is iPad otherwise false */ - protected function checkBrowseriPad() + protected function checkBrowseriPad(): bool { if (stripos($this->agent, 'iPad') !== false) { $this->setVersion(self::VERSION_UNKNOWN); @@ -1655,7 +1646,7 @@ protected function checkBrowseriPad() * Determine if the browser is iPod or not (last updated 1.7) * @return bool True if the browser is iPod otherwise false */ - protected function checkBrowseriPod() + protected function checkBrowseriPod(): bool { if (stripos($this->agent, 'iPod') !== false) { $this->setVersion(self::VERSION_UNKNOWN); @@ -1673,7 +1664,7 @@ protected function checkBrowseriPod() * Determine if the browser is Android or not (last updated 1.7) * @return bool True if the browser is Android otherwise false */ - protected function checkBrowserAndroid() + protected function checkBrowserAndroid(): bool { if (stripos($this->agent, 'Android') !== false) { $aresult = explode(' ', stristr($this->agent, 'Android')); @@ -1698,7 +1689,7 @@ protected function checkBrowserAndroid() * Determine if the browser is Vivaldi * @return bool True if the browser is Vivaldi otherwise false */ - protected function checkBrowserVivaldi() + protected function checkBrowserVivaldi(): bool { if (stripos($this->agent, 'Vivaldi') !== false) { $aresult = explode('/', stristr($this->agent, 'Vivaldi')); @@ -1716,7 +1707,7 @@ protected function checkBrowserVivaldi() * Determine if the browser is Yandex * @return bool True if the browser is Yandex otherwise false */ - protected function checkBrowserYandex() + protected function checkBrowserYandex(): bool { if (stripos($this->agent, 'YaBrowser') !== false) { $aresult = explode('/', stristr($this->agent, 'YaBrowser')); @@ -1744,7 +1735,7 @@ protected function checkBrowserYandex() * Determine if the browser is a PlayStation * @return bool True if the browser is PlayStation otherwise false */ - protected function checkBrowserPlayStation() + protected function checkBrowserPlayStation(): bool { if (stripos($this->agent, 'PlayStation ') !== false) { $aresult = explode(' ', stristr($this->agent, 'PlayStation ')); diff --git a/Ui/Component/Listing/Column/ActionTypeColumn.php b/Ui/Component/Listing/Column/ActionTypeColumn.php index d9a50e5..fb893c9 100644 --- a/Ui/Component/Listing/Column/ActionTypeColumn.php +++ b/Ui/Component/Listing/Column/ActionTypeColumn.php @@ -48,6 +48,7 @@ public function __construct( * @param array $dataSource * @return array */ + #[\Override] public function prepareDataSource(array $dataSource): array { if (isset($dataSource['data']['items'])) { diff --git a/Ui/Component/Listing/Column/BrowserColumn.php b/Ui/Component/Listing/Column/BrowserColumn.php index 4eeac6a..9a07031 100644 --- a/Ui/Component/Listing/Column/BrowserColumn.php +++ b/Ui/Component/Listing/Column/BrowserColumn.php @@ -60,6 +60,7 @@ public function getAgent(array $item): string * @param array $dataSource * @return array */ + #[\Override] public function prepareDataSource(array $dataSource): array { if (isset($dataSource['data']['items'])) { diff --git a/Ui/Component/Listing/Column/ItemColumn.php b/Ui/Component/Listing/Column/ItemColumn.php index 968921d..163874c 100644 --- a/Ui/Component/Listing/Column/ItemColumn.php +++ b/Ui/Component/Listing/Column/ItemColumn.php @@ -121,6 +121,7 @@ public function getLinkAttributes(): string * @param string $quote * @return string */ + #[\Override] public function serialize($keys = [], $valueSeparator = '=', $fieldSeparator = ' ', $quote = '"'): string { $data = []; @@ -171,6 +172,7 @@ protected function initLinkParams(array $item): void * @param array $dataSource * @return array */ + #[\Override] public function prepareDataSource(array $dataSource): array { if (isset($dataSource['data']['items'])) { diff --git a/Ui/Component/Listing/Column/RevertStatusColumn.php b/Ui/Component/Listing/Column/RevertStatusColumn.php index 9ce69bd..8ab9944 100644 --- a/Ui/Component/Listing/Column/RevertStatusColumn.php +++ b/Ui/Component/Listing/Column/RevertStatusColumn.php @@ -27,6 +27,7 @@ class RevertStatusColumn extends Column * @param array $dataSource * @return array */ + #[\Override] public function prepareDataSource(array $dataSource): array { if (isset($dataSource['data']['items'])) { diff --git a/Ui/Component/Listing/Column/StatusColumn.php b/Ui/Component/Listing/Column/StatusColumn.php index 292e95d..f1daf8f 100644 --- a/Ui/Component/Listing/Column/StatusColumn.php +++ b/Ui/Component/Listing/Column/StatusColumn.php @@ -28,7 +28,7 @@ class StatusColumn extends Column public function __construct( ContextInterface $context, UiComponentFactory $uiComponentFactory, - private Escaper $escaper, + private readonly Escaper $escaper, array $components = [], array $data = [] ) { @@ -40,6 +40,7 @@ public function __construct( * @param array $dataSource * @return array */ + #[\Override] public function prepareDataSource(array $dataSource): array { if (isset($dataSource['data']['items'])) { diff --git a/Ui/Component/Listing/Column/StoreColumn.php b/Ui/Component/Listing/Column/StoreColumn.php index 89970df..6f2eed6 100644 --- a/Ui/Component/Listing/Column/StoreColumn.php +++ b/Ui/Component/Listing/Column/StoreColumn.php @@ -29,6 +29,7 @@ class StoreColumn extends Store * @param array $item * @return string */ + #[\Override] public function prepareItem(array $item): string { $this->storeKey = !empty($this->storeKey) ? $this->storeKey : self::KEY_FIELD; diff --git a/Ui/Component/Listing/Column/UserAgentColumn.php b/Ui/Component/Listing/Column/UserAgentColumn.php index 0b143c9..840fa3c 100644 --- a/Ui/Component/Listing/Column/UserAgentColumn.php +++ b/Ui/Component/Listing/Column/UserAgentColumn.php @@ -60,6 +60,7 @@ public function getAgent(array $item): string * @param array $dataSource * @return array */ + #[\Override] public function prepareDataSource(array $dataSource): array { if (isset($dataSource['data']['items'])) { diff --git a/Ui/Component/Listing/Column/ViewAction.php b/Ui/Component/Listing/Column/ViewAction.php index 91c2384..56a140a 100644 --- a/Ui/Component/Listing/Column/ViewAction.php +++ b/Ui/Component/Listing/Column/ViewAction.php @@ -63,6 +63,7 @@ public function getViewUrl(): string * @param array $dataSource * @return array */ + #[\Override] public function prepareDataSource(array $dataSource): array { if (isset($dataSource['data']['items'])) { From 2a9c045c5381c306f1ab3e7327f6511b547c9b15 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 16:00:38 +0100 Subject: [PATCH 05/28] Add explicit return type declarations in collection constructors List of changes: - Updated `_construct` method in `Activity`, `Login`, `ActivityLogDetail`, and `ActivityLog` collection classes to include explicit `: void` return type declarations. - Improved code consistency and type safety across the module. --- Model/ResourceModel/Activity/Collection.php | 2 +- Model/ResourceModel/ActivityLog/Collection.php | 2 +- Model/ResourceModel/ActivityLogDetail/Collection.php | 2 +- Model/ResourceModel/Login/Collection.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Model/ResourceModel/Activity/Collection.php b/Model/ResourceModel/Activity/Collection.php index 914e215..79e5921 100644 --- a/Model/ResourceModel/Activity/Collection.php +++ b/Model/ResourceModel/Activity/Collection.php @@ -27,7 +27,7 @@ class Collection extends AbstractCollection * Define resource model * @return void */ - public function _construct() + public function _construct(): void { $this->_init( \MageOS\AdminActivityLog\Model\Activity::class, diff --git a/Model/ResourceModel/ActivityLog/Collection.php b/Model/ResourceModel/ActivityLog/Collection.php index bdd037c..cfba9e4 100644 --- a/Model/ResourceModel/ActivityLog/Collection.php +++ b/Model/ResourceModel/ActivityLog/Collection.php @@ -27,7 +27,7 @@ class Collection extends AbstractCollection * Define resource model * @return void */ - public function _construct() + public function _construct(): void { $this->_init( \MageOS\AdminActivityLog\Model\ActivityLog::class, diff --git a/Model/ResourceModel/ActivityLogDetail/Collection.php b/Model/ResourceModel/ActivityLogDetail/Collection.php index 134da04..abcdf52 100644 --- a/Model/ResourceModel/ActivityLogDetail/Collection.php +++ b/Model/ResourceModel/ActivityLogDetail/Collection.php @@ -27,7 +27,7 @@ class Collection extends AbstractCollection * Define resource model * @return void */ - public function _construct() + public function _construct(): void { $this->_init( \MageOS\AdminActivityLog\Model\ActivityLogDetail::class, diff --git a/Model/ResourceModel/Login/Collection.php b/Model/ResourceModel/Login/Collection.php index 28eec54..1e38e0b 100644 --- a/Model/ResourceModel/Login/Collection.php +++ b/Model/ResourceModel/Login/Collection.php @@ -27,7 +27,7 @@ class Collection extends AbstractCollection * Define resource model * @return void */ - public function _construct() + public function _construct(): void { $this->_init( \MageOS\AdminActivityLog\Model\Login::class, From 06c7d1d4ca9a82f0b1278cc2d9dd1d1232b4eeb3 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 16:00:50 +0100 Subject: [PATCH 06/28] Add explicit `void` return type to resource model constructors List of changes: - Updated `_construct` methods in `Activity`, `Login`, `ActivityLogDetail`, and `ActivityLog` resource model classes to include explicit `: void` return type declarations. - Improved code consistency and type safety across resource model classes in the `AdminActivityLog` module. --- Model/ResourceModel/Activity.php | 2 +- Model/ResourceModel/ActivityLog.php | 2 +- Model/ResourceModel/ActivityLogDetail.php | 2 +- Model/ResourceModel/Login.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Model/ResourceModel/Activity.php b/Model/ResourceModel/Activity.php index bb60a1e..0f9d5b0 100644 --- a/Model/ResourceModel/Activity.php +++ b/Model/ResourceModel/Activity.php @@ -26,7 +26,7 @@ class Activity extends AbstractDb * Initialize resource model * @return void */ - public function _construct() + public function _construct(): void { $this->_init('admin_activity', 'entity_id'); } diff --git a/Model/ResourceModel/ActivityLog.php b/Model/ResourceModel/ActivityLog.php index edc7af4..45e5fff 100644 --- a/Model/ResourceModel/ActivityLog.php +++ b/Model/ResourceModel/ActivityLog.php @@ -26,7 +26,7 @@ class ActivityLog extends AbstractDb * Initialize resource model * @return void */ - public function _construct() + public function _construct(): void { $this->_init('admin_activity_log', 'entity_id'); } diff --git a/Model/ResourceModel/ActivityLogDetail.php b/Model/ResourceModel/ActivityLogDetail.php index 72d4d94..7afee68 100644 --- a/Model/ResourceModel/ActivityLogDetail.php +++ b/Model/ResourceModel/ActivityLogDetail.php @@ -26,7 +26,7 @@ class ActivityLogDetail extends AbstractDb * Initialize resource model * @return void */ - public function _construct() + public function _construct(): void { $this->_init('admin_activity_detail', 'entity_id'); } diff --git a/Model/ResourceModel/Login.php b/Model/ResourceModel/Login.php index 1bc13f8..6614d78 100644 --- a/Model/ResourceModel/Login.php +++ b/Model/ResourceModel/Login.php @@ -26,7 +26,7 @@ class Login extends AbstractDb * Initialize resource model * @return void */ - public function _construct() + public function _construct(): void { $this->_init('admin_login_log', 'entity_id'); } From 9978e776b3b7391e12782f9d7c9ae37b8e558732 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 16:03:02 +0100 Subject: [PATCH 07/28] Add explicit type declarations across AdminActivityLog module List of changes: - Updated return types in various methods (e.g., `getAdminDetails`, `getEditData`, `revertData`) to enhance type safety and consistency. - Applied explicit type declarations to properties (e.g., `$labels` set to `private array`). - Standardized parameter type hints and updated usages (e.g., replaced `$model->getId()` with `$model::class` for improved clarity). - Ensured accurate type definitions for return types (e.g., `array{old_value: mixed, new_value: mixed}[]` added to `getEditData`). - Improved readability by enforcing type constraints, including casting specific values to `string`. --- Block/Adminhtml/ActivityLogListing.php | 2 +- Model/Activity/SystemConfig.php | 14 +++++++------- Model/ActivityRepository.php | 4 ++-- Model/Config.php | 3 +-- Model/LoginRepository.php | 2 +- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Block/Adminhtml/ActivityLogListing.php b/Block/Adminhtml/ActivityLogListing.php index 1463203..53d6b2d 100644 --- a/Block/Adminhtml/ActivityLogListing.php +++ b/Block/Adminhtml/ActivityLogListing.php @@ -60,7 +60,7 @@ public function getLogListing() * Get admin activity details * @return array */ - public function getAdminDetails() + public function getAdminDetails(): array { $id = $this->getRequest()->getParam('id'); $activity = $this->activityRepository->getActivityById($id); diff --git a/Model/Activity/SystemConfig.php b/Model/Activity/SystemConfig.php index d05d64d..77f1f3e 100644 --- a/Model/Activity/SystemConfig.php +++ b/Model/Activity/SystemConfig.php @@ -72,11 +72,11 @@ public function getOldData(DataObject $model) ); $data = []; foreach ($systemData->getData() as $config) { - $splittedPath = explode('/', $config['path']); + $splittedPath = explode('/', (string) $config['path']); if (count($splittedPath) === 2) { - [$group, $field] = explode('/', $config['path']); + [$group, $field] = explode('/', (string) $config['path']); } else { - [$path, $group, $field] = explode('/', $config['path']); + [$path, $group, $field] = explode('/', (string) $config['path']); } $data[$group]['fields'][$field]['value'] = $config['value']; @@ -89,9 +89,9 @@ public function getOldData(DataObject $model) * Get edit activity data of system config module * @param DataObject $model * @param array $fieldArray - * @return mixed + * @return array{old_value: mixed, new_value: mixed}[] */ - public function getEditData(DataObject $model, $fieldArray) + public function getEditData(DataObject $model, $fieldArray): array { $logData = []; @@ -132,7 +132,7 @@ public function getEditData(DataObject $model, $fieldArray) * @param mixed $scopeId * @return bool */ - public function revertData($logData, $scopeId) + public function revertData($logData, $scopeId): bool { if (!empty($logData)) { foreach ($logData as $log) { @@ -153,7 +153,7 @@ public function revertData($logData, $scopeId) * @param mixed $newData * @return array */ - protected function collectAdditionalData(array $oldData, $newData): array + protected function collectAdditionalData(array $oldData, array $newData): array { $result = []; if (!empty($oldData) && is_array($oldData)) { diff --git a/Model/ActivityRepository.php b/Model/ActivityRepository.php index eb249cd..96b516a 100644 --- a/Model/ActivityRepository.php +++ b/Model/ActivityRepository.php @@ -38,7 +38,7 @@ class ActivityRepository implements ActivityRepositoryInterface * @param ResourceModel\Activity\CollectionFactory $collectionFactory * @param ActivityLogDetailFactory $activityLogDetailFactory * @param ActivityLogFactory $activityLogFactory - * @param ResourceModel\ActivityLog\CollectionFactory $LogCollectionFactory + * @param CollectionFactory $LogCollectionFactory * @param SystemConfig $systemConfig * @param Activity\ThemeConfig $themeConfig * @param ObjectManagerInterface $objectManager @@ -195,7 +195,7 @@ public function getOldData(DataObject $model) if (Data::isWildCardModel($model)) { return $this->systemConfig->getOldData($model); } - $data = $this->objectManager->get(get_class($model))->load($model->getId()); + $data = $this->objectManager->get($model::class)->load($model->getId()); if ($data) { return $data; } diff --git a/Model/Config.php b/Model/Config.php index ebf5fc2..6e57ba6 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -31,9 +31,8 @@ class Config /** * Translated and sorted labels - * @var array */ - private $labels = []; + private array $labels = []; /** * Config constructor. diff --git a/Model/LoginRepository.php b/Model/LoginRepository.php index 005dd8f..b998898 100644 --- a/Model/LoginRepository.php +++ b/Model/LoginRepository.php @@ -36,7 +36,7 @@ class LoginRepository implements LoginRepositoryInterface /** * LoginRepository constructor. * @param LoginFactory $loginFactory - * @param ResourceModel\Login\CollectionFactory $collectionFactory + * @param CollectionFactory $collectionFactory * @param Processor $processor */ public function __construct( From 8cb18ca9cec2d8b74a637e8942ee1eef14519bc6 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 16:44:42 +0100 Subject: [PATCH 08/28] Add explicit type declarations for improved type safety in Processor class List of changes: - Added return type declarations (`: bool`, `: void`, `: array`, `: string`, `: static`) across methods for enhanced type safety and consistency. - Updated parameter type hints (e.g., `string $fullActionName`, `int $activityId`) to align with modern PHP typing standards. - Replaced `Exception $e` with `Exception` in `catch` blocks, reducing redundancy. - Updated `$model::class` usage for improved clarity when retrieving the model class name. - Simplified conditional logic with null coalescing and ternary operators where applicable. - Refactored PHPDoc comments by removing redundant or outdated annotations. - Improved code formatting for better readability and maintainability. --- Model/Processor.php | 65 +++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 41 deletions(-) diff --git a/Model/Processor.php b/Model/Processor.php index 90d9884..30c00c0 100644 --- a/Model/Processor.php +++ b/Model/Processor.php @@ -20,6 +20,7 @@ use Magento\Framework\App\RequestInterface; use Magento\Framework\HTTP\PhpEnvironment\RemoteAddress; use Magento\Framework\Message\ManagerInterface; +use Magento\Framework\Phrase; use Magento\Framework\Stdlib\DateTime\DateTime; use Magento\Store\Model\StoreManagerInterface; use MageOS\AdminActivityLog\Api\ActivityRepositoryInterface; @@ -123,11 +124,8 @@ public function __construct( /** * Get and set event config from full action name - * @param $fullActionName - * @param $actionName - * @return $this */ - public function init($fullActionName, $actionName) + public function init(string $fullActionName, string $actionName): static { $this->actionName = $actionName; @@ -145,9 +143,8 @@ public function init($fullActionName, $actionName) /** * Check Model class * @param $model - * @return bool */ - public function validate($model) + public function validate($model): bool { if (Helper::isWildCardModel($model)) { if (!empty($this->activityLogs)) { @@ -171,9 +168,8 @@ public function validate($model) /** * Return method name of TrackField class - * @return string */ - public function getMethod() + public function getMethod(): string { return $this->config->getTrackFieldModel($this->eventConfig['module']); } @@ -181,14 +177,13 @@ public function getMethod() /** * Get item url * @param $model - * @return string */ - public function getEditUrl($model) + public function getEditUrl($model): string|array { $id = $model->getId(); if ($this->eventConfig['module'] === self::SALES_ORDER && (!empty($model->getOrderId()) || !empty($model->getParentId()))) { - $id = ($model->getOrderId()) ? $model->getOrderId() : $model->getParentId(); + $id = $model->getOrderId() ?: $model->getParentId(); } return str_replace( $this->urlParams, @@ -206,9 +201,8 @@ public function getEditUrl($model) /** * Set activity data after item added * @param $model - * @return $this|bool */ - public function modelAddAfter($model) + public function modelAddAfter($model): static { if ($this->validate($model)) { $logData = $this->handler->modelAdd($model, $this->getMethod()); @@ -225,9 +219,8 @@ public function modelAddAfter($model) /** * Set activity data after item edited * @param $model - * @return $this|bool */ - public function modelEditAfter($model) + public function modelEditAfter($model): static { $label = ($this->eventConfig['action'] === self::SAVE_ACTION) ? self::EDIT_ACTION : $this->eventConfig['action']; if ($this->validate($model)) { @@ -247,9 +240,8 @@ public function modelEditAfter($model) /** * Set activity data after item deleted * @param $model - * @return $this|bool */ - public function modelDeleteAfter($model) + public function modelDeleteAfter($model): static { if ($this->validate($model)) { $logData = $this->handler->modelDelete($model, $this->getMethod()); @@ -262,6 +254,7 @@ public function modelDeleteAfter($model) $this->addLog($activity, $logData, $model); } } + return $this; } @@ -270,9 +263,8 @@ public function modelDeleteAfter($model) * @param $activity * @param $logData * @param $model - * @return void */ - public function addLog($activity, $logData, $model) + public function addLog($activity, $logData, $model): void { $logDetail = $this->initActivityDetail($model); $this->activityLogs[] = [ @@ -284,9 +276,8 @@ public function addLog($activity, $logData, $model) /** * Insert activity log data in database - * @return bool */ - public function saveLogs() + public function saveLogs(): bool { try { if (!empty($this->activityLogs)) { @@ -313,7 +304,7 @@ public function saveLogs() } $this->activityLogs = []; } - } catch (Exception $e) { + } catch (Exception) { return false; } return true; @@ -321,9 +312,8 @@ public function saveLogs() /** * Set activity details data - * @return Activity */ - public function initLog() + public function initLog(): Activity { $activity = $this->activityFactory->create(); @@ -377,7 +367,7 @@ public function initActivity($model) public function initActivityDetail($model) { $activity = $this->activityDetailFactory->create() - ->setModelClass((string)get_class($model)) + ->setModelClass((string)$model::class) ->setItemId((int)$model->getId()) ->setStatus('success') ->setResponse(''); @@ -386,9 +376,8 @@ public function initActivityDetail($model) /** * Check post dispatch method to track log for mass actions - * @return bool */ - public function callPostDispatchCallback() + public function callPostDispatchCallback(): bool { $handler = $this->postDispatch; if (isset($this->eventConfig['post_dispatch'])) { @@ -416,14 +405,14 @@ public function getStoreId($model) if (isset($data['store_id'])) { return $model->getStoreId(); } + return $this->storeManager->getStore()->getId(); } /** * Get scope name - * @return string */ - public function getScope() + public function getScope(): string { if ((int)$this->request->getParam('store') === 1 || $this->request->getParam('scope') === 'stores') { $scope = 'stores'; @@ -437,10 +426,12 @@ public function getScope() /** * Revert last changes made in module - * @param $activityId - * @return array + * @return array{ + * error: bool, + * message: string|Phrase + * } */ - public function revertActivity($activityId) + public function revertActivity(int $activityId): array { $result = [ 'error' => true, @@ -458,7 +449,7 @@ public function revertActivity($activityId) $activityModel->save(); $result['error'] = false; - $this->status->markSuccess((int)$activityId); + $this->status->markSuccess($activityId); $this->messageManager->addSuccessMessage(__('Activity data has been reverted successfully')); } } @@ -472,9 +463,6 @@ public function revertActivity($activityId) /** * Convert module and action name to user readable format - * @param string $name - * @param string $delimiter - * @return string */ public function escapeString(string $name, string $delimiter = ' '): string { @@ -494,9 +482,6 @@ public function escapeString(string $name, string $delimiter = ' '): string /** * Check action to skip - * @param string $module - * @param string $fullAction - * @return bool */ public function isValidAction(string $module, string $fullAction): bool { @@ -509,8 +494,6 @@ public function isValidAction(string $module, string $fullAction): bool /** * Track page visit history - * @param string $module - * @return void */ public function addPageVisitLog(string $module): void { From 544d428d2a25d542a5f3eedaf874d755ca94f4a7 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 16:48:16 +0100 Subject: [PATCH 09/28] Add type declarations and improve type safety in Data helper List of changes: - Added explicit parameter type hints (`string $path`, `string $module`) to `getConfigValue` and `getActivityModuleName` methods. - Added return type declarations (`: array`, `: string`) to `getAllActions` and `getActivityModuleName` methods. - Updated `isWildCardModel` to use `$model::class` for retrieving class name, enhancing readability and consistency. - Improved overall type safety and aligned with modern PHP standards. --- Helper/Data.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index bd5a32f..fc88135 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -102,7 +102,7 @@ public function isPageVisitEnable(): bool * @param $path * @return mixed|false */ - public function getConfigValue($path) + public function getConfigValue(string $path) { $moduleValue = $this->scopeConfig->getValue( constant( @@ -131,7 +131,7 @@ public function getActionTranslatedLabel(string $action): string * Get all actions * @return array */ - public function getAllActions() + public function getAllActions(): array { return $this->config->getActions(); } @@ -140,7 +140,7 @@ public function getAllActions() * Get activity module name * @return string */ - public function getActivityModuleName($module) + public function getActivityModuleName(string $module) { return $this->config->getActivityModuleName($module); } @@ -152,7 +152,7 @@ public function getActivityModuleName($module) */ public static function isWildCardModel($model): bool { - $model = is_string($model) ? $model : get_class($model); + $model = is_string($model) ? $model : $model::class; return in_array($model, self::$wildcardModels, true); } } From 987a220e0d14610b8d1d4802d53937799a5c5a6c Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 16:48:27 +0100 Subject: [PATCH 10/28] Add type casting to enhance type safety in Revert controller List of changes: - Added explicit type casting to `$activityId` by casting it to `(int)` in the `revertActivity` method. - Improved type safety and consistency in `MageOS\AdminActivityLog\Controller\Adminhtml\Activity\Revert`. --- Controller/Adminhtml/Activity/Revert.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller/Adminhtml/Activity/Revert.php b/Controller/Adminhtml/Activity/Revert.php index 1b1d760..9c25ce2 100644 --- a/Controller/Adminhtml/Activity/Revert.php +++ b/Controller/Adminhtml/Activity/Revert.php @@ -41,7 +41,7 @@ public function execute() { $activityId = $this->getRequest()->getParam('id'); - $result = $this->processor->revertActivity($activityId); + $result = $this->processor->revertActivity((int)$activityId); $json = $this->resultJsonFactory->create(); $json->setData($result); From 544a19b356f8311f148ff413cbd6c6f9e9ad7ba7 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 16:48:38 +0100 Subject: [PATCH 11/28] Add type declarations and improve method signatures in Status model List of changes: - Updated constants in `Status` class to include explicit `int` type declarations, enhancing type safety. - Added type hints (`int`) to method parameters in `markSuccess` and `markFail`, improving input validation and consistency. - Removed redundant PHPDoc comments for cleaner and more maintainable code. - Simplified `load` method calls by removing unnecessary `(int)` casting of `$activityId`. --- Model/Activity/Status.php | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/Model/Activity/Status.php b/Model/Activity/Status.php index 94ebcae..3dfa178 100644 --- a/Model/Activity/Status.php +++ b/Model/Activity/Status.php @@ -22,15 +22,11 @@ */ class Status { - public const ACTIVITY_NONE = 0; - public const ACTIVITY_REVERTABLE = 1; - public const ACTIVITY_REVERT_SUCCESS = 2; - public const ACTIVITY_FAIL = 3; + public const int ACTIVITY_NONE = 0; + public const int ACTIVITY_REVERTABLE = 1; + public const int ACTIVITY_REVERT_SUCCESS = 2; + public const int ACTIVITY_FAIL = 3; - /** - * Status constructor. - * @param ActivityFactory $activityFactory - */ public function __construct( protected readonly ActivityFactory $activityFactory ) { @@ -38,12 +34,10 @@ public function __construct( /** * Set success revert status - * @param $activityId - * @return void */ - public function markSuccess($activityId): void + public function markSuccess(int $activityId): void { - $activityModel = $this->activityFactory->create()->load((int)$activityId); + $activityModel = $this->activityFactory->create()->load($activityId); // After successful revert, activity is no longer revertable $activityModel->setIsRevertable(false); $activityModel->save(); @@ -51,12 +45,10 @@ public function markSuccess($activityId): void /** * Set fail revert status - * @param $activityId - * @return void */ - public function markFail($activityId): void + public function markFail(int $activityId): void { - $activityModel = $this->activityFactory->create()->load((int)$activityId); + $activityModel = $this->activityFactory->create()->load($activityId); // Revert attempt failed; keep activity revertable $activityModel->setIsRevertable(true); $activityModel->save(); From 9bfc9c92a24d92e592e6cd726a075804db4e99bf Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 18:55:48 +0100 Subject: [PATCH 12/28] Improve type safety and constructor design in ActivityLogListing List of changes: - Added `?JsonHelper` and `?DirectoryHelper` as optional dependencies in the `ActivityLogListing` constructor for enhanced flexibility. - Updated method signatures to include explicit type declarations (e.g., `?array` for `getLogListing` and `array` for `getAdminDetails`) for better type safety. - Refactored `getAdminDetails` method to simplify the construction of return data using an associative array. - Removed redundant PHPDoc comments to enhance code readability and maintainability. - Applied modern PHP conventions, aligning with existing updates across the module. --- Block/Adminhtml/ActivityLogListing.php | 50 +++++++++++++------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/Block/Adminhtml/ActivityLogListing.php b/Block/Adminhtml/ActivityLogListing.php index 53d6b2d..1258e9d 100644 --- a/Block/Adminhtml/ActivityLogListing.php +++ b/Block/Adminhtml/ActivityLogListing.php @@ -16,6 +16,8 @@ use Magento\Backend\Block\Template; use Magento\Backend\Block\Template\Context; +use Magento\Directory\Helper\Data as DirectoryHelper; +use Magento\Framework\Json\Helper\Data as JsonHelper; use MageOS\AdminActivityLog\Api\ActivityRepositoryInterface; use MageOS\AdminActivityLog\Helper\Browser; @@ -25,31 +27,31 @@ */ class ActivityLogListing extends Template { - /** - * Path to template file in theme. - * @var string - */ protected $_template = 'MageOS_AdminActivityLog::log_listing.phtml'; - /** - * ActivityLogListing constructor. - * @param Context $context - * @param ActivityRepositoryInterface $activityRepository - * @param Browser $browser - */ public function __construct( - Context $context, protected readonly ActivityRepositoryInterface $activityRepository, - protected readonly Browser $browser + protected readonly Browser $browser, + Context $context, + array $data = [], + ?JsonHelper $jsonHelper = null, + ?DirectoryHelper $directoryHelper = null ) { - parent::__construct($context); + parent::__construct($context, $data, $jsonHelper, $directoryHelper); } /** * Get admin activity log listing - * @return array + * + * @return null|array */ - public function getLogListing() + public function getLogListing(): ?array { $id = $this->getRequest()->getParam('id'); $data = $this->activityRepository->getActivityLog($id); @@ -58,7 +60,7 @@ public function getLogListing() /** * Get admin activity details - * @return array + * @return array */ public function getAdminDetails(): array { @@ -69,14 +71,14 @@ public function getAdminDetails(): array $this->browser->setUserAgent($activity->getUserAgent()); $browser = $this->browser->__toString(); - $logData = []; - $logData['username'] = $activity->getUsername(); - $logData['module'] = $activity->getModule(); - $logData['name'] = $activity->getName(); - $logData['fullaction'] = $activity->getFullaction(); - $logData['browser'] = $browser; - $logData['date'] = $activity->getUpdatedAt(); - return $logData; + return [ + 'username' => $activity->getUsername(), + 'module' => $activity->getModule(), + 'name' => $activity->getName(), + 'fullaction' => $activity->getFullaction(), + 'browser' => $browser, + 'date' => $activity->getUpdatedAt() + ]; } public function getActivityRepository(): ActivityRepositoryInterface From e6c1e3c3a6896336339cd247568f11576b01b437 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 18:56:09 +0100 Subject: [PATCH 13/28] Remove redundant PHPDoc in Selector block List of changes: - Removed unnecessary `@return string` PHPDoc comment from `getRevertUrl` method. - Improved code readability and alignment with modern PHP practices by eliminating redundant annotations. --- Block/Adminhtml/Selector.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Block/Adminhtml/Selector.php b/Block/Adminhtml/Selector.php index 7f776a4..dc1ae60 100644 --- a/Block/Adminhtml/Selector.php +++ b/Block/Adminhtml/Selector.php @@ -24,7 +24,6 @@ class Selector extends Template { /** * Revert Activity Log action URL - * @return string */ public function getRevertUrl(): string { From 56f66e728bb7a1bce93062f71b982428e8a49276 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 18:58:34 +0100 Subject: [PATCH 14/28] Remove redundant PHPDoc and improve method structure in Observers List of changes: - Removed redundant constructor and method-level PHPDoc comments from `SaveAfter` and `SaveBefore` classes to enhance code clarity. - Adjusted the placement of `benchmark->start` calls in `execute` methods for consistent and logical execution flow. - Improved code readability by aligning with modern PHP conventions and removing unnecessary annotations. --- Observer/SaveAfter.php | 17 ++++------------- Observer/SaveBefore.php | 17 +++-------------- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/Observer/SaveAfter.php b/Observer/SaveAfter.php index efe8e93..187934e 100644 --- a/Observer/SaveAfter.php +++ b/Observer/SaveAfter.php @@ -29,12 +29,6 @@ class SaveAfter implements ObserverInterface public const ACTION_MASSCANCEL = 'massCancel'; public const SYSTEM_CONFIG = 'adminhtml_system_config_save'; - /** - * SaveAfter constructor. - * @param Processor $processor - * @param Helper $helper - * @param Benchmark $benchmark - */ public function __construct( protected readonly Processor $processor, protected readonly Helper $helper, @@ -42,18 +36,14 @@ public function __construct( ) { } - /** - * Save after - * @param Observer $observer - * @return void - */ public function execute(Observer $observer): void { - $this->benchmark->start(__METHOD__); - if (!$this->helper->isEnable()) { return; } + + $this->benchmark->start(__METHOD__); + $object = $observer->getEvent()->getObject(); if ($object->getCheckIfIsNew()) { if ($this->processor->getInitAction() === self::SYSTEM_CONFIG) { @@ -66,6 +56,7 @@ public function execute(Observer $observer): void } $this->processor->modelEditAfter($object); } + $this->benchmark->end(__METHOD__); } } diff --git a/Observer/SaveBefore.php b/Observer/SaveBefore.php index 227d0d1..b31829e 100644 --- a/Observer/SaveBefore.php +++ b/Observer/SaveBefore.php @@ -27,13 +27,6 @@ */ class SaveBefore implements ObserverInterface { - /** - * SaveBefore constructor. - * @param Helper $helper - * @param Processor $processor - * @param ActivityRepositoryInterface $activityRepository - * @param Benchmark $benchmark - */ public function __construct( protected readonly Helper $helper, protected readonly Processor $processor, @@ -42,19 +35,14 @@ public function __construct( ) { } - /** - * Save before - * @param Observer $observer - * @return void - */ public function execute(Observer $observer): void { - $this->benchmark->start(__METHOD__); - if (!$this->helper->isEnable()) { return; } + $this->benchmark->start(__METHOD__); + $object = $observer->getEvent()->getObject(); if ((int)$object->getId() === 0) { $object->setCheckIfIsNew(true); @@ -71,6 +59,7 @@ public function execute(Observer $observer): void } } } + $this->benchmark->end(__METHOD__); } } From 4460e143d27d3e0ee3d59aeab621a3a63d52d128 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 19:03:15 +0100 Subject: [PATCH 15/28] Refactor Observers for improved type safety and readability List of changes: - Replaced `protected readonly` properties with `private readonly` in constructors across observer classes for better access control and encapsulation. - Removed redundant PHPDoc comments from constructors and execute methods in all observer classes to enhance code clarity and alignment with modern PHP conventions. - Added explicit `string` type declaration for constants like `SYSTEM_CONFIG` and `ACTION_MASSCANCEL` in `SaveAfter` and `DeleteAfter` observers. - Adjusted the order of `benchmark->start` calls within execute methods to ensure consistent and logical execution flow. - Refactored redundant multi-line method call chaining into concise single-line calls for `loginRepository` in `LoginSuccess` and `LoginFailed` observers. --- Observer/DeleteAfter.php | 24 +++++++----------------- Observer/LoadAfter.php | 22 +++++++--------------- Observer/LoginFailed.php | 27 ++++++++------------------- Observer/LoginSuccess.php | 23 +++++------------------ Observer/PostDispatch.php | 12 +++--------- Observer/SaveAfter.php | 10 +++++----- Observer/SaveBefore.php | 8 ++++---- 7 files changed, 39 insertions(+), 87 deletions(-) diff --git a/Observer/DeleteAfter.php b/Observer/DeleteAfter.php index f872337..d4238d9 100644 --- a/Observer/DeleteAfter.php +++ b/Observer/DeleteAfter.php @@ -26,39 +26,29 @@ */ class DeleteAfter implements ObserverInterface { - public const SYSTEM_CONFIG = 'adminhtml_system_config_save'; + public const string SYSTEM_CONFIG = 'adminhtml_system_config_save'; - /** - * DeleteAfter constructor. - * @param Processor $processor - * @param Helper $helper - * @param Benchmark $benchmark - */ public function __construct( - protected readonly Processor $processor, - protected readonly Helper $helper, - protected readonly Benchmark $benchmark + private readonly Processor $processor, + private readonly Helper $helper, + private readonly Benchmark $benchmark ) { } - /** - * Delete after - * - * @param Observer $observer - * @return void - */ public function execute(Observer $observer): void { - $this->benchmark->start(__METHOD__); if (!$this->helper->isEnable()) { return; } + $this->benchmark->start(__METHOD__); + $object = $observer->getEvent()->getObject(); if ($this->processor->validate($object) && ($this->processor->getInitAction() === self::SYSTEM_CONFIG)) { $this->processor->modelEditAfter($object); } $this->processor->modelDeleteAfter($object); + $this->benchmark->end(__METHOD__); } } diff --git a/Observer/LoadAfter.php b/Observer/LoadAfter.php index 300ff5e..4ade81e 100644 --- a/Observer/LoadAfter.php +++ b/Observer/LoadAfter.php @@ -26,32 +26,24 @@ */ class LoadAfter implements ObserverInterface { - /** - * LoadAfter constructor. - * @param Processor $processor - * @param Data $helper - * @param Benchmark $benchmark - */ public function __construct( - protected readonly Processor $processor, - protected readonly Data $helper, - protected readonly Benchmark $benchmark + private readonly Processor $processor, + private readonly Data $helper, + private readonly Benchmark $benchmark ) { } - /** - * Delete after - * @param Observer $observer - * @return void - */ public function execute(Observer $observer): void { - $this->benchmark->start(__METHOD__); if (!$this->helper->isEnable()) { return; } + + $this->benchmark->start(__METHOD__); + $object = $observer->getEvent()->getObject(); $this->processor->modelLoadAfter($object); + $this->benchmark->end(__METHOD__); } } diff --git a/Observer/LoginFailed.php b/Observer/LoginFailed.php index 23a2f8b..a0402b8 100644 --- a/Observer/LoginFailed.php +++ b/Observer/LoginFailed.php @@ -27,41 +27,30 @@ */ class LoginFailed implements ObserverInterface { - /** - * LoginFailed constructor. - * @param Helper $helper - * @param User $user - * @param LoginRepositoryInterface $loginRepository - * @param Benchmark $benchmark - */ public function __construct( - protected readonly Helper $helper, - protected readonly User $user, - protected readonly LoginRepositoryInterface $loginRepository, - protected readonly Benchmark $benchmark + private readonly Helper $helper, + private readonly User $user, + private readonly LoginRepositoryInterface $loginRepository, + private readonly Benchmark $benchmark ) { } - /** - * Login failed - * @param Observer $observer - * @return void - */ public function execute(Observer $observer): void { - $this->benchmark->start(__METHOD__); if (!$this->helper->isLoginEnable()) { return; } + $this->benchmark->start(__METHOD__); + $user = null; if ($observer->getUserName()) { $user = $this->user->loadByUsername($observer->getUserName()); } - $this->loginRepository - ->setUser($user) + $this->loginRepository->setUser($user) ->addFailedLog($observer->getException()->getMessage()); + $this->benchmark->end(__METHOD__); } } diff --git a/Observer/LoginSuccess.php b/Observer/LoginSuccess.php index 152c012..9da16eb 100644 --- a/Observer/LoginSuccess.php +++ b/Observer/LoginSuccess.php @@ -26,34 +26,21 @@ */ class LoginSuccess implements ObserverInterface { - /** - * LoginSuccess constructor. - * @param Helper $helper - * @param LoginRepositoryInterface $loginRepository - * @param Benchmark $benchmark - */ public function __construct( - protected readonly Helper $helper, - protected readonly LoginRepositoryInterface $loginRepository, - protected readonly Benchmark $benchmark + private readonly Helper $helper, + private readonly LoginRepositoryInterface $loginRepository, + private readonly Benchmark $benchmark ) { } - /** - * Login success - * @param Observer $observer - * @return void - */ public function execute(Observer $observer): void { - $this->benchmark->start(__METHOD__); if (!$this->helper->isLoginEnable()) { return; } - $this->loginRepository - ->setUser($observer->getUser()) - ->addSuccessLog(); + $this->benchmark->start(__METHOD__); + $this->loginRepository->setUser($observer->getUser())->addSuccessLog(); $this->benchmark->end(__METHOD__); } } diff --git a/Observer/PostDispatch.php b/Observer/PostDispatch.php index 9a009e2..fe15c5b 100644 --- a/Observer/PostDispatch.php +++ b/Observer/PostDispatch.php @@ -26,16 +26,10 @@ */ class PostDispatch implements ObserverInterface { - /** - * PostDispatch constructor. - * @param Processor $processor - * @param Helper $helper - * @param Benchmark $benchmark - */ public function __construct( - protected readonly Processor $processor, - protected readonly Helper $helper, - protected readonly Benchmark $benchmark + private readonly Processor $processor, + private readonly Helper $helper, + private readonly Benchmark $benchmark ) { } diff --git a/Observer/SaveAfter.php b/Observer/SaveAfter.php index 187934e..ed45e18 100644 --- a/Observer/SaveAfter.php +++ b/Observer/SaveAfter.php @@ -26,13 +26,13 @@ */ class SaveAfter implements ObserverInterface { - public const ACTION_MASSCANCEL = 'massCancel'; - public const SYSTEM_CONFIG = 'adminhtml_system_config_save'; + public const string ACTION_MASSCANCEL = 'massCancel'; + public const string SYSTEM_CONFIG = 'adminhtml_system_config_save'; public function __construct( - protected readonly Processor $processor, - protected readonly Helper $helper, - protected readonly Benchmark $benchmark + private readonly Processor $processor, + private readonly Helper $helper, + private readonly Benchmark $benchmark ) { } diff --git a/Observer/SaveBefore.php b/Observer/SaveBefore.php index b31829e..16d3e4b 100644 --- a/Observer/SaveBefore.php +++ b/Observer/SaveBefore.php @@ -28,10 +28,10 @@ class SaveBefore implements ObserverInterface { public function __construct( - protected readonly Helper $helper, - protected readonly Processor $processor, - protected readonly ActivityRepositoryInterface $activityRepository, - protected readonly Benchmark $benchmark + private readonly Helper $helper, + private readonly Processor $processor, + private readonly ActivityRepositoryInterface $activityRepository, + private readonly Benchmark $benchmark ) { } From 4e12ea37c53dc859a372dd68d2d0e1ee5cc0d541 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 19:07:30 +0100 Subject: [PATCH 16/28] Refactor Action plugin for improved type safety and encapsulation List of changes: - Replaced `ActionInterface` with `AbstractAction` in method signatures for better alignment with Magento's action structure. - Changed `protected readonly` properties to `private readonly` in the constructor to enhance encapsulation and access control. - Removed redundant PHPDoc comments from the class and method declarations, adhering to modern PHP conventions. - Streamlined method parameter names and usage to improve consistency and readability. - Adjusted `beforeDispatch` method to use `$subject` instead of `$controller`, ensuring clarity and standardization in variable naming. --- Plugin/App/Action.php | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/Plugin/App/Action.php b/Plugin/App/Action.php index b5297c7..b918f8d 100644 --- a/Plugin/App/Action.php +++ b/Plugin/App/Action.php @@ -14,7 +14,7 @@ namespace MageOS\AdminActivityLog\Plugin\App; -use Magento\Framework\App\ActionInterface; +use Magento\Framework\App\Action\AbstractAction; use MageOS\AdminActivityLog\Helper\Benchmark; use MageOS\AdminActivityLog\Model\Processor; @@ -24,31 +24,24 @@ */ class Action { - /** - * Action constructor. - * @param Processor $processor - * @param Benchmark $benchmark - */ public function __construct( - protected readonly Processor $processor, - protected readonly Benchmark $benchmark + private readonly Processor $processor, + private readonly Benchmark $benchmark ) { } /** * Get before dispatch data - * - * @param ActionInterface $controller - * @return void */ - public function beforeDispatch(ActionInterface $controller): void - { + public function beforeDispatch( + AbstractAction $subject + ): void { $this->benchmark->start(__METHOD__); - $actionName = $controller->getRequest()->getActionName(); - $fullActionName = $controller->getRequest()->getFullActionName(); + $actionName = $subject->getRequest()->getActionName(); + $fullActionName = $subject->getRequest()->getFullActionName(); $this->processor->init($fullActionName, $actionName); - $this->processor->addPageVisitLog($controller->getRequest()->getModuleName()); + $this->processor->addPageVisitLog($subject->getRequest()->getModuleName()); $this->benchmark->end(__METHOD__); } } From 60b486643b9b22d2f51d0057676d756ad5b2c9c1 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 19:09:04 +0100 Subject: [PATCH 17/28] Refactor Delete plugin for improved type safety and readability List of changes: - Replaced `protected readonly` property in the constructor with `private readonly` for enhanced encapsulation. - Updated method signature of `aroundDelete` to use `AbstractModel` for type safety and alignment with Magento conventions. - Refactored redundant variable naming, replacing `$object` with `$user` for clarity and consistency. - Removed unnecessary PHPDoc comments for cleaner and more maintainable code. - Simplified method logic by aligning with modern PHP standards and removing repetitive calls. --- Plugin/User/Delete.php | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/Plugin/User/Delete.php b/Plugin/User/Delete.php index d27d95f..c1914a4 100644 --- a/Plugin/User/Delete.php +++ b/Plugin/User/Delete.php @@ -14,6 +14,7 @@ namespace MageOS\AdminActivityLog\Plugin\User; +use Magento\Framework\Model\AbstractModel; use Magento\User\Model\ResourceModel\User; use MageOS\AdminActivityLog\Helper\Benchmark; @@ -23,28 +24,19 @@ */ class Delete { - /** - * Delete constructor. - * @param Benchmark $benchmark - */ public function __construct( - protected readonly Benchmark $benchmark + private readonly Benchmark $benchmark ) { } - /** - * @param User $user - * @param callable $proceed - * @param $object - * @return mixed - */ - public function aroundDelete(User $user, callable $proceed, $object) + public function aroundDelete(User $subject, callable $proceed, AbstractModel $user): bool { $this->benchmark->start(__METHOD__); - $object->load($object->getId()); + $user->load($user->getId()); - $result = $proceed($object); - $object->afterDelete(); + /** @var bool $result */ + $result = $proceed($user); + $user->afterDelete(); $this->benchmark->end(__METHOD__); return $result; From 44d76f22300473d7ce35ce14a005c9386d353e17 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 19:10:39 +0100 Subject: [PATCH 18/28] Refactor Auth plugin to improve type safety and encapsulation List of changes: - Replaced `protected readonly` properties in the constructor with `private readonly` to enhance encapsulation and access control. - Removed redundant PHPDoc comments to improve code clarity and adhere to modern PHP conventions. - Updated the `aroundLogout` method signature to include a `void` return type for better type safety. - Removed unnecessary variable usage in `aroundLogout`, simplifying the method logic and aligning with modern PHP practices. --- Plugin/Auth.php | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/Plugin/Auth.php b/Plugin/Auth.php index 63bd5b2..993d100 100644 --- a/Plugin/Auth.php +++ b/Plugin/Auth.php @@ -24,34 +24,27 @@ */ class Auth { - /** - * Auth constructor. - * @param Helper $helper - * @param LoginRepositoryInterface $loginRepository - * @param Benchmark $benchmark - */ public function __construct( - protected readonly Helper $helper, - protected readonly LoginRepositoryInterface $loginRepository, - protected readonly Benchmark $benchmark + private readonly Helper $helper, + private readonly LoginRepositoryInterface $loginRepository, + private readonly Benchmark $benchmark ) { } /** * Track admin logout activity - * @param \Magento\Backend\Model\Auth $auth - * @param callable $proceed - * @return mixed */ - public function aroundLogout(\Magento\Backend\Model\Auth $auth, callable $proceed) + public function aroundLogout(\Magento\Backend\Model\Auth $auth, callable $proceed): void { $this->benchmark->start(__METHOD__); + if ($this->helper->isLoginEnable()) { $user = $auth->getAuthStorage()->getUser(); $this->loginRepository->setUser($user)->addLogoutLog(); } - $result = $proceed(); + + $proceed(); + $this->benchmark->end(__METHOD__); - return $result; } } From e8afd3134b023a0d11766da0c13ba6305b11f8f7 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 19:13:20 +0100 Subject: [PATCH 19/28] Rename plugin classes for better consistency and clarity List of changes: - Renamed `Action` to `ActionPlugin` to clarify its purpose as a plugin. - Updated `Auth` to `AuthPlugin` and adjusted type usage in the `aroundLogout` method for improved alignment with naming conventions. - Changed `Delete` to `DeletePlugin` for consistency with other plugin naming patterns. - Updated `di.xml` to reflect the new class names in plugin declarations. - Improved overall code clarity and maintained adherence to module structure and Magento standards. --- Plugin/App/{Action.php => ActionPlugin.php} | 2 +- Plugin/{Auth.php => AuthPlugin.php} | 5 +++-- Plugin/User/{Delete.php => DeletePlugin.php} | 2 +- etc/adminhtml/di.xml | 6 +++--- 4 files changed, 8 insertions(+), 7 deletions(-) rename Plugin/App/{Action.php => ActionPlugin.php} (98%) rename Plugin/{Auth.php => AuthPlugin.php} (91%) rename Plugin/User/{Delete.php => DeletePlugin.php} (98%) diff --git a/Plugin/App/Action.php b/Plugin/App/ActionPlugin.php similarity index 98% rename from Plugin/App/Action.php rename to Plugin/App/ActionPlugin.php index b918f8d..263773b 100644 --- a/Plugin/App/Action.php +++ b/Plugin/App/ActionPlugin.php @@ -22,7 +22,7 @@ * Class Action * @package MageOS\AdminActivityLog\Plugin\App */ -class Action +class ActionPlugin { public function __construct( private readonly Processor $processor, diff --git a/Plugin/Auth.php b/Plugin/AuthPlugin.php similarity index 91% rename from Plugin/Auth.php rename to Plugin/AuthPlugin.php index 993d100..5af85b3 100644 --- a/Plugin/Auth.php +++ b/Plugin/AuthPlugin.php @@ -14,6 +14,7 @@ namespace MageOS\AdminActivityLog\Plugin; +use Magento\Backend\Model\Auth; use MageOS\AdminActivityLog\Api\LoginRepositoryInterface; use MageOS\AdminActivityLog\Helper\Benchmark; use MageOS\AdminActivityLog\Helper\Data as Helper; @@ -22,7 +23,7 @@ * Class Auth * @package MageOS\AdminActivityLog\Plugin */ -class Auth +class AuthPlugin { public function __construct( private readonly Helper $helper, @@ -34,7 +35,7 @@ public function __construct( /** * Track admin logout activity */ - public function aroundLogout(\Magento\Backend\Model\Auth $auth, callable $proceed): void + public function aroundLogout(Auth $auth, callable $proceed): void { $this->benchmark->start(__METHOD__); diff --git a/Plugin/User/Delete.php b/Plugin/User/DeletePlugin.php similarity index 98% rename from Plugin/User/Delete.php rename to Plugin/User/DeletePlugin.php index c1914a4..8cd0f77 100644 --- a/Plugin/User/Delete.php +++ b/Plugin/User/DeletePlugin.php @@ -22,7 +22,7 @@ * Class Delete * @package MageOS\AdminActivityLog\Plugin\User */ -class Delete +class DeletePlugin { public function __construct( private readonly Benchmark $benchmark diff --git a/etc/adminhtml/di.xml b/etc/adminhtml/di.xml index 771fc29..e7de35a 100644 --- a/etc/adminhtml/di.xml +++ b/etc/adminhtml/di.xml @@ -15,12 +15,12 @@ --> - + - + - + From 57ad91c2f168a445f1eeb7ba5d4fc3ab03426ea4 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 20:45:14 +0100 Subject: [PATCH 20/28] Refactor column classes for improved type safety and clarity List of changes: - Replaced generic array type annotations with precise `array` or `array` declarations in constructors and methods across column classes. - Added explicit property types (e.g., `array` and `string[]`) for better type safety, including constants such as `URL_COUNT` and `KEY_FIELD`. - Removed redundant PHPDoc comments from constructors and method annotations to enhance code readability and align with modern PHP standards. - Updated method signatures to use type-safe constructs, such as `array|string` instead of `string|array`, improving clarity in `ItemColumn` and similar classes. - Applied `private readonly` for constructor dependencies wherever appropriate, following modern PHP practices for better encapsulation. --- .../Listing/Column/ActionType/Options.php | 6 +--- .../Listing/Column/ActionTypeColumn.php | 13 +++---- Ui/Component/Listing/Column/BrowserColumn.php | 16 +++------ Ui/Component/Listing/Column/ItemColumn.php | 35 ++++++------------- .../Listing/Column/RevertStatusColumn.php | 4 +-- Ui/Component/Listing/Column/StatusColumn.php | 4 +-- Ui/Component/Listing/Column/StoreColumn.php | 5 ++- .../Listing/Column/UserAgentColumn.php | 15 +++----- Ui/Component/Listing/Column/ViewAction.php | 18 +++------- 9 files changed, 36 insertions(+), 80 deletions(-) diff --git a/Ui/Component/Listing/Column/ActionType/Options.php b/Ui/Component/Listing/Column/ActionType/Options.php index ef76451..b06b265 100644 --- a/Ui/Component/Listing/Column/ActionType/Options.php +++ b/Ui/Component/Listing/Column/ActionType/Options.php @@ -23,12 +23,8 @@ */ class Options implements ArrayInterface { - /** - * Options constructor. - * @param Data $helper - */ public function __construct( - protected readonly Data $helper + private readonly Data $helper ) { } diff --git a/Ui/Component/Listing/Column/ActionTypeColumn.php b/Ui/Component/Listing/Column/ActionTypeColumn.php index fb893c9..a76d77f 100644 --- a/Ui/Component/Listing/Column/ActionTypeColumn.php +++ b/Ui/Component/Listing/Column/ActionTypeColumn.php @@ -26,12 +26,8 @@ class ActionTypeColumn extends Column { /** - * ActionTypeColumn constructor. - * @param ContextInterface $context - * @param UiComponentFactory $uiComponentFactory - * @param Helper $helper - * @param array $components - * @param array $data + * @param array $components + * @param array $data */ public function __construct( ContextInterface $context, @@ -44,9 +40,8 @@ public function __construct( } /** - * Prepare Data Source - * @param array $dataSource - * @return array + * @param array $dataSource + * @return array */ #[\Override] public function prepareDataSource(array $dataSource): array diff --git a/Ui/Component/Listing/Column/BrowserColumn.php b/Ui/Component/Listing/Column/BrowserColumn.php index 9a07031..e74333c 100644 --- a/Ui/Component/Listing/Column/BrowserColumn.php +++ b/Ui/Component/Listing/Column/BrowserColumn.php @@ -26,12 +26,8 @@ class BrowserColumn extends Column { /** - * BrowserColumn constructor. - * @param ContextInterface $context - * @param UiComponentFactory $uiComponentFactory - * @param Browser $browser - * @param array $components - * @param array $data + * @param array $components + * @param array $data */ public function __construct( ContextInterface $context, @@ -45,8 +41,7 @@ public function __construct( /** * Get user agent data - * @param array $item - * @return string + * @param array $item */ public function getAgent(array $item): string { @@ -56,9 +51,8 @@ public function getAgent(array $item): string } /** - * Prepare Data Source - * @param array $dataSource - * @return array + * @param array $dataSource + * @return array */ #[\Override] public function prepareDataSource(array $dataSource): array diff --git a/Ui/Component/Listing/Column/ItemColumn.php b/Ui/Component/Listing/Column/ItemColumn.php index 163874c..7a4a3f2 100644 --- a/Ui/Component/Listing/Column/ItemColumn.php +++ b/Ui/Component/Listing/Column/ItemColumn.php @@ -28,12 +28,12 @@ */ class ItemColumn extends Column { - public const URL_COUNT = 7; + public const int URL_COUNT = 7; /** - * @var array + * @var string[] */ - protected $allowedAttributes = [ + protected array $allowedAttributes = [ 'href', 'title', 'id', @@ -46,13 +46,8 @@ class ItemColumn extends Column protected readonly FilterManager $filterManager; /** - * ItemColumn constructor. - * @param ContextInterface $context - * @param Context $contexts - * @param UiComponentFactory $uiComponentFactory - * @param UrlInterface $backendUrl - * @param array $components - * @param array $data + * @param array $components + * @param array $data */ public function __construct( ContextInterface $context, @@ -68,19 +63,16 @@ public function __construct( } /** - * Escape HTML entities - * @param string|array $data - * @param array|null $allowedTags - * @return string + * @param string|array $data + * @param string[]|null $allowedTags */ - public function escapeHtml($data, ?array $allowedTags = null): string + public function escapeHtml(array|string $data, ?array $allowedTags = null): string { return $this->escaper->escapeHtml($data, $allowedTags); } /** * Render block HTML - * @return string */ public function _toHtml(): string { @@ -94,7 +86,6 @@ public function _toHtml(): string /** * Prepare link attributes as serialized and formatted string - * @return string */ public function getLinkAttributes(): string { @@ -119,7 +110,6 @@ public function getLinkAttributes(): string * @param string $valueSeparator * @param string $fieldSeparator * @param string $quote - * @return string */ #[\Override] public function serialize($keys = [], $valueSeparator = '=', $fieldSeparator = ' ', $quote = '"'): string @@ -133,8 +123,6 @@ public function serialize($keys = [], $valueSeparator = '=', $fieldSeparator = ' /** * Convert action to url - * @param string $url - * @return string */ public function prepareUrl(string $url): string { @@ -156,8 +144,7 @@ public function prepareUrl(string $url): string /** * Initialize parameter for link - * @param array $item - * @return void + * @param array $item */ protected function initLinkParams(array $item): void { @@ -169,8 +156,8 @@ protected function initLinkParams(array $item): void /** * Prepare Data Source - * @param array $dataSource - * @return array + * @param array $dataSource + * @return array */ #[\Override] public function prepareDataSource(array $dataSource): array diff --git a/Ui/Component/Listing/Column/RevertStatusColumn.php b/Ui/Component/Listing/Column/RevertStatusColumn.php index 8ab9944..bef0767 100644 --- a/Ui/Component/Listing/Column/RevertStatusColumn.php +++ b/Ui/Component/Listing/Column/RevertStatusColumn.php @@ -24,8 +24,8 @@ class RevertStatusColumn extends Column { /** * Prepare Data Source - * @param array $dataSource - * @return array + * @param array $dataSource + * @return array */ #[\Override] public function prepareDataSource(array $dataSource): array diff --git a/Ui/Component/Listing/Column/StatusColumn.php b/Ui/Component/Listing/Column/StatusColumn.php index f1daf8f..0339830 100644 --- a/Ui/Component/Listing/Column/StatusColumn.php +++ b/Ui/Component/Listing/Column/StatusColumn.php @@ -37,8 +37,8 @@ public function __construct( /** * Prepare Data Source - * @param array $dataSource - * @return array + * @param array $dataSource + * @return array */ #[\Override] public function prepareDataSource(array $dataSource): array diff --git a/Ui/Component/Listing/Column/StoreColumn.php b/Ui/Component/Listing/Column/StoreColumn.php index 6f2eed6..cab649b 100644 --- a/Ui/Component/Listing/Column/StoreColumn.php +++ b/Ui/Component/Listing/Column/StoreColumn.php @@ -22,12 +22,11 @@ */ class StoreColumn extends Store { - public const KEY_FIELD = 'store_id'; + public const string KEY_FIELD = 'store_id'; /** * Prepare Item - * @param array $item - * @return string + * @param array $item */ #[\Override] public function prepareItem(array $item): string diff --git a/Ui/Component/Listing/Column/UserAgentColumn.php b/Ui/Component/Listing/Column/UserAgentColumn.php index 840fa3c..50d7360 100644 --- a/Ui/Component/Listing/Column/UserAgentColumn.php +++ b/Ui/Component/Listing/Column/UserAgentColumn.php @@ -26,12 +26,8 @@ class UserAgentColumn extends Column { /** - * UserAgentColumn constructor. - * @param ContextInterface $context - * @param UiComponentFactory $uiComponentFactory - * @param Browser $browser - * @param array $components - * @param array $data + * @param array $components + * @param array $data */ public function __construct( ContextInterface $context, @@ -45,8 +41,7 @@ public function __construct( /** * Get user agent data - * @param array $item - * @return string + * @param array $item */ public function getAgent(array $item): string { @@ -57,8 +52,8 @@ public function getAgent(array $item): string /** * Prepare Data Source - * @param array $dataSource - * @return array + * @param array $dataSource + * @return array */ #[\Override] public function prepareDataSource(array $dataSource): array diff --git a/Ui/Component/Listing/Column/ViewAction.php b/Ui/Component/Listing/Column/ViewAction.php index 56a140a..c000ef8 100644 --- a/Ui/Component/Listing/Column/ViewAction.php +++ b/Ui/Component/Listing/Column/ViewAction.php @@ -28,13 +28,8 @@ class ViewAction extends Column { /** - * ViewAction constructor. - * @param ContextInterface $context - * @param UiComponentFactory $uiComponentFactory - * @param UrlInterface $urlBuilder - * @param LayoutInterface $layout - * @param array $components - * @param array $data + * @param array $components + * @param array $data */ public function __construct( ContextInterface $context, @@ -47,10 +42,6 @@ public function __construct( parent::__construct($context, $uiComponentFactory, $components, $data); } - /** - * Get item url - * @return string - */ public function getViewUrl(): string { return $this->urlBuilder->getUrl( @@ -59,9 +50,8 @@ public function getViewUrl(): string } /** - * Prepare Data Source - * @param array $dataSource - * @return array + * @param array $dataSource + * @return array */ #[\Override] public function prepareDataSource(array $dataSource): array From c7c79c81938d1a8d7f8b2da099783b3ff18202ee Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 21:14:36 +0100 Subject: [PATCH 21/28] Remove redundant PHPDoc comments from resource models and collections List of changes: - Eliminated unnecessary PHPDoc comments from the `_construct` methods in resource model and collection classes across the `AdminActivityLog` module. - Improved code readability and alignment with modern PHP standards by removing redundant annotations. - Retained functionality while simplifying the codebase for better maintainability. --- Model/ResourceModel/Activity.php | 4 ---- Model/ResourceModel/Activity/Collection.php | 4 ---- Model/ResourceModel/ActivityLog.php | 4 ---- Model/ResourceModel/ActivityLog/Collection.php | 4 ---- Model/ResourceModel/ActivityLogDetail.php | 4 ---- Model/ResourceModel/ActivityLogDetail/Collection.php | 4 ---- Model/ResourceModel/Login.php | 4 ---- Model/ResourceModel/Login/Collection.php | 4 ---- 8 files changed, 32 deletions(-) diff --git a/Model/ResourceModel/Activity.php b/Model/ResourceModel/Activity.php index 0f9d5b0..42962a4 100644 --- a/Model/ResourceModel/Activity.php +++ b/Model/ResourceModel/Activity.php @@ -22,10 +22,6 @@ */ class Activity extends AbstractDb { - /** - * Initialize resource model - * @return void - */ public function _construct(): void { $this->_init('admin_activity', 'entity_id'); diff --git a/Model/ResourceModel/Activity/Collection.php b/Model/ResourceModel/Activity/Collection.php index 79e5921..d9b9843 100644 --- a/Model/ResourceModel/Activity/Collection.php +++ b/Model/ResourceModel/Activity/Collection.php @@ -23,10 +23,6 @@ */ class Collection extends AbstractCollection { - /** - * Define resource model - * @return void - */ public function _construct(): void { $this->_init( diff --git a/Model/ResourceModel/ActivityLog.php b/Model/ResourceModel/ActivityLog.php index 45e5fff..7829f42 100644 --- a/Model/ResourceModel/ActivityLog.php +++ b/Model/ResourceModel/ActivityLog.php @@ -22,10 +22,6 @@ */ class ActivityLog extends AbstractDb { - /** - * Initialize resource model - * @return void - */ public function _construct(): void { $this->_init('admin_activity_log', 'entity_id'); diff --git a/Model/ResourceModel/ActivityLog/Collection.php b/Model/ResourceModel/ActivityLog/Collection.php index cfba9e4..db37571 100644 --- a/Model/ResourceModel/ActivityLog/Collection.php +++ b/Model/ResourceModel/ActivityLog/Collection.php @@ -23,10 +23,6 @@ */ class Collection extends AbstractCollection { - /** - * Define resource model - * @return void - */ public function _construct(): void { $this->_init( diff --git a/Model/ResourceModel/ActivityLogDetail.php b/Model/ResourceModel/ActivityLogDetail.php index 7afee68..7e28d01 100644 --- a/Model/ResourceModel/ActivityLogDetail.php +++ b/Model/ResourceModel/ActivityLogDetail.php @@ -22,10 +22,6 @@ */ class ActivityLogDetail extends AbstractDb { - /** - * Initialize resource model - * @return void - */ public function _construct(): void { $this->_init('admin_activity_detail', 'entity_id'); diff --git a/Model/ResourceModel/ActivityLogDetail/Collection.php b/Model/ResourceModel/ActivityLogDetail/Collection.php index abcdf52..f1ba5f4 100644 --- a/Model/ResourceModel/ActivityLogDetail/Collection.php +++ b/Model/ResourceModel/ActivityLogDetail/Collection.php @@ -23,10 +23,6 @@ */ class Collection extends AbstractCollection { - /** - * Define resource model - * @return void - */ public function _construct(): void { $this->_init( diff --git a/Model/ResourceModel/Login.php b/Model/ResourceModel/Login.php index 6614d78..5eb84e0 100644 --- a/Model/ResourceModel/Login.php +++ b/Model/ResourceModel/Login.php @@ -22,10 +22,6 @@ */ class Login extends AbstractDb { - /** - * Initialize resource model - * @return void - */ public function _construct(): void { $this->_init('admin_login_log', 'entity_id'); diff --git a/Model/ResourceModel/Login/Collection.php b/Model/ResourceModel/Login/Collection.php index 1e38e0b..4ee18a7 100644 --- a/Model/ResourceModel/Login/Collection.php +++ b/Model/ResourceModel/Login/Collection.php @@ -23,10 +23,6 @@ */ class Collection extends AbstractCollection { - /** - * Define resource model - * @return void - */ public function _construct(): void { $this->_init( From 7bde7406ad8dd76dd5c3b4ddf88da5170bfc3b84 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 21:14:56 +0100 Subject: [PATCH 22/28] Improve type safety and modernize TrackField helper List of changes: - Updated class constants to include explicit `string` type declarations for enhanced clarity and type enforcement. - Refined method return types from `array` to `string[]` or more specific types where applicable for type safety. - Enhanced method parameters with explicit type declarations, such as `string` and `DataObject`, improving code readability. - Updated PHPDoc annotations for complex return types to better describe returned data structures. - Simplified and modernized the constructor by using `protected readonly` properties for dependency injection. - Removed redundancies and aligned code with modern PHP standards for improved maintainability. --- Helper/TrackField.php | 116 ++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 62 deletions(-) diff --git a/Helper/TrackField.php b/Helper/TrackField.php index 8e9907a..af0817b 100644 --- a/Helper/TrackField.php +++ b/Helper/TrackField.php @@ -26,16 +26,10 @@ */ class TrackField extends AbstractHelper { - public const SYSTEM_METHOD = 'getSystemConfigFieldData'; - public const THEME_METHOD = 'getThemeConfigFieldData'; - public const PRODUCT_METHOD = 'getProductFieldData'; + public const string SYSTEM_METHOD = 'getSystemConfigFieldData'; + public const string THEME_METHOD = 'getThemeConfigFieldData'; + public const string PRODUCT_METHOD = 'getProductFieldData'; - /** - * TrackField constructor. - * @param Context $context - * @param SystemConfig $systemConfig - * @param ThemeConfig $themeConfig - */ public function __construct( Context $context, protected readonly SystemConfig $systemConfig, @@ -46,7 +40,7 @@ public function __construct( /** * Get product module fields - * @return array + * @return string[] */ public function getProductFieldData(): array { @@ -75,7 +69,7 @@ public function getProductFieldData(): array /** * Get category module fields - * @return array + * @return string[] */ public function getCategoryFieldData(): array { @@ -88,7 +82,7 @@ public function getCategoryFieldData(): array /** * Get customer module fields - * @return array + * @return string[] */ public function getCustomerFieldData(): array { @@ -113,7 +107,7 @@ public function getCustomerFieldData(): array /** * Get customer group modules fields - * @return array + * @return string[] */ public function getCustomerGroupFieldData(): array { @@ -125,7 +119,7 @@ public function getCustomerGroupFieldData(): array /** * Get catalog promotion modules fields - * @return array + * @return string[] */ public function getCatalogPromotionFieldData(): array { @@ -138,7 +132,7 @@ public function getCatalogPromotionFieldData(): array /** * Get cart promotion modules fields - * @return array + * @return string[] */ public function getCartPromotionFieldData(): array { @@ -152,7 +146,7 @@ public function getCartPromotionFieldData(): array /** * Get email modules fields - * @return array + * @return string[] */ public function getEmailFieldData(): array { @@ -172,7 +166,7 @@ public function getEmailFieldData(): array /** * Get page modules fields - * @return array + * @return string[] */ public function getPageFieldData(): array { @@ -187,7 +181,7 @@ public function getPageFieldData(): array /** * Get block modules fields - * @return array + * @return string[] */ public function getBlockFieldData(): array { @@ -201,7 +195,7 @@ public function getBlockFieldData(): array /** * Get widget modules fields - * @return array + * @return string[] */ public function getWidgetFieldData(): array { @@ -213,7 +207,7 @@ public function getWidgetFieldData(): array /** * Get theme configuration field data - * @return array + * @return string[] */ public function getThemeConfigFieldData(): array { @@ -228,7 +222,7 @@ public function getThemeConfigFieldData(): array /** * Get theme schedule field data - * @return array + * @return string[] */ public function getThemeScheduleFieldData(): array { @@ -240,7 +234,7 @@ public function getThemeScheduleFieldData(): array /** * Get system config field data - * @return array + * @return string[] */ public function getSystemConfigFieldData(): array { @@ -251,7 +245,7 @@ public function getSystemConfigFieldData(): array /** * Get attribute modules fields - * @return array + * @return string[] */ public function getAttributeFieldData(): array { @@ -266,7 +260,7 @@ public function getAttributeFieldData(): array /** * Get attribute set modules fields - * @return array + * @return string[] */ public function getAttributeSetFieldData(): array { @@ -279,7 +273,7 @@ public function getAttributeSetFieldData(): array /** * Get attribute set modules fields - * @return array + * @return string[] */ public function getReviewRatingFieldData(): array { @@ -291,7 +285,7 @@ public function getReviewRatingFieldData(): array /** * Get review modules fields - * @return array + * @return string[] */ public function getReviewFieldData(): array { @@ -306,7 +300,7 @@ public function getReviewFieldData(): array /** * Get admin user modules fields - * @return array + * @return string[] */ public function getAdminUserFieldData(): array { @@ -323,7 +317,7 @@ public function getAdminUserFieldData(): array /** * Get admin user role modules fields - * @return array + * @return string[] */ public function getAdminUserRoleFieldData(): array { @@ -336,7 +330,7 @@ public function getAdminUserRoleFieldData(): array /** * Get order modules fields - * @return array + * @return string[] */ public function getOrderFieldData(): array { @@ -352,7 +346,7 @@ public function getOrderFieldData(): array /** * Get tax rule modules fields - * @return array + * @return string[] */ public function getTaxRuleFieldData(): array { @@ -366,7 +360,7 @@ public function getTaxRuleFieldData(): array /** * Get tax rate modules fields - * @return array + * @return string[] */ public function getTaxRateFieldData(): array { @@ -379,7 +373,7 @@ public function getTaxRateFieldData(): array /** * Get url rewrites modules fields - * @return array + * @return string[] */ public function getUrlRewriteFieldData(): array { @@ -391,7 +385,7 @@ public function getUrlRewriteFieldData(): array /** * Get search term modules fields - * @return array + * @return string[] */ public function getSearchTermFieldData(): array { @@ -404,7 +398,7 @@ public function getSearchTermFieldData(): array /** * Get search synonyms modules fields - * @return array + * @return array{} */ public function getSearchSynonymsFieldData(): array { @@ -413,7 +407,7 @@ public function getSearchSynonymsFieldData(): array /** * Get sitemap modules fields - * @return array + * @return string[] */ public function getSitemapFieldData(): array { @@ -427,7 +421,7 @@ public function getSitemapFieldData(): array /** * Get checkout agreement modules fields - * @return array + * @return string[] */ public function getCheckoutAgreementFieldData(): array { @@ -440,7 +434,7 @@ public function getCheckoutAgreementFieldData(): array /** * Get Order satus modules fields - * @return array + * @return string[] */ public function getOrderStatusFieldData(): array { @@ -452,7 +446,7 @@ public function getOrderStatusFieldData(): array /** * Get System store modules fields - * @return array + * @return string[] */ public function getSystemStoreFieldData(): array { @@ -463,7 +457,7 @@ public function getSystemStoreFieldData(): array /** * Get integration modules fields - * @return array + * @return string[] */ public function getIntegrationFieldData(): array { @@ -481,7 +475,7 @@ public function getIntegrationFieldData(): array /** * Get Edit fields which will skip - * @return array + * @return string[] */ public function getSkipEditFieldData(): array { @@ -524,10 +518,9 @@ public function getSkipEditFieldData(): array /** * Get all fields by method - * @param $method - * @return array + * @return string[] */ - public function getFields($method): array + public function getFields(string $method): array { $fieldArray = []; if (!empty($method) && method_exists($this, $method)) { @@ -538,11 +531,12 @@ public function getFields($method): array /** * Get added activity data - * @param $model - * @param $method - * @return array + * @return array{}|array */ - public function getAddData($model, $method): array + public function getAddData(DataObject $model, string $method): array { $skipFieldArray = $this->getFields($method); @@ -564,9 +558,10 @@ public function getAddData($model, $method): array /** * Get edited activity data - * @param DataObject $model - * @param string $method - * @return array + * @return array{}|array */ public function getEditData(DataObject $model, string $method): array { @@ -606,9 +601,10 @@ public function getEditData(DataObject $model, string $method): array /** * Get deleted activity data - * @param DataObject $model - * @param string $method - * @return array + * @return array{}|array */ public function getDeleteData(DataObject $model, string $method): array { @@ -632,9 +628,10 @@ public function getDeleteData(DataObject $model, string $method): array /** * Get wild data - * @param DataObject $model - * @param string $method - * @return array + * @return array{}|array */ public function getWildCardData(DataObject $model, string $method): array { @@ -655,13 +652,8 @@ public function getWildCardData(DataObject $model, string $method): array /** * Skip this fields while tracking activity log - * @param $model - * @param $key - * @param $value - * @param $skipFields - * @return bool */ - public function validateValue($model, $key, $value, $skipFields): bool + public function validateValue(DataObject $model, string $key, mixed $value, array $skipFields): bool { if (is_array($value) || is_object($value) || is_array($model->getOrigData($key)) || in_array($key, $skipFields)) { From 682034c43e93b9dc9f5dc9b65228e08e8848f298 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 21:15:11 +0100 Subject: [PATCH 23/28] Enhance type safety and simplify SystemConfig model List of changes: - Removed redundant PHPDoc comments from the `SystemConfig` class constructor and methods to improve clarity. - Updated method signatures by adding explicit parameter and return types for improved type safety, such as `DataObject` and typed array structures. - Refined complex return type annotations for `getEditData` to clearly describe the data structure being returned. - Simplified constructor using `protected readonly` dependencies for better maintainability and alignment with modern PHP practices. - Enhanced overall readability and maintainability by adhering to current PHP standards. --- Model/Activity/SystemConfig.php | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/Model/Activity/SystemConfig.php b/Model/Activity/SystemConfig.php index 77f1f3e..9e7020b 100644 --- a/Model/Activity/SystemConfig.php +++ b/Model/Activity/SystemConfig.php @@ -26,12 +26,6 @@ */ class SystemConfig implements ModelInterface { - /** - * SystemConfig constructor. - * @param DataObject $dataObject - * @param ValueFactory $valueFactory - * @param WriterInterface $configWriter - */ public function __construct( protected readonly DataObject $dataObject, protected readonly ValueFactory $valueFactory, @@ -41,10 +35,8 @@ public function __construct( /** * Get config path - * @param $model - * @return string */ - public function getPath($model): string + public function getPath(DataObject $model): string { if ($model->getData('path')) { return current( @@ -60,10 +52,8 @@ public function getPath($model): string /** * Get old activity data of system config module - * @param DataObject $model - * @return mixed */ - public function getOldData(DataObject $model) + public function getOldData(DataObject $model): DataObject { $path = $this->getPath($model); $systemData = $this->valueFactory->create()->getCollection()->addFieldToFilter( @@ -89,7 +79,10 @@ public function getOldData(DataObject $model) * Get edit activity data of system config module * @param DataObject $model * @param array $fieldArray - * @return array{old_value: mixed, new_value: mixed}[] + * @return array{}|array */ public function getEditData(DataObject $model, $fieldArray): array { From 90e6afc5b80ea7ca8978eb0d906ea190fdee76b5 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 21:16:53 +0100 Subject: [PATCH 24/28] Refactor ThemeConfig for improved type safety and maintainability List of changes: - Replaced redundant `ValueFactory` with `ConfigCollectionFactory` for collection handling in theme configurations. - Enhanced method signatures by adding precise parameter and return type declarations, such as `array` for improved type safety. - Updated `revertData` to utilize `Collection` for better type alignment and encapsulation. - Removed unnecessary PHPDoc comments to simplify and align with modern PHP standards. - Refactored constructor by using `protected readonly` properties, simplifying dependency injection and improving maintainability. - Streamlined old data retrieval and processing logic with the updated collection factory. --- Model/Activity/ThemeConfig.php | 75 +++++++++++++++------------------- 1 file changed, 34 insertions(+), 41 deletions(-) diff --git a/Model/Activity/ThemeConfig.php b/Model/Activity/ThemeConfig.php index 8b2b19b..a59dfae 100644 --- a/Model/Activity/ThemeConfig.php +++ b/Model/Activity/ThemeConfig.php @@ -14,11 +14,13 @@ namespace MageOS\AdminActivityLog\Model\Activity; +use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory as ConfigCollectionFactory; +use Magento\Config\Model\ResourceModel\Config\Data\Collection as ConfigCollection; use Magento\Framework\App\Config\Storage\WriterInterface; -use Magento\Framework\App\Config\ValueFactory; use Magento\Framework\App\RequestInterface; use Magento\Framework\DataObject; use MageOS\AdminActivityLog\Api\Activity\ModelInterface; +use MageOS\AdminActivityLog\Model\ResourceModel\ActivityLog\Collection; /** * Class ThemeConfig @@ -26,16 +28,9 @@ */ class ThemeConfig implements ModelInterface { - /** - * ThemeConfig constructor. - * @param DataObject $dataObject - * @param ValueFactory $valueFactory - * @param RequestInterface $request - * @param WriterInterface $configWriter - */ public function __construct( protected readonly DataObject $dataObject, - protected readonly ValueFactory $valueFactory, + protected readonly ConfigCollectionFactory $configCollectionFactory, protected readonly RequestInterface $request, protected readonly WriterInterface $configWriter ) { @@ -43,8 +38,6 @@ public function __construct( /** * Get config path of theme configuration - * @param DataObject $model - * @return string */ public function getPath(DataObject $model): string { @@ -61,30 +54,33 @@ public function getPath(DataObject $model): string /** * Get old activity data of theme configuration - * @param DataObject $model - * @return mixed + * @return array */ - public function getOldData(DataObject $model) + public function getOldData(DataObject $model): array { $path = $this->getPath($model); - $systemData = $this->valueFactory->create()->getCollection() - ->addFieldToFilter('path', ['like' => $path . '/%']); + /** @var ConfigCollection $systemDataCollection */ + $systemDataCollection = $this->configCollectionFactory->create(); + $systemDataCollection->addFieldToFilter('path', ['like' => $path . '/%']); $data = []; - foreach ($systemData->getData() as $config) { + foreach ($systemDataCollection->getData() as $config) { $path = str_replace('design_', '', str_replace('/', '_', $config['path'])); $data[$path] = $config['value']; } + return $data; } /** * Get edit activity data of theme configuration - * @param DataObject $model - * @param array $fieldArray - * @return mixed + * @param array $fieldArray + * @return array{}|array */ - public function getEditData(DataObject $model, $fieldArray) + public function getEditData(DataObject $model, array $fieldArray): array { $path = 'stores/scope_id/' . $model->getScopeId(); $oldData = $this->getOldData($model); @@ -97,34 +93,31 @@ public function getEditData(DataObject $model, $fieldArray) /** * Get revert activity data of theme configuration - * @param $logData - * @param $scopeId - * @param $scope - * @return bool */ - public function revertData($logData, $scopeId, $scope) + public function revertData(Collection $logData, int|string $scopeId, string $scope): bool { - if (!empty($logData)) { - foreach ($logData as $log) { - $this->configWriter->save( - $log->getFieldName(), - $log->getOldValue(), - $scope, - $scopeId - ); - } + foreach ($logData as $log) { + $this->configWriter->save( + $log->getFieldName(), + $log->getOldValue(), + $scope, + $scopeId + ); } return true; } /** * Set additional data - * @param $oldData - * @param $newData - * @param $fieldArray - * @return array + * @param array $oldData + * @param array $newData + * @param array $fieldArray + * @return array{}|array */ - public function collectAdditionalData($oldData, $newData, $fieldArray): array + public function collectAdditionalData(array $oldData, array $newData, array $fieldArray): array { $logData = []; foreach ($newData as $key => $value) { @@ -135,7 +128,7 @@ public function collectAdditionalData($oldData, $newData, $fieldArray): array $oldValue = !empty($oldData[$key]) ? $oldData[$key] : ''; if ($newValue != $oldValue) { - $key = 'design/' . preg_replace('/_/', '/', $key, 1); + $key = 'design/' . preg_replace('/_/', '/', (string) $key, 1); $logData[$key] = [ 'old_value' => $oldValue, 'new_value' => $newValue From 21cd2b8ab7f2fffffd32c402ea6b239933f2c19a Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 21:17:21 +0100 Subject: [PATCH 25/28] Refactor ModelInterface for improved type safety List of changes: - Added detailed return type annotations for `getEditData` to specify the exact structure of returned data, ensuring clarity and type safety. - Updated method parameter `$fieldArray` in `getEditData` to use the `array` type for consistency and better type enforcement. - Removed redundant PHPDoc comments for `getOldData` and `getEditData` methods, simplifying the interface while adhering to modern PHP standards. --- Api/Activity/ModelInterface.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Api/Activity/ModelInterface.php b/Api/Activity/ModelInterface.php index 06a3f29..1a319fc 100644 --- a/Api/Activity/ModelInterface.php +++ b/Api/Activity/ModelInterface.php @@ -23,17 +23,18 @@ interface ModelInterface { /** - * Get old data * @param DataObject $model * @return mixed */ public function getOldData(DataObject $model); /** - * Get edit data * @param DataObject $model - * @param $fieldArray - * @return mixed + * @param array $fieldArray + * @return array{}|array */ - public function getEditData(DataObject $model, $fieldArray); + public function getEditData(DataObject $model, array $fieldArray); } From f7cac1a26ae91464c5f903423deb6c18a9adb52d Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 21:18:32 +0100 Subject: [PATCH 26/28] CS-fix --- Helper/Browser.php | 50 ++++---- Model/Activity/ThemeConfig.php | 2 +- view/adminhtml/templates/activity/js.phtml | 138 ++++++++++----------- view/adminhtml/templates/log_listing.phtml | 108 ++++++++-------- 4 files changed, 149 insertions(+), 149 deletions(-) diff --git a/Helper/Browser.php b/Helper/Browser.php index db2d938..26b4928 100644 --- a/Helper/Browser.php +++ b/Helper/Browser.php @@ -1252,19 +1252,19 @@ protected function checkBrowserFirebird(): bool protected function checkBrowserNetscapeNavigator9Plus(): bool { if (stripos($this->agent, 'Firefox') !== false && preg_match( - '/Navigator\/([^ ]*)/i', - $this->agent, - $matches - )) { + '/Navigator\/([^ ]*)/i', + $this->agent, + $matches + )) { $this->setVersion($matches[1]); $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR); return true; } else { if (stripos($this->agent, 'Firefox') === false && preg_match( - '/Netscape6?\/([^ ]*)/i', - $this->agent, - $matches - )) { + '/Netscape6?\/([^ ]*)/i', + $this->agent, + $matches + )) { $this->setVersion($matches[1]); $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR); return true; @@ -1280,10 +1280,10 @@ protected function checkBrowserNetscapeNavigator9Plus(): bool protected function checkBrowserShiretoko(): bool { if (stripos($this->agent, 'Mozilla') !== false && preg_match( - '/Shiretoko\/([^ ]*)/i', - $this->agent, - $matches - )) { + '/Shiretoko\/([^ ]*)/i', + $this->agent, + $matches + )) { $this->setVersion($matches[1]); $this->setBrowser(self::BROWSER_SHIRETOKO); return true; @@ -1379,9 +1379,9 @@ protected function checkBrowserIceweasel(): bool protected function checkBrowserMozilla(): bool { if (stripos($this->agent, 'mozilla') !== false && preg_match( - '/rv:[0-9].[0-9][a-b]?/i', - $this->agent - ) && stripos($this->agent, 'netscape') === false) { + '/rv:[0-9].[0-9][a-b]?/i', + $this->agent + ) && stripos($this->agent, 'netscape') === false) { $aversion = explode(' ', stristr($this->agent, 'rv:')); preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->agent, $aversion); $this->setVersion(str_replace('rv:', '', $aversion[0])); @@ -1389,19 +1389,19 @@ protected function checkBrowserMozilla(): bool return true; } else { if (stripos($this->agent, 'mozilla') !== false && preg_match( - '/rv:[0-9]\.[0-9]/i', - $this->agent - ) && stripos($this->agent, 'netscape') === false) { + '/rv:[0-9]\.[0-9]/i', + $this->agent + ) && stripos($this->agent, 'netscape') === false) { $aversion = explode('', stristr($this->agent, 'rv:')); $this->setVersion(str_replace('rv:', '', $aversion[0])); $this->setBrowser(self::BROWSER_MOZILLA); return true; } else { if (stripos($this->agent, 'mozilla') !== false && preg_match( - '/mozilla\/([^ ]*)/i', - $this->agent, - $matches - ) && stripos($this->agent, 'netscape') === false) { + '/mozilla\/([^ ]*)/i', + $this->agent, + $matches + ) && stripos($this->agent, 'netscape') === false) { $this->setVersion($matches[1]); $this->setBrowser(self::BROWSER_MOZILLA); return true; @@ -1776,9 +1776,9 @@ protected function checkPlatform() } elseif (stripos($this->agent, 'Silk') !== false) { $this->platform = self::PLATFORM_FIRE_OS; } elseif (stripos($this->agent, 'linux') !== false && stripos( - $this->agent, - 'SMART-TV' - ) !== false) { + $this->agent, + 'SMART-TV' + ) !== false) { $this->platform = self::PLATFORM_LINUX . '/' . self::PLATFORM_SMART_TV; } elseif (stripos($this->agent, 'linux') !== false) { $this->platform = self::PLATFORM_LINUX; diff --git a/Model/Activity/ThemeConfig.php b/Model/Activity/ThemeConfig.php index a59dfae..321c27b 100644 --- a/Model/Activity/ThemeConfig.php +++ b/Model/Activity/ThemeConfig.php @@ -14,8 +14,8 @@ namespace MageOS\AdminActivityLog\Model\Activity; -use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory as ConfigCollectionFactory; use Magento\Config\Model\ResourceModel\Config\Data\Collection as ConfigCollection; +use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory as ConfigCollectionFactory; use Magento\Framework\App\Config\Storage\WriterInterface; use Magento\Framework\App\RequestInterface; use Magento\Framework\DataObject; diff --git a/view/adminhtml/templates/activity/js.phtml b/view/adminhtml/templates/activity/js.phtml index 413d32e..d420aa6 100644 --- a/view/adminhtml/templates/activity/js.phtml +++ b/view/adminhtml/templates/activity/js.phtml @@ -1,26 +1,26 @@ -escapeUrl($block->getRevertUrl())}', data: { id: this.activityId, - form_key: '{$escaper->escapeJs($block->getFormKey())}' - }, - dataType: 'json', - showLoader: true, - success: (data) => { - if (!data.error) { - this.closeDialogWindow(dialogWindow); - window.location.reload(); - } else { - this.error(data.message); - } - } - }) - }, - closeDialogWindow: function (dialogWindow) { - jQuery('body').trigger('processStop'); - dialogWindow.closeModal(); - Window.overlayShowEffectOptions = this.overlayShowEffectOptions; - Window.overlayHideEffectOptions = this.overlayHideEffectOptions; - }, - error: function (message) { - jQuery('body').notification('clear') - .notification('add', { - error: true, - message: jQuery.mage.__(message), - insertMethod: function (message) { - let wrapper = jQuery('
').html(message); - jQuery('.page-main-actions').after(wrapper); - } - }); - }, - autoResize: function () { - jQuery.each(jQuery('textarea.value-container'), function () { - let offset = this.offsetHeight - this.clientHeight; - const resizeTextarea = function (el) { - jQuery(el).css('height', 'auto').css('height', el.scrollHeight + offset); - }; - jQuery(this).unbind().on('click', function () { - resizeTextarea(this); - }).trigger('click'); - }); - } - }; - }); -JS; -echo $secureRenderer->renderTag('script', [], $script, false); + form_key: '{$escaper->escapeJs($block->getFormKey())}' + }, + dataType: 'json', + showLoader: true, + success: (data) => { + if (!data.error) { + this.closeDialogWindow(dialogWindow); + window.location.reload(); + } else { + this.error(data.message); + } + } + }) + }, + closeDialogWindow: function (dialogWindow) { + jQuery('body').trigger('processStop'); + dialogWindow.closeModal(); + Window.overlayShowEffectOptions = this.overlayShowEffectOptions; + Window.overlayHideEffectOptions = this.overlayHideEffectOptions; + }, + error: function (message) { + jQuery('body').notification('clear') + .notification('add', { + error: true, + message: jQuery.mage.__(message), + insertMethod: function (message) { + let wrapper = jQuery('
').html(message); + jQuery('.page-main-actions').after(wrapper); + } + }); + }, + autoResize: function () { + jQuery.each(jQuery('textarea.value-container'), function () { + let offset = this.offsetHeight - this.clientHeight; + const resizeTextarea = function (el) { + jQuery(el).css('height', 'auto').css('height', el.scrollHeight + offset); + }; + jQuery(this).unbind().on('click', function () { + resizeTextarea(this); + }).trigger('click'); + }); + } + }; + }); +JS; +echo $secureRenderer->renderTag('script', [], $script, false); diff --git a/view/adminhtml/templates/log_listing.phtml b/view/adminhtml/templates/log_listing.phtml index b8a49c2..6708c06 100644 --- a/view/adminhtml/templates/log_listing.phtml +++ b/view/adminhtml/templates/log_listing.phtml @@ -1,28 +1,28 @@ -getLogListing(); -$adminDetails = $block->getAdminDetails(); -?> +getLogListing(); +$adminDetails = $block->getAdminDetails(); +?> - + @@ -52,10 +52,10 @@ $adminDetails = $block->getAdminDetails(); - + @@ -68,8 +68,8 @@ $adminDetails = $block->getAdminDetails(); - + - +
@@ -30,14 +30,14 @@ $adminDetails = $block->getAdminDetails();
Admin :escapeHtml($adminDetails['username']); - if (!empty($adminDetails['name'])) { - echo $escaper->escapeHtml(" (" . ucwords(strtolower($adminDetails['name'])) . ") "); - } - } - ?>escapeHtml($adminDetails['username']); + if (!empty($adminDetails['name'])) { + echo $escaper->escapeHtml(" (" . ucwords(strtolower($adminDetails['name'])) . ") "); + } + } +?>
Module
User Agent :escapeHtml( - $adminDetails['browser'], - ['strong', 'br'] - ) ?>escapeHtml( + $adminDetails['browser'], + ['strong', 'br'] + ) ?>
Date
@@ -78,30 +78,30 @@ $adminDetails = $block->getAdminDetails(); - + - +
Old Value New Value
- escapeHtml(ucfirst(str_replace('_', ' ', $item["field_name"]))) ?> + escapeHtml(ucfirst(str_replace('_', ' ', $item["field_name"]))) ?> - + - +
From 6150f3291881ada8963b9b965531550807443499 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 21:19:49 +0100 Subject: [PATCH 27/28] Add explicit return type to initActivity method in AdminActivityLog List of changes: - Updated the `initActivity` method in `Processor` class to include a precise return type `false|Activity`. - Improved type safety and alignment with modern PHP standards. --- Model/Processor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/Processor.php b/Model/Processor.php index 30c00c0..3b26eb2 100644 --- a/Model/Processor.php +++ b/Model/Processor.php @@ -340,7 +340,7 @@ public function initLog(): Activity * @param $model * @return bool|Activity */ - public function initActivity($model) + public function initActivity($model): false|Activity { if (!$this->authSession->isLoggedIn()) { return false; From a38edc9b16280919931863263ed77405779eb665 Mon Sep 17 00:00:00 2001 From: Luca Fuser Date: Sun, 14 Dec 2025 21:19:59 +0100 Subject: [PATCH 28/28] Add nullable return types to version methods in Browser helper List of changes: - Updated the `getVersion` method to include a nullable `string` return type for enhanced type safety and clarity. - Modified the `getAolVersion` method to specify a nullable `string` return type, improving adherence to modern PHP standards. --- Helper/Browser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Helper/Browser.php b/Helper/Browser.php index 26b4928..ea6a3cf 100644 --- a/Helper/Browser.php +++ b/Helper/Browser.php @@ -243,7 +243,7 @@ public function setPlatform($platform): void * The version of the browser. * @return string Version of the browser (will only contain alpha-numeric characters and a period) */ - public function getVersion() + public function getVersion(): ?string { return $this->version; } @@ -262,7 +262,7 @@ public function setVersion($version): void * The version of AOL. * @return string Version of AOL (will only contain alpha-numeric characters and a period) */ - public function getAolVersion() + public function getAolVersion(): ?string { return $this->aol_version; }