Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Block/Adminhtml/System/Config/DeploymentConfigInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function render(AbstractElement $element)
/**
* Get static version.
*
* @return string
* @return ?string
*/
public function getVersion()
{
Expand Down
4 changes: 2 additions & 2 deletions Block/SentryScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function getJsSdkVersion()
/**
* Get the current version of the Magento application.
*
* @return int|string
* @return ?string
*/
public function getVersion()
{
Expand Down Expand Up @@ -231,6 +231,6 @@ public function getTracingSampleRate(): float
*/
public function getIgnoreJsErrors(): string
{
return $this->json->serialize($this->dataHelper->getIgnoreJsErrors());
return (string) $this->json->serialize($this->dataHelper->getIgnoreJsErrors() ?? '[]');
}
}
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Test/Sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function execute()
$response = $this->getResponse();

return $response->representJson(
$this->jsonSerializer->serialize($result)
(string) $this->jsonSerializer->serialize($result)
);
}
}
10 changes: 5 additions & 5 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,15 @@ public function collectModuleConfig(): array
try {
$this->config[$storeId]['enabled'] = $this->scopeConfig->getValue('sentry/environment/enabled', ScopeInterface::SCOPE_STORE)
?? $this->deploymentConfig->get('sentry') !== null;
} catch (TableNotFoundException|FileSystemException|RuntimeException|DomainException|Zend_Db_Adapter_Exception $e) {
} catch (TableNotFoundException|FileSystemException|RuntimeException|DomainException|Zend_Db_Adapter_Exception) {
$this->config[$storeId]['enabled'] = $this->deploymentConfig->get('sentry') !== null;
}

foreach ($this->configKeys as $key => $config) {
try {
$value = $this->scopeConfig->getValue('sentry/environment/'.$key, ScopeInterface::SCOPE_STORE)
?? $this->deploymentConfig->get('sentry/'.$key);
} catch (TableNotFoundException|FileSystemException|RuntimeException|DomainException|Zend_Db_Adapter_Exception $e) {
} catch (TableNotFoundException|FileSystemException|RuntimeException|DomainException|Zend_Db_Adapter_Exception) {
$value = $this->deploymentConfig->get('sentry/'.$key);
}

Expand Down Expand Up @@ -403,7 +403,7 @@ public function isActiveWithReason(): array
*/
public function isProductionMode(): bool
{
return $this->appState->emulateAreaCode(Area::AREA_GLOBAL, [$this, 'getAppState']) === 'production';
return $this->appState->emulateAreaCode(Area::AREA_GLOBAL, $this->getAppState(...)) === 'production';
}

/**
Expand Down Expand Up @@ -445,7 +445,7 @@ public function getStore(): ?\Magento\Store\Api\Data\StoreInterface
{
try {
return $this->storeManager->getStore();
} catch (DomainException|Zend_Db_Adapter_Exception|NoSuchEntityException $e) {
} catch (DomainException|Zend_Db_Adapter_Exception|NoSuchEntityException) {
// If the store is not available, return null
return null;
}
Expand Down Expand Up @@ -665,7 +665,7 @@ public function shouldCaptureException(Throwable $ex): bool
return false;
}

if (in_array(get_class($ex), $this->getIgnoreExceptions())) {
if (in_array($ex::class, $this->getIgnoreExceptions())) {
return false;
}

Expand Down
20 changes: 8 additions & 12 deletions Helper/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
class Version extends AbstractHelper
{
/**
* @var string
* @var ?string
*/
private $cachedValue;

/**
* @var LoggerInterface
* @var ?LoggerInterface
*/
private $logger;

/**
* @var DeploymentConfig
* @var ?DeploymentConfig
*/
private $deploymentConfig;

Expand All @@ -45,8 +45,6 @@ public function __construct(

/**
* Retrieve deployment version of static files.
*
* @return string|null
*/
public function getValue(): ?string
{
Expand All @@ -73,15 +71,15 @@ protected function readValue($appMode): ?string
$result = $this->versionStorage->load();
if (!$result) {
if ($appMode == \Magento\Framework\App\State::MODE_PRODUCTION
&& !$this->deploymentConfig->getConfigData(
&& !$this->deploymentConfig?->getConfigData(
ConfigOptionsListConstants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION
)
) {
$this->getLogger()->critical('Can not load static content version.');
$this->getLogger()?->critical('Can not load static content version.');

return null;
}
$result = $this->generateVersion();
$result = (string) $this->generateVersion();
$this->versionStorage->save((string) $result);
}

Expand All @@ -90,18 +88,16 @@ protected function readValue($appMode): ?string

/**
* Generate version of static content.
*
* @return int
*/
private function generateVersion()
private function generateVersion(): int
{
return time();
}

/**
* Get logger.
*
* @return LoggerInterface
* @return ?LoggerInterface
*/
private function getLogger()
{
Expand Down
4 changes: 1 addition & 3 deletions Model/ReleaseIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ public function __construct(

/**
* Get release ID from magento internal release number.
*
* @return string
*/
public function getReleaseId()
public function getReleaseId(): ?string
{
return $this->version->getValue();
}
Expand Down
2 changes: 1 addition & 1 deletion Model/SentryCron.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function sendScheduleStatus(Schedule $schedule): void
!array_reduce(
$this->data->getTrackCrons(),
fn ($trackCron, $expression) => $trackCron || (
preg_match('/^\/.*\/[imsu]*$/', $expression) ?
preg_match('/^\/.*\/[imsu]*$/', (string) $expression) ?
preg_match($expression, $schedule->getJobCode()) :
$schedule->getJobCode() === $expression
),
Expand Down
17 changes: 11 additions & 6 deletions Model/SentryInteraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function canGetUserContext(): bool
try {
// @phpcs:ignore Generic.PHP.NoSilencedErrors
return in_array(@$this->appState->getAreaCode(), [Area::AREA_ADMINHTML, Area::AREA_FRONTEND, Area::AREA_WEBAPI_REST, Area::AREA_WEBAPI_SOAP, Area::AREA_GRAPHQL]);
} catch (LocalizedException $ex) {
} catch (LocalizedException) {
return false;
}
}
Expand Down Expand Up @@ -106,7 +106,10 @@ public function getUserContext(): ?UserContextInterface
return $this->userContext;
}

return $this->userContext = $this->getObjectIfInitialized(UserContextInterface::class);
/** @var ?UserContextInterface $userContext */
$userContext = $this->getObjectIfInitialized(UserContextInterface::class);

return $this->userContext = $userContext;
}

/**
Expand All @@ -117,7 +120,7 @@ public function canGetUserData(): bool
try {
// @phpcs:ignore Generic.PHP.NoSilencedErrors
return in_array(@$this->appState->getAreaCode(), [Area::AREA_ADMINHTML, Area::AREA_FRONTEND]);
} catch (LocalizedException $ex) {
} catch (LocalizedException) {
return false;
}
}
Expand All @@ -132,6 +135,7 @@ private function getSessionUserData(): array
}

if ($this->appState->getAreaCode() === Area::AREA_ADMINHTML) {
/** @var ?AdminSession $adminSession */
$adminSession = $this->getObjectIfInitialized(AdminSession::class);
if ($adminSession === null) {
return [];
Expand All @@ -147,6 +151,7 @@ private function getSessionUserData(): array
}

if ($this->appState->getAreaCode() === Area::AREA_FRONTEND) {
/** @var ?CustomerSession $customerSession */
$customerSession = $this->getObjectIfInitialized(CustomerSession::class);
if ($customerSession === null) {
return [];
Expand Down Expand Up @@ -188,9 +193,9 @@ public function addUserContext(): void
}

if ($this->canGetUserContext()) {
$userId = $this->getUserContext()->getUserId();
$userId = $this->getUserContext()?->getUserId();
if ($userId) {
$userType = $this->getUserContext()->getUserType();
$userType = $this->getUserContext()?->getUserType();
}
}

Expand All @@ -217,7 +222,7 @@ public function addUserContext(): void
},
]);
});
} catch (\Throwable $e) {
} catch (\Throwable) {
// User context could not be found or added.
\Magento\Framework\Profiler::stop('SENTRY::add_user_context');

Expand Down
4 changes: 2 additions & 2 deletions Model/SentryLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function (SentryScope $scope) use ($context, $customTags): void {
if (true === $this->canGetCustomerData()) {
$this->customerSession->setSentryEventId($lastEventId);
}
} catch (SessionException $e) {
} catch (SessionException) {
return;
}
}
Expand Down Expand Up @@ -132,7 +132,7 @@ private function canGetCustomerData()
{
try {
return $this->appState->getAreaCode() === Area::AREA_FRONTEND;
} catch (LocalizedException $ex) {
} catch (LocalizedException) {
return false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions Model/SentryPerformance.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public function startHttpTransaction(Http $app): void
$requestStartTime = $this->request->getServer('REQUEST_TIME_FLOAT', microtime(true));

$context = TransactionContext::fromHeaders(
$this->request->getHeader('sentry-trace') ?: '',
$this->request->getHeader('baggage') ?: ''
(string) ($this->request->getHeader('sentry-trace') ?: ''),
(string) ($this->request->getHeader('baggage') ?: '')
);

$requestPath = '/'.ltrim($this->request->getRequestUri(), '/');
Expand Down Expand Up @@ -175,7 +175,7 @@ public function finishTransaction(ResponseInterface|int|null $statusCode = null)
try {
$state = $this->objectManager->get(State::class);
$areaCode = $state->getAreaCode();
} catch (LocalizedException $e) {
} catch (LocalizedException) {
// Default area is global.
$areaCode = Area::AREA_GLOBAL;
}
Expand Down
2 changes: 1 addition & 1 deletion Plugin/CspModeConfigManagerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function afterGetConfigured(ModeConfigManagerInterface $subject, ModeConf

$uriParsed = UriFactory::factory($dsn);

$dsnPaths = explode('/', $uriParsed->getPath()); // the last one is the project-id
$dsnPaths = explode('/', (string) $uriParsed->getPath()); // the last one is the project-id
$reportUri = sprintf('https://%s/api/%s/security', $uriParsed->getHost(), $dsnPaths[count($dsnPaths) - 1]);

$params = [
Expand Down
2 changes: 1 addition & 1 deletion Plugin/GlobalExceptionCatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function prepareConfig(): DataObject
$disabledDefaultIntegrations = $this->sentryHelper->getDisabledDefaultIntegrations();
$config->setData('integrations', static fn (array $integrations) => array_filter(
$integrations,
static fn (IntegrationInterface $integration) => !in_array(get_class($integration), $disabledDefaultIntegrations)
static fn (IntegrationInterface $integration) => !in_array($integration::class, $disabledDefaultIntegrations)
));

$config->setErrorTypes($this->sentryHelper->getErrorTypes());
Expand Down
2 changes: 1 addition & 1 deletion Plugin/Profiling/ExchangePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function beforeEnqueue(ExchangeInterface|BulkExchangeInterface $subject,
$body = json_decode($envelope->getBody(), true);
$envelope = $this->setBody(
$envelope,
json_encode([
(string) json_encode([
...$body,
'sentry_trace' => \Sentry\getTraceparent(),
'sentry_baggage' => \Sentry\getBaggage(),
Expand Down
2 changes: 1 addition & 1 deletion Plugin/Profiling/QueuePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function afterDequeue(QueueInterface $queue, ?EnvelopeInterface $envelope
unset($body['sentry_trace']);
unset($body['sentry_baggage']);

return $this->setBody($envelope, json_encode($body));
return $this->setBody($envelope, (string) json_encode($body));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Plugin/Profiling/TemplatePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function aroundFetchView(Template $subject, callable $callable, $fileName
->setTags($tags)
->setData([
'block_name' => $subject->getNameInLayout(),
'block_class' => get_class($subject),
'block_class' => $subject::class,
'module' => $subject->getModuleName(),
'template' => $fileName,
])
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"type": "magento2-module",
"license": "MIT",
"require": {
"php": ">=8.0",
"php": ">=8.1",
"sentry/sentry": "^4.13",
"monolog/monolog": ">=2.7.0|^3.0",
"magento/framework": ">=103.0.7",
Expand Down Expand Up @@ -72,13 +72,15 @@
"analyse": "vendor/bin/phpstan analyse --memory-limit='1G'",
"phpcs": "vendor/bin/phpcs --colors --standard=vendor/magento/magento-coding-standard/Magento2 -s --exclude=Generic.Files.LineLength --report=full,summary,gitblame --extensions=php,phtml --ignore=./vendor ./",
"phpcbf": "vendor/bin/phpcbf --colors --standard=vendor/magento/magento-coding-standard/Magento2 --exclude=Generic.Files.LineLength --extensions=php,phtml --ignore=./vendor ./ || exit 0",
"rector": "vendor/bin/rector",
"codestyle": [
"@phpcbf",
"@phpcs"
]
},
"require-dev": {
"bitexpert/phpstan-magento": "^0.32.0",
"magento/magento-coding-standard": "^34"
"magento/magento-coding-standard": "^34",
"rector/rector": ">=1.2.5"
}
}
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ parameters:
- vendor
- Test/*
- Logger/Handler/Sentry.php
level: 6
level: 8
ignoreErrors:
-
identifier: missingType.iterableValue
Expand Down
Loading