Skip to content

Commit e5adb14

Browse files
Fix PHPStan
Fix missing $ Fix "Received non-retryable error: Failed request: (409) Conflict: an artifact with this name already exists on the workflow run" Fix PHPStan
1 parent 33de85a commit e5adb14

32 files changed

+100
-237
lines changed

.github/workflows/ci.yaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ jobs:
2424
php-cs-fixer:
2525
runs-on: ubuntu-latest
2626
timeout-minutes: 5
27-
env:
28-
PHP_CS_FIXER_FUTURE_MODE: '1'
2927
steps:
3028
- name: Checkout
3129
uses: actions/checkout@v3
@@ -64,7 +62,6 @@ jobs:
6462
run: |
6563
composer global config --no-plugins allow-plugins.symfony/flex true
6664
composer global require symfony/flex --no-progress --no-scripts --no-plugins
67-
composer config extra.symfony.require "6.4"
6865
composer update --no-interaction --no-progress --ansi
6966
7067
- name: Run phpstan
@@ -80,15 +77,15 @@ jobs:
8077
- php: '8.3'
8178
symfony-version: '^6.4'
8279
- php: '8.3'
83-
symfony-version: '^7.3'
84-
- php: '8.3'
85-
symfony-version: '^6.4'
86-
- php: '8.3'
87-
symfony-version: '^7.3'
80+
symfony-version: '^7.4'
8881
- php: '8.4'
8982
symfony-version: '^6.4'
9083
- php: '8.4'
91-
symfony-version: '^7.3'
84+
symfony-version: '^7.4'
85+
- php: '8.5'
86+
symfony-version: '^6.4'
87+
- php: '8.5'
88+
symfony-version: '^7.4'
9289
fail-fast: false
9390

9491
steps:
@@ -125,6 +122,6 @@ jobs:
125122
if: always()
126123
uses: actions/upload-artifact@v4
127124
with:
128-
name: phpunit-logs-php${{ matrix.php }}
125+
name: phpunit-logs-php${{ matrix.php }}-symfony${{ matrix.symfony-version }}
129126
path: build/logs/phpunit
130127
continue-on-error: true

composer.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,31 +95,31 @@
9595
"require": {
9696
"php": "^8.3",
9797
"symfony/deprecation-contracts": "^3.0",
98-
"symfony/framework-bundle": "^6.4 || ^7.3",
99-
"symfony/http-foundation": "^6.4 || ^7.3",
100-
"symfony/security-bundle": "^6.4 || ^7.3",
101-
"symfony/options-resolver": "^6.4 || ^7.3",
102-
"symfony/form": "^6.4 || ^7.3",
103-
"symfony/http-client": "^6.4 || ^7.3",
104-
"symfony/routing": "^6.4 || ^7.3",
105-
"symfony/twig-bundle": "^6.4 || ^7.3"
98+
"symfony/framework-bundle": "^6.4 || ^7.4",
99+
"symfony/http-foundation": "^6.4 || ^7.4",
100+
"symfony/security-bundle": "^6.4 || ^7.4",
101+
"symfony/options-resolver": "^6.4 || ^7.4",
102+
"symfony/form": "^6.4 || ^7.4",
103+
"symfony/http-client": "^6.4 || ^7.4",
104+
"symfony/routing": "^6.4 || ^7.4",
105+
"symfony/twig-bundle": "^6.4 || ^7.4"
106106
},
107107

108108
"require-dev": {
109109
"doctrine/doctrine-bundle": "^2.4",
110110
"doctrine/orm": "^2.9",
111-
"symfony/browser-kit": "^6.4 || ^7.3",
112-
"symfony/css-selector": "^6.4 || ^7.3",
113-
"symfony/property-access": "^6.4 || ^7.3",
114-
"symfony/validator": "^6.4 || ^7.3",
115-
"symfony/stopwatch": "^6.4 || ^7.3",
116-
"symfony/translation": "^6.4 || ^7.3",
117-
"symfony/yaml": "^6.4 || ^7.3",
111+
"symfony/browser-kit": "^6.4 || ^7.4",
112+
"symfony/css-selector": "^6.4 || ^7.4",
113+
"symfony/property-access": "^6.4 || ^7.4",
114+
"symfony/validator": "^6.4 || ^7.4",
115+
"symfony/stopwatch": "^6.4 || ^7.4",
116+
"symfony/translation": "^6.4 || ^7.4",
117+
"symfony/yaml": "^6.4 || ^7.4",
118118
"phpunit/phpunit": "^12.3",
119119
"friendsofphp/php-cs-fixer": "^3.23",
120120
"symfony/monolog-bundle": "^3.4",
121-
"phpstan/phpstan": "^1.10",
122-
"phpstan/phpstan-symfony": "^1.3",
121+
"phpstan/phpstan": "^2.1",
122+
"phpstan/phpstan-symfony": "^2.0",
123123
"phpstan/extension-installer": "^1.3",
124124
"firebase/php-jwt": "^6.8"
125125
},

phpstan.neon

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ parameters:
44
- src/
55
- tests/
66
excludePaths:
7-
# Symfony <5.4 BC layer
8-
- src/DependencyInjection/Security/Factory/OAuthFactory.php
9-
- src/Security/Core/Authentication/Provider/OAuthProvider.php
107
- src/Security/Core/Exception/AccountNotLinkedException.php
118
- src/Security/Core/User/OAuthAwareUserProviderInterface.php
129
- src/Security/Http/Firewall/OAuthListener.php

src/Controller/Connect/AbstractController.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ protected function authenticateUser(Request $request, UserInterface $user, strin
120120
*/
121121
protected function getConfirmationResponse(Request $request, array $accessToken, string $service): Response
122122
{
123-
/** @var OAuthToken $currentToken */
124123
$currentToken = $this->tokenStorage->getToken();
125124
/** @var UserInterface $currentUser */
126125
$currentUser = $currentToken->getUser();
@@ -164,17 +163,9 @@ protected function dispatch(Event $event, ?string $eventName = null): void
164163
$this->dispatcher->dispatch($event, $eventName);
165164
}
166165

167-
protected function getSession(): ?SessionInterface
166+
protected function getSession(): SessionInterface
168167
{
169-
if (method_exists($this->requestStack, 'getSession')) {
170-
return $this->requestStack->getSession();
171-
}
172-
173-
if ((null !== $request = $this->requestStack->getCurrentRequest()) && $request->hasSession()) {
174-
return $request->getSession();
175-
}
176-
177-
return null;
168+
return $this->requestStack->getSession();
178169
}
179170

180171
protected function getTargetPath(?SessionInterface $session): ?string

src/Controller/Connect/ConnectController.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function connectServiceAction(Request $request, string $service): Respons
109109
$resourceOwner = $this->getResourceOwnerByName($service);
110110

111111
$session = $request->hasSession() ? $request->getSession() : $this->getSession();
112-
if ($session && !$session->isStarted()) {
112+
if (!$session->isStarted()) {
113113
$session->start();
114114
}
115115

@@ -122,11 +122,9 @@ public function connectServiceAction(Request $request, string $service): Respons
122122
$this->oauthUtils->getServiceAuthUrl($request, $resourceOwner)
123123
);
124124

125-
if ($session) {
126-
// save in session
127-
$session->set('_hwi_oauth.connect_confirmation.'.$key, $accessToken);
128-
}
129-
} elseif ($session) {
125+
// save in session
126+
$session->set('_hwi_oauth.connect_confirmation.'.$key, $accessToken);
127+
} else {
130128
$accessToken = $session->get('_hwi_oauth.connect_confirmation.'.$key);
131129
}
132130

src/Controller/Connect/RegisterController.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ public function registrationAction(Request $request, string $key): Response
103103

104104
$error = null;
105105
$session = $request->hasSession() ? $request->getSession() : $this->getSession();
106-
if ($session) {
107-
if (!$session->isStarted()) {
108-
$session->start();
109-
}
110-
$error = $session->get('_hwi_oauth.registration_error.'.$key);
111-
$session->remove('_hwi_oauth.registration_error.'.$key);
106+
if (!$session->isStarted()) {
107+
$session->start();
112108
}
113109

110+
$error = $session->get('_hwi_oauth.registration_error.'.$key);
111+
112+
$session->remove('_hwi_oauth.registration_error.'.$key);
113+
114114
if (!$error instanceof AccountNotLinkedException) {
115115
throw new RuntimeException('Cannot register an account.', 0, $error instanceof Exception ? $error : null);
116116
}
@@ -154,10 +154,8 @@ public function registrationAction(Request $request, string $key): Response
154154
return $event->getResponse();
155155
}
156156

157-
if ($session) {
158-
// reset the error in the session
159-
$session->set('_hwi_oauth.registration_error.'.$key, $error);
160-
}
157+
// reset the error in the session
158+
$session->set('_hwi_oauth.registration_error.'.$key, $error);
161159

162160
/** @var UserInterface $user */
163161
$user = $form->getData();

src/Controller/LoginController.php

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Component\HttpFoundation\Request;
1818
use Symfony\Component\HttpFoundation\RequestStack;
1919
use Symfony\Component\HttpFoundation\Response;
20-
use Symfony\Component\HttpFoundation\Session\SessionInterface;
2120
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2221
use Symfony\Component\Routing\RouterInterface;
2322
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
@@ -77,15 +76,13 @@ public function connectAction(Request $request): Response
7776
// if connecting is enabled and there is no user, redirect to the registration form
7877
if ($this->connect && !$hasUser && $error instanceof AccountNotLinkedException) {
7978
$key = time();
80-
$session = $request->hasSession() ? $request->getSession() : $this->getSession();
81-
if ($session) {
82-
if (!$session->isStarted()) {
83-
$session->start();
84-
}
85-
86-
$session->set('_hwi_oauth.registration_error.'.$key, $error);
79+
$session = $request->hasSession() ? $request->getSession() : $this->requestStack->getSession();
80+
if (!$session->isStarted()) {
81+
$session->start();
8782
}
8883

84+
$session->set('_hwi_oauth.registration_error.'.$key, $error);
85+
8986
return new RedirectResponse($this->router->generate('hwi_oauth_connect_registration', ['key' => $key], UrlGeneratorInterface::ABSOLUTE_PATH));
9087
}
9188

@@ -97,17 +94,4 @@ public function connectAction(Request $request): Response
9794
$this->twig->render('@HWIOAuth/Connect/login.html.twig', ['error' => $error])
9895
);
9996
}
100-
101-
private function getSession(): ?SessionInterface
102-
{
103-
if (method_exists($this->requestStack, 'getSession')) {
104-
return $this->requestStack->getSession();
105-
}
106-
107-
if ((null !== $request = $this->requestStack->getCurrentRequest()) && $request->hasSession()) {
108-
return $request->getSession();
109-
}
110-
111-
return null;
112-
}
11397
}

src/DependencyInjection/Configuration.php

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use HWI\Bundle\OAuthBundle\OAuth\ResourceOwnerInterface;
1717
use LogicException;
1818
use ReflectionClass;
19-
use Symfony\Component\Config\Definition\BaseNode;
2019
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
2120
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
2221
use Symfony\Component\Config\Definition\ConfigurationInterface;
@@ -114,7 +113,11 @@ public function getConfigTreeBuilder(): TreeBuilder
114113
->fixXmlConfig('firewall_name')
115114
->children()
116115
->arrayNode('firewall_names')
117-
->setDeprecated(...$this->getDeprecationParams())
116+
->setDeprecated(
117+
'hwi/oauth-bundle',
118+
'2.0',
119+
'option "%path%.%node%" is deprecated. Firewall names are collected automatically.',
120+
)
118121
->defaultValue([])
119122
->prototype('scalar')->end()
120123
->end()
@@ -417,27 +420,4 @@ private static function loadResourceOwners(): void
417420
self::registerResourceOwner('HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\\'.str_replace('.php', '', $f->getFilename()));
418421
}
419422
}
420-
421-
/**
422-
* Returns the correct deprecation params as an array for setDeprecated().
423-
*
424-
* symfony/config v5.1 introduces a deprecation notice when calling
425-
* setDeprecated() with less than 3 args and the getDeprecation() method was
426-
* introduced at the same time. By checking if getDeprecation() exists,
427-
* we can determine the correct param count to use when calling setDeprecated().
428-
*
429-
* @return string[]
430-
*/
431-
private function getDeprecationParams(): array
432-
{
433-
if (method_exists(BaseNode::class, 'getDeprecation')) {
434-
return [
435-
'hwi/oauth-bundle',
436-
'2.0',
437-
'option "%path%.%node%" is deprecated. Firewall names are collected automatically.',
438-
];
439-
}
440-
441-
return ['Since hwi/oauth-bundle 2.0: option "hwi_oauth.firewall_names" is deprecated. Firewall names are collected automatically.'];
442-
}
443423
}

src/DependencyInjection/Security/Factory/OAuthAuthenticatorFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ protected function createAuthProvider(ContainerBuilder $container, string $id, a
177177
/**
178178
* {@inheritdoc}
179179
*/
180-
protected function createEntryPoint($container, $id, $config, ?string $defaultEntryPointId): ?string
180+
protected function createEntryPoint($container, $id, $config, ?string $defaultEntryPointId): string
181181
{
182182
$entryPointId = 'hwi_oauth.authentication.entry_point.oauth.'.$id;
183183

src/HWIOAuthBundle.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
use HWI\Bundle\OAuthBundle\DependencyInjection\CompilerPass\EnableRefreshOAuthTokenListenerCompilerPass;
1515
use HWI\Bundle\OAuthBundle\DependencyInjection\CompilerPass\ResourceOwnerCompilerPass;
16+
use HWI\Bundle\OAuthBundle\DependencyInjection\HWIOAuthExtension;
1617
use HWI\Bundle\OAuthBundle\DependencyInjection\Security\Factory\OAuthAuthenticatorFactory;
17-
use RuntimeException;
1818
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
1919
use Symfony\Component\DependencyInjection\ContainerBuilder;
2020
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
@@ -33,16 +33,13 @@ public function build(ContainerBuilder $container): void
3333
{
3434
parent::build($container);
3535

36+
/** @var HWIOAuthExtension $oAuthExtension */
37+
$oAuthExtension = $this->extension;
38+
$firewallNames = $oAuthExtension->getFirewallNames();
39+
3640
/** @var SecurityExtension $extension */
3741
$extension = $container->getExtension('security');
38-
39-
$firewallNames = $this->extension->getFirewallNames();
40-
41-
if (method_exists($extension, 'addAuthenticatorFactory')) {
42-
$extension->addAuthenticatorFactory(new OAuthAuthenticatorFactory($firewallNames));
43-
} else {
44-
throw new RuntimeException('Unsupported Symfony Security component version');
45-
}
42+
$extension->addAuthenticatorFactory(new OAuthAuthenticatorFactory($firewallNames));
4643

4744
$container->addCompilerPass(new ResourceOwnerCompilerPass());
4845
$container->addCompilerPass(new EnableRefreshOAuthTokenListenerCompilerPass());

0 commit comments

Comments
 (0)