Skip to content

Commit 3989a6d

Browse files
committed
Fix scoper issues for WP specifically
1 parent b9742ba commit 3989a6d

File tree

5 files changed

+86
-22
lines changed

5 files changed

+86
-22
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,10 @@ fabric.properties
120120
/build/
121121

122122
# End of https://www.toptal.com/developers/gitignore/api/composer,phpcodesniffer,phpstorm+all,phpunit
123+
124+
# Build files
125+
WP_OIDC_Login_*.zip
126+
wp-oidc-login/
127+
128+
# Potential secrets
129+
.env

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"require": {
3030
"php": "^8.2",
3131
"jumbojett/openid-connect-php": "^1.0",
32-
"phpseclib/bcmath_compat": "^2.0"
32+
"phpseclib/bcmath_compat": "^2.0",
33+
"sniccowp/php-scoper-wordpress-excludes": "^6.9"
3334
},
3435
"require-dev": {
3536
"lkrms/pretty-php": "^0.4.94",

composer.lock

Lines changed: 48 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scoper.inc.php

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
<?php
2-
3-
declare(strict_types=1);
1+
<?php declare(strict_types=1);
42

53
use Isolated\Symfony\Component\Finder\Finder;
64

7-
return [
8-
'prefix' => 'OTWSystems\\WpOidcLogin\\Vendor',
5+
function getWpExcludedSymbols(string $fileName): array
6+
{
7+
$filePath = __DIR__ . '/vendor/sniccowp/php-scoper-wordpress-excludes/generated/' . $fileName;
8+
9+
return json_decode(
10+
file_get_contents($filePath),
11+
true,
12+
);
13+
}
914

15+
$wpConstants = getWpExcludedSymbols('exclude-wordpress-constants.json');
16+
$wpClasses = getWpExcludedSymbols('exclude-wordpress-classes.json');
17+
$wpFunctions = getWpExcludedSymbols('exclude-wordpress-functions.json');
18+
19+
return [
20+
'prefix' => 'OTWSystems\WpOidcLogin\Vendor',
1021
'finders' => [
1122
Finder::create()
1223
->files()
1324
->ignoreVCS(true)
14-
->notName('/.*\\.dist|Makefile|scoper.inc.php|build.sh|public-signing-key.pub|composer.json|composer.lock/')
25+
->notName('/.*\.dist|Makefile|scoper.inc.php|build.sh|public-signing-key.pub|composer.json|composer.lock/')
1526
->exclude([
1627
'doc',
1728
'test',
@@ -20,28 +31,25 @@
2031
'Tests',
2132
'vendor-bin',
2233
])
23-
->in(['vendor', '.']),
24-
34+
->in(['vendor', '.']),
2535
Finder::create()->append([
2636
'composer.json',
2737
]),
2838
],
29-
30-
'exclude-constants' => [
39+
'exclude-constants' => array_merge([
3140
'ABSPATH',
3241
'WP_OIDC_LOGIN_VERSION',
33-
],
34-
42+
], $wpConstants),
43+
'exclude-classes' => $wpClasses,
44+
'exclude-functions' => $wpFunctions,
3545
'exclude-namespaces' => [
3646
'/^OTWSystems\\\\WpOidcLogin\\\\/',
3747
'/^OTWSystems\\\\WpOidcLogin/',
38-
'/^Psr\\\/',
48+
'/^Psr\\\\/',
3949
],
40-
41-
'expose-global-constants' => false,
42-
'expose-global-classes' => false,
43-
'expose-global-functions' => false,
44-
50+
'expose-global-constants' => false,
51+
'expose-global-classes' => false,
52+
'expose-global-functions' => false,
4553
'patchers' => [
4654
static function (string $filePath, string $prefix, string $content): string {
4755
// Fix the string reference of a scoped dependency in the Math lib
@@ -51,15 +59,15 @@ static function (string $filePath, string $prefix, string $content): string {
5159
str_ends_with($filePath, 'vendor/phpseclib/phpseclib/phpseclib/Math/BigInteger/Engines/Engine.php')
5260
) {
5361
$content = str_replace(
54-
'phpseclib3\\Math\\BigInteger\\Engines\\\\',
62+
'phpseclib3\Math\BigInteger\Engines\\\\',
5563
"{$escapedPrefix}\\\\phpseclib3\\\\Math\\\\BigInteger\\\\Engines\\\\",
5664
$content
5765
);
5866
}
5967

6068
if (str_ends_with($filePath, 'vendor/phpseclib/phpseclib/phpseclib/Crypt/Common/AsymmetricKey.php')) {
6169
$content = str_replace(
62-
'phpseclib3\\Crypt\\\\',
70+
'phpseclib3\Crypt\\\\',
6371
"{$escapedPrefix}\\\\phpseclib3\\\\Crypt\\\\",
6472
$content
6573
);

src/Plugin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function getSdk(): OpenIDConnectClient
8484
$clientId = $this->getOptionString('client', 'id');
8585
$clientSecret = $this->getOptionString('client', 'secret');
8686
$this->sdk = new OpenIDConnectClient($endpoint, $clientId, $clientSecret);
87+
$this->sdk->setHttpUpgradeInsecureRequests(false);
8788
$this->sdk->addScope(['email', 'profile', 'groups']);
8889
}
8990

0 commit comments

Comments
 (0)