Skip to content

Commit a3fc2ca

Browse files
author
Adam Halfar
committed
Revert unwanted formatting, add checks if functions exists, add inflate for content loaded from resource
1 parent e238bcb commit a3fc2ca

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

src/Model/Entity/Panel.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,20 @@ class Panel extends Entity
4646
*/
4747
protected function _getContent(mixed $content): string
4848
{
49-
if (is_string($content)) {
49+
if (is_resource($content)) {
50+
$content = (string)stream_get_contents($content);
51+
}
52+
53+
if (is_string($content) && function_exists('gzinflate')) {
5054
// phpcs:disable
5155
$contentInflated = @gzinflate($content);
5256
// phpcs:enable
5357
if ($contentInflated !== false) {
5458
return $contentInflated;
5559
}
56-
57-
return $content;
5860
}
5961

60-
if (is_resource($content)) {
61-
return (string)stream_get_contents($content);
62-
}
63-
64-
return '';
62+
return $content;
6563
}
6664

6765
/**
@@ -72,9 +70,9 @@ protected function _getContent(mixed $content): string
7270
*/
7371
protected function _setContent(mixed $content): mixed
7472
{
75-
if (is_string($content)) {
73+
if (is_string($content) && function_exists('gzdeflate')) {
7674
$contentDeflated = gzdeflate($content, 9);
77-
if ($contentDeflated !== false) {
75+
if ($contentDeflated) {
7876
$content = $contentDeflated;
7977
}
8078
}

src/Model/Table/RequestsTable.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
declare(strict_types=1);
43

54
/**
@@ -35,7 +34,8 @@
3534
* @method \DebugKit\Model\Entity\Request[] patchEntities($entities, array $data, array $options = [])
3635
* @method \DebugKit\Model\Entity\Request findOrCreate($search, callable $callback = null, array $options = [])
3736
*/
38-
class RequestsTable extends Table {
37+
class RequestsTable extends Table
38+
{
3939
use LazyTableTrait;
4040
use SqlTraceTrait;
4141

@@ -45,7 +45,8 @@ class RequestsTable extends Table {
4545
* @param array $config Config data.
4646
* @return void
4747
*/
48-
public function initialize(array $config): void {
48+
public function initialize(array $config): void
49+
{
4950
$this->hasMany('DebugKit.Panels', [
5051
'sort' => ['Panels.title' => 'ASC'],
5152
]);
@@ -62,7 +63,8 @@ public function initialize(array $config): void {
6263
*
6364
* @return string
6465
*/
65-
public static function defaultConnectionName(): string {
66+
public static function defaultConnectionName(): string
67+
{
6668
return 'debug_kit';
6769
}
6870

@@ -72,7 +74,8 @@ public static function defaultConnectionName(): string {
7274
* @param \Cake\ORM\Query\SelectQuery $query The query
7375
* @return \Cake\ORM\Query\SelectQuery The query.
7476
*/
75-
public function findRecent(SelectQuery $query): SelectQuery {
77+
public function findRecent(SelectQuery $query): SelectQuery
78+
{
7679
return $query->orderBy(['Requests.requested_at' => 'DESC'])
7780
->limit(10);
7881
}
@@ -82,7 +85,8 @@ public function findRecent(SelectQuery $query): SelectQuery {
8285
*
8386
* @return bool
8487
*/
85-
protected function shouldGc(): bool {
88+
protected function shouldGc(): bool
89+
{
8690
return rand(1, 10) === 10;
8791
}
8892

@@ -91,7 +95,8 @@ protected function shouldGc(): bool {
9195
*
9296
* @return bool
9397
*/
94-
protected function shouldGcVacuum(): bool {
98+
protected function shouldGcVacuum(): bool
99+
{
95100
return rand(1, 10) === 10;
96101
}
97102

@@ -104,7 +109,8 @@ protected function shouldGcVacuum(): bool {
104109
*
105110
* @return void
106111
*/
107-
public function gc(): void {
112+
public function gc(): void
113+
{
108114
if (!$this->shouldGc()) {
109115
return;
110116
}

0 commit comments

Comments
 (0)