Skip to content

Commit 8a759df

Browse files
authored
Merge pull request #41 from samsonasik/php74-syntax
Apply PHP 7.4 syntax
2 parents 3eac9d1 + 30defee commit 8a759df

File tree

9 files changed

+26
-37
lines changed

9 files changed

+26
-37
lines changed

src/Factory/AuthControllerFactory.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ private function getOAuth2ServerFactory(ContainerInterface $container)
5959
return $oauth2ServerFactory;
6060
}
6161

62-
return function () use ($oauth2ServerFactory) {
63-
return $oauth2ServerFactory;
64-
};
62+
return fn() => $oauth2ServerFactory;
6563
}
6664

6765
/**

src/Factory/OAuth2ServerInstanceFactory.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Interop\Container\ContainerInterface; // phpcs:ignore WebimpressCodingStandard.PHP.CorrectClassNameCase.Invalid
88
use Laminas\ApiTools\OAuth2\Controller\Exception;
9-
use Laminas\ServiceManager\ServiceLocatorInterface;
109
use OAuth2\GrantType\AuthorizationCode;
1110
use OAuth2\GrantType\ClientCredentials;
1211
use OAuth2\GrantType\JwtBearer;
@@ -20,14 +19,11 @@
2019

2120
class OAuth2ServerInstanceFactory
2221
{
23-
/** @var array */
24-
private $config;
22+
private array $config;
2523

26-
/** @var ServiceLocatorInterface */
27-
private $services;
24+
private ContainerInterface $services;
2825

29-
/** @var OAuth2Server|null */
30-
private $server;
26+
private ?OAuth2Server $server = null;
3127

3228
/**
3329
* @param array $config Configuration to use when creating the instance.

src/Provider/UserId/AuthenticationService.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515

1616
class AuthenticationService implements UserIdProviderInterface
1717
{
18-
/** @var AuthenticationServiceInterface */
19-
private $authenticationService;
18+
private ?AuthenticationServiceInterface $authenticationService;
2019

21-
/** @var string */
22-
private $userId = 'id';
20+
private string $userId = 'id';
2321

2422
/**
2523
* Set authentication service

test/Adapter/Pdo/ClientTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
use OAuth2\Storage\ClientInterface;
88

9-
use function rand;
9+
use function mt_getrandmax;
10+
use function random_int;
1011

1112
class ClientTest extends AbstractBaseTest
1213
{
@@ -79,7 +80,7 @@ public function testSaveClient(ClientInterface $storage): void
7980
return;
8081
}
8182

82-
$clientId = 'some-client-' . rand();
83+
$clientId = 'some-client-' . random_int(0, mt_getrandmax());
8384

8485
// create a new client
8586
$success = $storage->setClientDetails(

test/Adapter/Pdo/JwtBearerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ public function testGetClientKey(object $storage)
3636
$this->assertNotNull($key);
3737
$this->assertEquals(
3838
$key,
39-
<<<'END'
40-
-----BEGIN PUBLIC KEY-----
41-
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCvfF+Cw8nzsc9Twam37SYpAW3+
42-
lRGUle/hYnd9obfBvDHKBvgb1WfGCblwjwImGL9u0rEIW2sspkwBEsGGFFBmSaqq
43-
fvEER7Yr++VIidOUHkas3cHO1TVoERO3s0THOobw0OzghPnMJL6ayelYOESwfnqR
44-
WfuEMSaWaW0G38QPzwIDAQAB
45-
-----END PUBLIC KEY-----
46-
END
39+
<<<'END_WRAP'
40+
-----BEGIN PUBLIC KEY-----
41+
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCvfF+Cw8nzsc9Twam37SYpAW3+
42+
lRGUle/hYnd9obfBvDHKBvgb1WfGCblwjwImGL9u0rEIW2sspkwBEsGGFFBmSaqq
43+
fvEER7Yr++VIidOUHkas3cHO1TVoERO3s0THOobw0OzghPnMJL6ayelYOESwfnqR
44+
WfuEMSaWaW0G38QPzwIDAQAB
45+
-----END PUBLIC KEY-----
46+
END_WRAP
4747
);
4848
}
4949
}

test/Controller/AuthControllerTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,7 @@ public function testTokenActionUsesCodeFromTokenExceptionIfPresentToCreateApiPro
413413
$oauth2Server
414414
->handleTokenRequest(Argument::type(OAuth2Request::class))
415415
->willThrow($exception);
416-
$factory = function () use ($oauth2Server): OAuth2Server {
417-
return $oauth2Server->reveal();
418-
};
416+
$factory = fn(): OAuth2Server => $oauth2Server->reveal();
419417

420418
$provider = $this->prophesize(UserIdProviderInterface::class)->reveal();
421419

@@ -447,9 +445,7 @@ public function testTokenActionUses401CodeIfTokenExceptionCodeIsInvalidWhenCreat
447445
$oauth2Server
448446
->handleTokenRequest(Argument::type(OAuth2Request::class))
449447
->willThrow($exception);
450-
$factory = function () use ($oauth2Server): OAuth2Server {
451-
return $oauth2Server->reveal();
452-
};
448+
$factory = fn(): OAuth2Server => $oauth2Server->reveal();
453449

454450
$provider = $this->prophesize(UserIdProviderInterface::class)->reveal();
455451

test/Factory/MongoAdapterFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function testInstanceCreatedWithMongoDbInServiceLocator(): void
8383
],
8484
],
8585
]);
86-
$mock = $this->getMockBuilder(MongoDB::class, [], [], '', false)
86+
$mock = $this->getMockBuilder(MongoDB::class)
8787
->disableOriginalConstructor()
8888
->getMock();
8989
$this->services->setService('testdb', $mock);
@@ -104,7 +104,7 @@ public function testCanPassAdapterConfigurationWhenCreatingInstance(): void
104104
],
105105
],
106106
]);
107-
$mock = $this->getMockBuilder(MongoDB::class, [], [], '', false)
107+
$mock = $this->getMockBuilder(MongoDB::class)
108108
->disableOriginalConstructor()
109109
->getMock();
110110
$this->services->setService('testdb', $mock);

test/Factory/OAuth2ServerFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testExceptionThrownOnMissingStorageClass(): void
6363

6464
$this->services->setService('config', []);
6565
$smFactory = $this->factory;
66-
$factory = $smFactory($this->services, 'OAuth2Server');
66+
$factory = $smFactory($this->services);
6767

6868
$this->expectException(RuntimeException::class);
6969
$factory();

test/TestAsset/autoload_laminas_authenticationservice/global.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
),
1818
),
1919
'api-tools-oauth2' => array(
20-
'storage' => 'Laminas\ApiTools\OAuth2\Adapter\PdoAdapter',
20+
'storage' => \Laminas\ApiTools\OAuth2\Adapter\PdoAdapter::class,
2121
'db' => array(
2222
'dsn' => 'sqlite::memory:',
2323
),
@@ -37,13 +37,13 @@
3737
'service_manager' => array(
3838
'aliases' => array(
3939
'translator' => 'MvcTranslator',
40-
'Laminas\ApiTools\OAuth2\Provider\UserId' => 'Laminas\ApiTools\OAuth2\Provider\UserId\AuthenticationService',
40+
'Laminas\ApiTools\OAuth2\Provider\UserId' => \Laminas\ApiTools\OAuth2\Provider\UserId\AuthenticationService::class,
4141
),
4242
'invokables' => array(
43-
'Laminas\Authentication\AuthenticationService' => 'Laminas\Authentication\AuthenticationService',
43+
\Laminas\Authentication\AuthenticationService::class => \Laminas\Authentication\AuthenticationService::class,
4444
),
4545
'factories' => array(
46-
'Laminas\ApiTools\OAuth2\Provider\UserId\AuthenticationService' => 'Laminas\ApiTools\OAuth2\Provider\UserId\AuthenticationServiceFactory',
46+
\Laminas\ApiTools\OAuth2\Provider\UserId\AuthenticationService::class => \Laminas\ApiTools\OAuth2\Provider\UserId\AuthenticationServiceFactory::class,
4747
),
4848
),
4949
);

0 commit comments

Comments
 (0)