Skip to content

Commit

Permalink
Set minimum PHP version to 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
guvra committed Sep 5, 2023
1 parent 18f7507 commit 25a1f30
Show file tree
Hide file tree
Showing 37 changed files with 106 additions and 278 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
php-version:
- '7.4'
- '8.1'

steps:
- name: 'Checkout'
Expand Down
9 changes: 2 additions & 7 deletions Block/Toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,18 @@
*/
class Toolbar extends Template
{
protected DataHelper $dataHelper;
protected SummaryFactory $blockSummaryFactory;

/**
* @var Zone\AbstractZone[]
*/
protected array $zones = [];

public function __construct(
Context $context,
DataHelper $dataHelper,
SummaryFactory $blockSummaryFactory,
protected DataHelper $dataHelper,
protected SummaryFactory $blockSummaryFactory,
array $data = []
) {
parent::__construct($context, $data);
$this->dataHelper = $dataHelper;
$this->blockSummaryFactory = $blockSummaryFactory;

$this->setData('cache_lifetime', 0);
$this->setTemplate('Smile_DebugToolbar::toolbar.phtml');
Expand Down
27 changes: 7 additions & 20 deletions Block/Zone/AbstractZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,17 @@
*/
abstract class AbstractZone extends Template
{
protected DataHelper $dataHelper;
protected FormatterFactory $formatterFactory;
protected Summary $summaryBlock;
protected bool $warning = false;
protected array $tablesToDisplay = [];

public function __construct(
Context $context,
DataHelper $dataHelper,
FormatterFactory $formatterFactory,
protected DataHelper $dataHelper,
protected FormatterFactory $formatterFactory,
array $data = []
) {
parent::__construct($context, $data);
$this->dataHelper = $dataHelper;
$this->formatterFactory = $formatterFactory;

$this->setData('cache_lifetime', 0);
$this->setTemplate('Smile_DebugToolbar::zone/' . $this->getCode() . '.phtml');
}
Expand Down Expand Up @@ -66,10 +61,8 @@ public function setSummaryBlock(Summary $block): self

/**
* Add a value to the summary.
*
* @param mixed $value
*/
public function addToSummary(string $sectionName, string $key, $value): void
public function addToSummary(string $sectionName, string $key, mixed $value): void
{
$this->summaryBlock->addToSummary($sectionName, $key, $value);
}
Expand Down Expand Up @@ -109,7 +102,7 @@ public function displaySections(array $sections = []): string
}

foreach ($sectionValues as $name => $value) {
$html .= $this->displaySectionValue($name, $value);
$html .= $this->displaySectionValue((string) $name, $value);
}
$html .= '</tbody>';

Expand Down Expand Up @@ -148,10 +141,9 @@ public function displaySectionsGrouped(array $sections = []): string
/**
* Get the good css class and the cleaned value.
*
* @param mixed $value
* @return string[]
*/
protected function getClassAndValue($value): array
protected function getClassAndValue(mixed $value): array
{
if (
!is_array($value)
Expand All @@ -166,11 +158,8 @@ protected function getClassAndValue($value): array

/**
* Display a row section.
*
* @param string|int $name
* @param mixed $value
*/
protected function displaySectionValue($name, $value): string
protected function displaySectionValue(string $name, mixed $value): string
{
[$class, $value] = $this->getClassAndValue($value);

Expand Down Expand Up @@ -237,10 +226,8 @@ public function getTimer(string $code): float

/**
* Format a value, using rules, and type.
*
* @param string|float $value
*/
public function formatValue($value, array $rules = [], ?string $type = null): array
public function formatValue(mixed $value, array $rules = [], ?string $type = null): array
{
$formatter = $this->formatterFactory->create(
[
Expand Down
13 changes: 3 additions & 10 deletions Block/Zone/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,15 @@
*/
class Cache extends AbstractZone
{
protected DeploymentConfig $deployConfig;
protected CacheHelper $cacheHelper;

public function __construct(
Context $context,
DataHelper $dataHelper,
FormatterFactory $formatterFactory,
DeploymentConfig $deployConfig,
CacheHelper $cacheHelper,
protected DeploymentConfig $deployConfig,
protected CacheHelper $cacheHelper,
array $data = []
) {
parent::__construct($context, $dataHelper, $formatterFactory, $data);
$this->deployConfig = $deployConfig;
$this->cacheHelper = $cacheHelper;
}

/**
Expand Down Expand Up @@ -62,10 +57,8 @@ public function getCacheMode(): string

/**
* Get the cache info.
*
* @return string|array
*/
public function getCacheInfo()
public function getCacheInfo(): array|string
{
$config = $this->deployConfig->get('cache');
if (!$config || !is_array($config)) {
Expand Down
17 changes: 4 additions & 13 deletions Block/Zone/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,16 @@
*/
class Generic extends AbstractZone
{
protected ProductMetadataInterface $productMetadata;
protected AppState $appState;
protected DeploymentConfig $deployConfig;

public function __construct(
Context $context,
DataHelper $dataHelper,
FormatterFactory $formatterFactory,
ProductMetadataInterface $productMetadata,
AppState $appState,
DeploymentConfig $deployConfig,
protected ProductMetadataInterface $productMetadata,
protected AppState $appState,
protected DeploymentConfig $deployConfig,
array $data = []
) {
parent::__construct($context, $dataHelper, $formatterFactory, $data);
$this->productMetadata = $productMetadata;
$this->appState = $appState;
$this->deployConfig = $deployConfig;
}

/**
Expand Down Expand Up @@ -111,10 +104,8 @@ public function getSessionMode(): string

/**
* Get the session info.
*
* @return array|string
*/
public function getSessionInfo()
public function getSessionInfo(): array|string
{
$config = $this->deployConfig->get('session');
if (!$config || !is_array($config)) {
Expand Down
5 changes: 1 addition & 4 deletions Block/Zone/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
*/
class Layout extends AbstractZone
{
protected LayoutHelper $layoutHelper;

public function __construct(
Context $context,
DataHelper $dataHelper,
FormatterFactory $formatterFactory,
LayoutHelper $layoutHelper,
protected LayoutHelper $layoutHelper,
array $data = []
) {
parent::__construct($context, $dataHelper, $formatterFactory, $data);
$this->layoutHelper = $layoutHelper;
}

/**
Expand Down
9 changes: 2 additions & 7 deletions Block/Zone/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,15 @@
*/
class Mysql extends AbstractZone
{
protected ResourceModel $resourceModel;
protected DirectoryList $directoryList;

public function __construct(
Context $context,
DataHelper $dataHelper,
FormatterFactory $formatterFactory,
ResourceModel $resourceModel,
DirectoryList $directoryList,
protected ResourceModel $resourceModel,
protected DirectoryList $directoryList,
array $data = []
) {
parent::__construct($context, $dataHelper, $formatterFactory, $data);
$this->resourceModel = $resourceModel;
$this->directoryList = $directoryList;
}

/**
Expand Down
5 changes: 1 addition & 4 deletions Block/Zone/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
*/
class Observer extends AbstractZone
{
protected ObserverHelper $observerHelper;

public function __construct(
Context $context,
DataHelper $dataHelper,
FormatterFactory $formatterFactory,
ObserverHelper $observerHelper,
protected ObserverHelper $observerHelper,
array $data = []
) {
parent::__construct($context, $dataHelper, $formatterFactory, $data);
$this->observerHelper = $observerHelper;
}

/**
Expand Down
5 changes: 1 addition & 4 deletions Block/Zone/Preference.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
*/
class Preference extends AbstractZone
{
protected PreferenceHelper $preferenceHelper;

public function __construct(
Context $context,
DataHelper $dataHelper,
FormatterFactory $formatterFactory,
PreferenceHelper $preferenceHelper,
protected PreferenceHelper $preferenceHelper,
array $data = []
) {
parent::__construct($context, $dataHelper, $formatterFactory, $data);
$this->preferenceHelper = $preferenceHelper;
}

/**
Expand Down
5 changes: 1 addition & 4 deletions Block/Zone/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@
*/
class Profiler extends AbstractZone
{
protected ProfilerHelper $profilerHelper;

public function __construct(
Context $context,
DataHelper $dataHelper,
FormatterFactory $formatterFactory,
ProfilerHelper $profilerHelper,
protected ProfilerHelper $profilerHelper,
array $data = []
) {
parent::__construct($context, $dataHelper, $formatterFactory, $data);
$this->profilerHelper = $profilerHelper;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Block/Zone/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getSummarySections(): array
/**
* @inheritdoc
*/
public function addToSummary(string $sectionName, string $key, $value): void
public function addToSummary(string $sectionName, string $key, mixed $value): void
{
if (is_array($value) && array_key_exists('has_warning', $value) && $value['has_warning']) {
$this->hasWarning();
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## WIP

- Set minimum PHP version to 8.1

## [6.1.3] - 2023-09-04
[6.1.3]: https://github.com/Smile-SA/magento2-module-debug-toolbar/compare/6.1.2...6.1.3

Expand Down
5 changes: 1 addition & 4 deletions Controller/Index/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@

class Index implements HttpGetActionInterface
{
protected ResultFactory $resultFactory;

public function __construct(ResultFactory $resultFactory)
public function __construct(protected ResultFactory $resultFactory)
{
$this->resultFactory = $resultFactory;
}

/**
Expand Down
28 changes: 8 additions & 20 deletions DB/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Profiler extends OriginalProfiler
{
/**
* @inheritDoc
* @inheritdoc
*/
public function queryStart($queryText, $queryType = null): ?int
{
Expand Down Expand Up @@ -44,24 +44,12 @@ protected function getTypeFromQuery(string $queryText): int
}
$base = strtolower($base);

switch ($base) {
case 'insert':
$queryType = self::INSERT;
break;
case 'update':
$queryType = self::UPDATE;
break;
case 'delete':
$queryType = self::DELETE;
break;
case 'select':
$queryType = self::SELECT;
break;
default:
$queryType = self::QUERY;
break;
}

return $queryType;
return match ($base) {
'insert' => self::INSERT,
'update' => self::UPDATE,
'delete' => self::DELETE,
'select' => self::SELECT,
default => self::QUERY,
};
}
}
Loading

0 comments on commit 25a1f30

Please sign in to comment.