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); } diff --git a/Block/Adminhtml/ActivityLogListing.php b/Block/Adminhtml/ActivityLogListing.php index 1463203..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,9 +60,9 @@ public function getLogListing() /** * Get admin activity details - * @return array + * @return array */ - public function getAdminDetails() + public function getAdminDetails(): array { $id = $this->getRequest()->getParam('id'); $activity = $this->activityRepository->getActivityById($id); @@ -69,14 +71,14 @@ public function getAdminDetails() $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 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 { 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..9c25ce2 100644 --- a/Controller/Adminhtml/Activity/Revert.php +++ b/Controller/Adminhtml/Activity/Revert.php @@ -26,29 +26,22 @@ */ 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() { $activityId = $this->getRequest()->getParam('id'); - $result = $this->processor->revertActivity($activityId); + $result = $this->processor->revertActivity((int)$activityId); $json = $this->resultJsonFactory->create(); $json->setData($result); 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 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, 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; diff --git a/Helper/Browser.php b/Helper/Browser.php index 5245024..ea6a3cf 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; } @@ -252,7 +243,7 @@ public function setPlatform($platform) * 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 +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); } @@ -271,7 +262,7 @@ public function setVersion($version) * 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; } @@ -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,22 +1249,22 @@ 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', - $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; @@ -1286,13 +1277,13 @@ 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', - $this->agent, - $matches - )) { + '/Shiretoko\/([^ ]*)/i', + $this->agent, + $matches + )) { $this->setVersion($matches[1]); $this->setBrowser(self::BROWSER_SHIRETOKO); return true; @@ -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,12 +1376,12 @@ 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', - $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])); @@ -1398,19 +1389,19 @@ protected function checkBrowserMozilla() 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; @@ -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 ')); @@ -1785,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/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); } } 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)) { 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(); diff --git a/Model/Activity/SystemConfig.php b/Model/Activity/SystemConfig.php index d05d64d..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( @@ -72,11 +62,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 +79,12 @@ public function getOldData(DataObject $model) * Get edit activity data of system config module * @param DataObject $model * @param array $fieldArray - * @return mixed + * @return array{}|array */ - public function getEditData(DataObject $model, $fieldArray) + public function getEditData(DataObject $model, $fieldArray): array { $logData = []; @@ -132,7 +125,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 +146,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/Activity/ThemeConfig.php b/Model/Activity/ThemeConfig.php index 8b2b19b..321c27b 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\Collection as ConfigCollection; +use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory as ConfigCollectionFactory; 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 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( diff --git a/Model/Processor.php b/Model/Processor.php index 90d9884..3b26eb2 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(); @@ -350,7 +340,7 @@ public function initLog() * @param $model * @return bool|Activity */ - public function initActivity($model) + public function initActivity($model): false|Activity { if (!$this->authSession->isLoggedIn()) { return false; @@ -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 { diff --git a/Model/ResourceModel/Activity.php b/Model/ResourceModel/Activity.php index bb60a1e..42962a4 100644 --- a/Model/ResourceModel/Activity.php +++ b/Model/ResourceModel/Activity.php @@ -22,11 +22,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/Activity/Collection.php b/Model/ResourceModel/Activity/Collection.php index 914e215..d9b9843 100644 --- a/Model/ResourceModel/Activity/Collection.php +++ b/Model/ResourceModel/Activity/Collection.php @@ -23,11 +23,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.php b/Model/ResourceModel/ActivityLog.php index edc7af4..7829f42 100644 --- a/Model/ResourceModel/ActivityLog.php +++ b/Model/ResourceModel/ActivityLog.php @@ -22,11 +22,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/ActivityLog/Collection.php b/Model/ResourceModel/ActivityLog/Collection.php index bdd037c..db37571 100644 --- a/Model/ResourceModel/ActivityLog/Collection.php +++ b/Model/ResourceModel/ActivityLog/Collection.php @@ -23,11 +23,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.php b/Model/ResourceModel/ActivityLogDetail.php index 72d4d94..7e28d01 100644 --- a/Model/ResourceModel/ActivityLogDetail.php +++ b/Model/ResourceModel/ActivityLogDetail.php @@ -22,11 +22,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/ActivityLogDetail/Collection.php b/Model/ResourceModel/ActivityLogDetail/Collection.php index 134da04..f1ba5f4 100644 --- a/Model/ResourceModel/ActivityLogDetail/Collection.php +++ b/Model/ResourceModel/ActivityLogDetail/Collection.php @@ -23,11 +23,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.php b/Model/ResourceModel/Login.php index 1bc13f8..5eb84e0 100644 --- a/Model/ResourceModel/Login.php +++ b/Model/ResourceModel/Login.php @@ -22,11 +22,7 @@ */ class Login extends AbstractDb { - /** - * Initialize resource model - * @return void - */ - public function _construct() + 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 28eec54..4ee18a7 100644 --- a/Model/ResourceModel/Login/Collection.php +++ b/Model/ResourceModel/Login/Collection.php @@ -23,11 +23,7 @@ */ class Collection extends AbstractCollection { - /** - * Define resource model - * @return void - */ - public function _construct() + public function _construct(): void { $this->_init( \MageOS\AdminActivityLog\Model\Login::class, 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 efe8e93..ed45e18 100644 --- a/Observer/SaveAfter.php +++ b/Observer/SaveAfter.php @@ -26,34 +26,24 @@ */ 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'; - /** - * SaveAfter 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 ) { } - /** - * 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..16d3e4b 100644 --- a/Observer/SaveBefore.php +++ b/Observer/SaveBefore.php @@ -27,34 +27,22 @@ */ 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, - protected readonly ActivityRepositoryInterface $activityRepository, - protected readonly Benchmark $benchmark + private readonly Helper $helper, + private readonly Processor $processor, + private readonly ActivityRepositoryInterface $activityRepository, + private readonly Benchmark $benchmark ) { } - /** - * 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__); } } diff --git a/Plugin/App/Action.php b/Plugin/App/ActionPlugin.php similarity index 59% rename from Plugin/App/Action.php rename to Plugin/App/ActionPlugin.php index b5297c7..263773b 100644 --- a/Plugin/App/Action.php +++ b/Plugin/App/ActionPlugin.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; @@ -22,33 +22,26 @@ * Class Action * @package MageOS\AdminActivityLog\Plugin\App */ -class Action +class ActionPlugin { - /** - * 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__); } } diff --git a/Plugin/Auth.php b/Plugin/AuthPlugin.php similarity index 65% rename from Plugin/Auth.php rename to Plugin/AuthPlugin.php index 63bd5b2..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,36 +23,29 @@ * Class Auth * @package MageOS\AdminActivityLog\Plugin */ -class Auth +class AuthPlugin { - /** - * 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(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; } } diff --git a/Plugin/User/Delete.php b/Plugin/User/DeletePlugin.php similarity index 65% rename from Plugin/User/Delete.php rename to Plugin/User/DeletePlugin.php index d27d95f..8cd0f77 100644 --- a/Plugin/User/Delete.php +++ b/Plugin/User/DeletePlugin.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; @@ -21,30 +22,21 @@ * Class Delete * @package MageOS\AdminActivityLog\Plugin\User */ -class Delete +class DeletePlugin { - /** - * 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; 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 d9a50e5..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,10 +40,10 @@ public function __construct( } /** - * Prepare Data Source - * @param array $dataSource - * @return array + * @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..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,10 +51,10 @@ 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 { if (isset($dataSource['data']['items'])) { diff --git a/Ui/Component/Listing/Column/ItemColumn.php b/Ui/Component/Listing/Column/ItemColumn.php index 968921d..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,8 +110,8 @@ public function getLinkAttributes(): string * @param string $valueSeparator * @param string $fieldSeparator * @param string $quote - * @return string */ + #[\Override] public function serialize($keys = [], $valueSeparator = '=', $fieldSeparator = ' ', $quote = '"'): string { $data = []; @@ -132,8 +123,6 @@ public function serialize($keys = [], $valueSeparator = '=', $fieldSeparator = ' /** * Convert action to url - * @param string $url - * @return string */ public function prepareUrl(string $url): string { @@ -155,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 { @@ -168,9 +156,10 @@ 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 { if (isset($dataSource['data']['items'])) { diff --git a/Ui/Component/Listing/Column/RevertStatusColumn.php b/Ui/Component/Listing/Column/RevertStatusColumn.php index 9ce69bd..bef0767 100644 --- a/Ui/Component/Listing/Column/RevertStatusColumn.php +++ b/Ui/Component/Listing/Column/RevertStatusColumn.php @@ -24,9 +24,10 @@ class RevertStatusColumn extends Column { /** * Prepare Data Source - * @param array $dataSource - * @return array + * @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..0339830 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 = [] ) { @@ -37,9 +37,10 @@ public function __construct( /** * Prepare Data Source - * @param array $dataSource - * @return array + * @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..cab649b 100644 --- a/Ui/Component/Listing/Column/StoreColumn.php +++ b/Ui/Component/Listing/Column/StoreColumn.php @@ -22,13 +22,13 @@ */ 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 { $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..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,9 +52,10 @@ 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 { if (isset($dataSource['data']['items'])) { diff --git a/Ui/Component/Listing/Column/ViewAction.php b/Ui/Component/Listing/Column/ViewAction.php index 91c2384..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,10 +50,10 @@ public function getViewUrl(): string } /** - * Prepare Data Source - * @param array $dataSource - * @return array + * @param array $dataSource + * @return array */ + #[\Override] public function prepareDataSource(array $dataSource): array { if (isset($dataSource['data']['items'])) { 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 @@ --> - + - + - + 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"]))) ?> - + - +