Skip to content

Commit

Permalink
Merge pull request #17 from LPawinsky/fix/lpawinski/session-build-error
Browse files Browse the repository at this point in the history
Fix phpcs build error on graphql disable session error
  • Loading branch information
makao authored Nov 27, 2023
2 parents efb02e0 + ccd7901 commit 9a55944
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
fail-fast: false
matrix:
php:
- "7.4"
- "8.1"
- "8.2"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
Expand Down
32 changes: 24 additions & 8 deletions Helper/Injector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

class Injector
{
private const TEMPLATE_TOOLBAR = 'ClawRock_Debug::profiler/toolbar/js.phtml';
private const TEMPLATE_BLOCK = 'ClawRock_Debug::profiler/js.phtml';

private \Magento\Framework\View\LayoutInterface $layout;
private \ClawRock\Debug\Model\View\Toolbar $viewModel;

Expand All @@ -27,16 +30,29 @@ public function inject(Request $request, Response $response, ?string $token = nu

if (false !== $pos) {
/** @var \Magento\Framework\View\Element\Template $toolbarBlock */
$toolbarBlock = $this->layout->createBlock(Template::class, 'debug.toolbar');
$toolbarBlock->setTemplate('ClawRock_Debug::profiler/toolbar/js.phtml')->setData([
'view_model' => $this->viewModel,
'token' => $token,
'request' => $request,
]);
$toolbarBlock = $this->layout->createBlock(
Template::class,
'debug.toolbar',
[
'data' => [
'template' => self::TEMPLATE_TOOLBAR,
'view_model' => $this->viewModel,
'token' => $token,
'request' => $request,
],
]
);

/** @var \Magento\Framework\View\Element\Template $jsBlock */
$jsBlock = $this->layout->createBlock(Template::class, 'debug.profiler.js');
$jsBlock->setTemplate('ClawRock_Debug::profiler/js.phtml');
$jsBlock = $this->layout->createBlock(
Template::class,
'debug.profiler.js',
[
'data' => [
'template' => self::TEMPLATE_BLOCK,
],
]
);

$toolbarBlock->setChild('debug_profiler_js', $jsBlock);

Expand Down
2 changes: 1 addition & 1 deletion Model/Info/RequestInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function getStatusCode(): int
*/
public function getSessionAttributes(): array
{
return session_status() ? $_SESSION : []; // phpcs:ignore Magento2.Security.Superglobal.SuperglobalUsageError
return $_SESSION ?? []; // phpcs:ignore Magento2.Security.Superglobal.SuperglobalUsageError
}

public function getPathInfo(): string
Expand Down
19 changes: 12 additions & 7 deletions Model/View/Renderer/LayoutGraphRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@ public function __construct(
public function render(): string
{
/** @var \Magento\Framework\View\Element\Template $block */
$block = $this->layout->createBlock(Template::class);
$block = $this->layout->createBlock(
Template::class,
'clawrock_layout_graph_renderer',
[
'data' => [
'template' => self::TEMPLATE,
'nodes' => $this->createNodes(),
'layout_node_renderer' => $this->layoutNodeRendererFactory,
],
]
);

return $block->setTemplate(self::TEMPLATE)
->setData([
'nodes' => $this->createNodes(),
'layout_node_renderer' => $this->layoutNodeRendererFactory,
])
->toHtml();
return $block->toHtml();
}

private function createNodes(): array
Expand Down
21 changes: 13 additions & 8 deletions Model/View/Renderer/LayoutNodeRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ public function __construct(
public function render(): string
{
/** @var \Magento\Framework\View\Element\Template $block */
$block = $this->layout->createBlock(Template::class);
$block = $this->layout->createBlock(
Template::class,
'',
[
'data' => [
'template' => self::TEMPLATE,
'node' => $this->node,
'formatter' => $this->formatter,
'layout_node_renderer' => $this->layoutNodeRendererFactory,
],
]
);

return $block->setTemplate(self::TEMPLATE)
->setData([
'node' => $this->node,
'formatter' => $this->formatter,
'layout_node_renderer' => $this->layoutNodeRendererFactory,
])
->toHtml();
return $block->toHtml();
}
}
17 changes: 12 additions & 5 deletions Model/View/Renderer/ParametersRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,18 @@ public function __construct(
public function render(): string
{
/** @var \Magento\Framework\View\Element\Template $block */
$block = $this->layout->createBlock(Template::class);
$block = $this->layout->createBlock(
Template::class,
'',
[
'data' => [
'template' => self::TEMPLATE,
'parameters' => $this->parameters,
'var_renderer' => $this->varRenderer,
],
]
);

return $block->setTemplate(self::TEMPLATE)
->setData('parameters', $this->parameters)
->setData('var_renderer', $this->varRenderer)
->toHtml();
return $block->toHtml();
}
}
23 changes: 14 additions & 9 deletions Model/View/Renderer/QueryListRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,20 @@ public function __construct(
public function render(): string
{
/** @var \Magento\Framework\View\Element\Template $block */
$block = $this->layout->createBlock(Template::class);
$block = $this->layout->createBlock(
Template::class,
'',
[
'data' => [
'template' => self::TEMPLATE,
'queries' => $this->queries,
'query_renderer' => $this->queryRendererFactory,
'prefix' => $this->mathRandom->getUniqueHash(),
'formatter' => $this->formatter,
],
]
);

return $block->setTemplate(self::TEMPLATE)
->setData([
'queries' => $this->queries,
'query_renderer' => $this->queryRendererFactory,
'prefix' => $this->mathRandom->getUniqueHash(),
'formatter' => $this->formatter,
])
->toHtml();
return $block->toHtml();
}
}
37 changes: 21 additions & 16 deletions Model/View/Renderer/QueryRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,27 @@ public function __construct(
public function render(): string
{
/** @var \Magento\Framework\View\Element\Template $block */
$block = $this->layout->createBlock(Template::class);
$block = $this->layout->createBlock(
Template::class,
'',
[
'data' => [
'template' => self::TEMPLATE,
'query' => $this->query,
'highlighted_query' => $this->databaseHelper->highlightQuery($this->query->getQuery()),
'formatted_query' => $this->databaseHelper->formatQuery($this->query->getQuery()),
'runnable_query' => $this->databaseHelper->highlightQuery(
$this->databaseHelper->replaceQueryParameters(
$this->query->getQuery(),
$this->query->getQueryParams()
)
),
'var_renderer' => $this->varRenderer,
'uniq_id' => $this->mathRandom->getUniqueHash(),
],
]
);

return $block->setTemplate(self::TEMPLATE)
->setData([
'query' => $this->query,
'highlighted_query' => $this->databaseHelper->highlightQuery($this->query->getQuery()),
'formatted_query' => $this->databaseHelper->formatQuery($this->query->getQuery()),
'runnable_query' => $this->databaseHelper->highlightQuery(
$this->databaseHelper->replaceQueryParameters(
$this->query->getQuery(),
$this->query->getQueryParams()
)
),
'var_renderer' => $this->varRenderer,
'uniq_id' => $this->mathRandom->getUniqueHash(),
])
->toHtml();
return $block->toHtml();
}
}
15 changes: 11 additions & 4 deletions Model/View/Renderer/RedirectRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,17 @@ public function __construct(
public function render(): string
{
/** @var \Magento\Framework\View\Element\Template $block */
$block = $this->layout->createBlock(Template::class);

return $block->setTemplate(self::TEMPLATE)
->setProfilerUrl($this->url->getProfilerUrl($this->redirect->getToken()))
$block = $this->layout->createBlock(
Template::class,
'',
[
'data' => [
'template' => self::TEMPLATE,
],
]
);

return $block->setProfilerUrl($this->url->getProfilerUrl($this->redirect->getToken()))
->setRedirect($this->redirect)
->toHtml();
}
Expand Down
23 changes: 15 additions & 8 deletions Model/View/Renderer/TableRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ public function __construct(
public function render(): string
{
/** @var \Magento\Framework\View\Element\Template $block */
$block = $this->layout->createBlock(Template::class);
$block = $this->layout->createBlock(
Template::class,
'',
[
'data' => [
'template' => self::TEMPLATE,
'items' => $this->items,
'labels' => $this->labels,
'var_renderer' => $this->varRenderer,
'key_label' => $this->labels[0] ?? 'Key',
'value_label' => $this->labels[1] ?? 'Value',
],
]
);

return $block->setTemplate(self::TEMPLATE)
->setData('items', $this->items)
->setData('labels', $this->labels)
->setData('var_renderer', $this->varRenderer)
->setData('key_label', $this->labels[0] ?? 'Key')
->setData('value_label', $this->labels[1] ?? 'Value')
->toHtml();
return $block->toHtml();
}
}
12 changes: 10 additions & 2 deletions Model/View/Renderer/TraceCallRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ public function __construct(
public function render(): string
{
/** @var \Magento\Framework\View\Element\Template $block */
$block = $this->layout->createBlock(Template::class);
$block = $this->layout->createBlock(
Template::class,
'',
[
'data' => [
'template' => self::TEMPLATE,
],
]
);

foreach (self::CALL_INFO as $info) {
if (isset($this->call[$info])) {
Expand All @@ -38,7 +46,7 @@ public function render(): string
$block->setFile($this->relativizePath($block->getFile()));
}

return $block->setTemplate(self::TEMPLATE)->toHtml();
return $block->toHtml();
}

private function relativizePath(string $path): string
Expand Down
21 changes: 14 additions & 7 deletions Model/View/Renderer/TraceRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ public function __construct(
public function render(): string
{
/** @var \Magento\Framework\View\Element\Template $block */
$block = $this->layout->createBlock(Template::class);

return $block->setTemplate(self::TEMPLATE)
->setData('trace', $this->trace)
->setData('trace_id', $this->id)
->setData('trace_call_renderer', $this->traceCallRendererFactory)
->toHtml();
$block = $this->layout->createBlock(
Template::class,
'',
[
'data' => [
'template' => self::TEMPLATE,
'trace' => $this->trace,
'trace_id' => $this->id,
'trace_call_renderer' => $this->traceCallRendererFactory,
],
]
);

return $block->toHtml();
}

public function getId(): string
Expand Down
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Module for debugging Magento 2 performance. It works without overwriting any cor
All settings have only default scope and config type pool is set to environment for better integration with `php bin/magento app:config:dump`

## Compatibility
* Magento 2.4
* PHP 7.4, 8.1
* Magento >= 2.4.4
* PHP 8.1, 8.2

## Profiler collectors
- Ajax
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"AFL-3.0"
],
"require": {
"php": ">=7.4",
"php": ">=8.1",
"magento/framework": "~103.0",
"magento/module-backend": "~102.0",
"magento/module-developer": "^100.4",
Expand All @@ -17,16 +17,16 @@
"symfony/stopwatch": "^2.8 || ^3.0 || ^4.0 || ^5.0"
},
"require-dev": {
"bitexpert/phpstan-magento": "^0.28.0",
"bitexpert/phpstan-magento": "^0.30.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
"magento/magento-coding-standard": "*",
"phpcompatibility/php-compatibility": "^9.3",
"phpmd/phpmd": "^2.9.1",
"phpstan/phpstan": "~1.9.0",
"phpstan/phpstan": "~1.10.0",
"phpunit/phpunit": "~9.5.0",
"sebastian/phpcpd": "^6.0.3",
"slevomat/coding-standard": "~6.4.1",
"squizlabs/php_codesniffer": "~3.6.0",
"squizlabs/php_codesniffer": "~3.7.2",
"phpstan/phpstan-phpunit": "^1.1.1"
},
"repositories": [
Expand Down

0 comments on commit 9a55944

Please sign in to comment.