Skip to content

Commit 930f882

Browse files
committed
Remove dead code for old PHP versions
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 66c640d commit 930f882

10 files changed

Lines changed: 13 additions & 104 deletions

File tree

libraries/classes/Config.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
use const PHP_OS;
6767
use const PHP_URL_PATH;
6868
use const PHP_URL_SCHEME;
69-
use const PHP_VERSION_ID;
7069

7170
/**
7271
* Configuration handling
@@ -952,18 +951,6 @@ public function setCookie(
952951
/** @psalm-var 'Lax'|'Strict'|'None' $cookieSameSite */
953952
$cookieSameSite = $this->get('CookieSameSite');
954953

955-
if (PHP_VERSION_ID < 70300) {
956-
return setcookie(
957-
$httpCookieName,
958-
$value,
959-
$validity,
960-
$this->getRootPath() . '; SameSite=' . $cookieSameSite,
961-
'',
962-
$this->isHttps(),
963-
$httponly
964-
);
965-
}
966-
967954
$optionalParams = [
968955
'expires' => $validity,
969956
'path' => $this->getRootPath(),

libraries/classes/ErrorHandler.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
use const E_USER_NOTICE;
3535
use const E_USER_WARNING;
3636
use const E_WARNING;
37-
use const PHP_VERSION_ID;
3837

3938
/**
4039
* handling errors
@@ -202,9 +201,6 @@ public function handleError(
202201
* See: https://github.com/phpmyadmin/phpmyadmin/issues/16729
203202
*/
204203
$isSilenced = ! (error_reporting() & $errno);
205-
if (PHP_VERSION_ID < 80000) {
206-
$isSilenced = error_reporting() == 0;
207-
}
208204

209205
if (
210206
isset($GLOBALS['cfg']['environment'])

libraries/classes/Image/ImageWrapper.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace PhpMyAdmin\Image;
66

7-
use function count;
87
use function extension_loaded;
98
use function function_exists;
109
use function imagearc;
@@ -22,8 +21,6 @@
2221
use function imagesx;
2322
use function imagesy;
2423

25-
use const PHP_VERSION_ID;
26-
2724
final class ImageWrapper
2825
{
2926
/** @var resource */
@@ -141,19 +138,11 @@ public function copyResampled(
141138

142139
public function destroy(): bool
143140
{
144-
if (PHP_VERSION_ID >= 80000) {
145-
return true;
146-
}
147-
148-
return imagedestroy($this->image);
141+
return true;
149142
}
150143

151144
public function filledPolygon(array $points, int $color): bool
152145
{
153-
if (PHP_VERSION_ID < 80000) {
154-
return imagefilledpolygon($this->image, $points, (int) (count($points) / 2), $color);
155-
}
156-
157146
return imagefilledpolygon($this->image, $points, $color);
158147
}
159148

libraries/classes/Plugins/Auth/AuthenticationSignon.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
use function session_set_cookie_params;
2424
use function session_start;
2525
use function session_write_close;
26-
use function version_compare;
27-
28-
use const PHP_VERSION;
2926

3027
/**
3128
* Handles the SignOn authentication method
@@ -110,18 +107,7 @@ public function setCookieParams(?array $sessionCookieParams = null): void
110107
unset($sessionCookieParams['samesite']);
111108
}
112109

113-
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
114-
/** @psalm-suppress InvalidArgument */
115-
session_set_cookie_params($sessionCookieParams);
116-
} else {
117-
session_set_cookie_params(
118-
$sessionCookieParams['lifetime'],
119-
$sessionCookieParams['path'],
120-
$sessionCookieParams['domain'],
121-
$sessionCookieParams['secure'],
122-
$sessionCookieParams['httponly']
123-
);
124-
}
110+
session_set_cookie_params($sessionCookieParams);
125111
}
126112

127113
/**

libraries/classes/Plugins/Import/ImportOds.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@
2323
use function __;
2424
use function count;
2525
use function implode;
26-
use function libxml_disable_entity_loader;
2726
use function rtrim;
2827
use function simplexml_load_string;
2928
use function strcmp;
3029
use function strlen;
3130

3231
use const LIBXML_COMPACT;
33-
use const PHP_VERSION_ID;
3432

3533
/**
3634
* Handles the import for the ODS format
@@ -130,14 +128,6 @@ public function doImport(?File $importHandle = null): array
130128
$buffer .= $data;
131129
}
132130

133-
/**
134-
* Disable loading of external XML entities for PHP versions below 8.0.
135-
*/
136-
if (PHP_VERSION_ID < 80000) {
137-
// phpcs:ignore Generic.PHP.DeprecatedFunctions.Deprecated
138-
libxml_disable_entity_loader();
139-
}
140-
141131
/**
142132
* Load the XML string
143133
*

libraries/classes/Plugins/Import/ImportXml.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@
2020
use function __;
2121
use function count;
2222
use function in_array;
23-
use function libxml_disable_entity_loader;
2423
use function simplexml_load_string;
2524
use function str_replace;
2625
use function strcmp;
2726
use function strlen;
2827

2928
use const LIBXML_COMPACT;
30-
use const PHP_VERSION_ID;
3129

3230
/**
3331
* Handles the import for the XML format
@@ -86,14 +84,6 @@ public function doImport(?File $importHandle = null): array
8684
$buffer .= $data;
8785
}
8886

89-
/**
90-
* Disable loading of external XML entities for PHP versions below 8.0.
91-
*/
92-
if (PHP_VERSION_ID < 80000) {
93-
// phpcs:ignore Generic.PHP.DeprecatedFunctions.Deprecated
94-
libxml_disable_entity_loader();
95-
}
96-
9787
/**
9888
* Load the XML string
9989
*

libraries/classes/Session.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use function setcookie;
2727

2828
use const PHP_SESSION_ACTIVE;
29-
use const PHP_VERSION_ID;
3029

3130
class Session
3231
{
@@ -132,18 +131,15 @@ public static function setUp(Config $config, ErrorHandler $errorHandler): void
132131
/** @psalm-var 'Lax'|'Strict'|'None' $cookieSameSite */
133132
$cookieSameSite = $config->get('CookieSameSite') ?? 'Strict';
134133
$cookiePath = $config->getRootPath();
135-
if (PHP_VERSION_ID < 70300) {
136-
$cookiePath .= '; SameSite=' . $cookieSameSite;
137-
}
138134

139-
// session cookie settings
140-
session_set_cookie_params(
141-
0,
142-
$cookiePath,
143-
'',
144-
$config->isHttps(),
145-
true
146-
);
135+
session_set_cookie_params([
136+
'lifetime' => 0,
137+
'path' => $cookiePath,
138+
'domain' => '',
139+
'secure' => $config->isHttps(),
140+
'httponly' => true,
141+
'samesite' => $cookieSameSite,
142+
]);
147143

148144
// cookies are safer (use ini_set() in case this function is disabled)
149145
ini_set('session.use_cookies', 'true');
@@ -164,10 +160,8 @@ public static function setUp(Config $config, ErrorHandler $errorHandler): void
164160
ini_set('session.use_strict_mode', '1');
165161
// make the session cookie HttpOnly
166162
ini_set('session.cookie_httponly', '1');
167-
if (PHP_VERSION_ID >= 70300) {
168-
// add SameSite to the session cookie
169-
ini_set('session.cookie_samesite', $cookieSameSite);
170-
}
163+
// add SameSite to the session cookie
164+
ini_set('session.cookie_samesite', $cookieSameSite);
171165

172166
// do not force transparent session ids
173167
ini_set('session.use_trans_sid', '0');

phpstan-baseline.neon

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4795,14 +4795,9 @@ parameters:
47954795
count: 1
47964796
path: libraries/classes/Image/ImageWrapper.php
47974797

4798-
-
4799-
message: "#^Parameter \\#1 \\$image of function imagedestroy expects GdImage, resource given\\.$#"
4800-
count: 1
4801-
path: libraries/classes/Image/ImageWrapper.php
4802-
48034798
-
48044799
message: "#^Parameter \\#1 \\$image of function imagefilledpolygon expects GdImage, resource given\\.$#"
4805-
count: 2
4800+
count: 1
48064801
path: libraries/classes/Image/ImageWrapper.php
48074802

48084803
-
@@ -11250,11 +11245,6 @@ parameters:
1125011245
count: 1
1125111246
path: test/classes/Plugins/Auth/AuthenticationHttpTest.php
1125211247

11253-
-
11254-
message: "#^Casting to string something that's already string\\.$#"
11255-
count: 1
11256-
path: test/classes/Plugins/Auth/AuthenticationSignonTest.php
11257-
1125811248
-
1125911249
message: "#^Parameter \\#2 \\$haystack of method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\) expects string, mixed given\\.$#"
1126011250
count: 1

psalm-baseline.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8958,8 +8958,6 @@
89588958
<code>$this-&gt;image</code>
89598959
<code>$this-&gt;image</code>
89608960
<code>$this-&gt;image</code>
8961-
<code>$this-&gt;image</code>
8962-
<code>$this-&gt;image</code>
89638961
</InvalidArgument>
89648962
<PossiblyUnusedReturnValue>
89658963
<code>bool</code>
@@ -10859,11 +10857,6 @@
1085910857
</file>
1086010858
<file src="libraries/classes/Plugins/Auth/AuthenticationSignon.php">
1086110859
<MixedArgument>
10862-
<code>$sessionCookieParams['domain']</code>
10863-
<code>$sessionCookieParams['httponly']</code>
10864-
<code>$sessionCookieParams['lifetime']</code>
10865-
<code>$sessionCookieParams['path']</code>
10866-
<code>$sessionCookieParams['secure']</code>
1086710860
<code>$single_signon_cfgupdate</code>
1086810861
</MixedArgument>
1086910862
<MixedArgumentTypeCoercion>

test/classes/Plugins/Auth/AuthenticationSignonTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111

1212
use function ob_get_clean;
1313
use function ob_start;
14-
use function phpversion;
1514
use function session_get_cookie_params;
1615
use function session_id;
1716
use function session_name;
18-
use function version_compare;
1917

2018
/**
2119
* @covers \PhpMyAdmin\Plugins\Auth\AuthenticationSignon
@@ -348,10 +346,6 @@ public function testSetCookieParamsDefaults(): void
348346
'httponly' => false,
349347
'samesite' => '',
350348
];
351-
// php did not set 'samesite' attribute in session_get_cookie_params since not yet implemented
352-
if (version_compare((string) phpversion(), '7.3.0', '<')) {
353-
unset($defaultOptions['samesite']);
354-
}
355349

356350
$this->assertSame(
357351
$defaultOptions,

0 commit comments

Comments
 (0)