Skip to content

Commit 10d1f55

Browse files
committed
minor #45 remove HubInterface::getName() (azjezz)
This PR was merged into the 0.5.x-dev branch. Discussion ---------- remove HubInterface::getName() not really needed. Commits ------- 947baf5 remove HubInterface::getName()
2 parents 488fb3d + 947baf5 commit 10d1f55

File tree

8 files changed

+11
-30
lines changed

8 files changed

+11
-30
lines changed

src/Authorization.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function createCookie(Request $request, array $subscribe = [], array $pub
4242
$hubInstance = $this->registry->getHub($hub);
4343
$tokenFactory = $hubInstance->getFactory();
4444
if (null === $tokenFactory) {
45-
throw new InvalidArgumentException(sprintf('The hub "%s" does not contain a token factory.', $hubInstance->getName()));
45+
throw new InvalidArgumentException(sprintf('The %s hub does not contain a token factory.', $hub ? '"'.$hub.'"' : 'default'));
4646
}
4747

4848
$token = $tokenFactory->create($subscribe, $publish, $additionalClaims);

src/Debug/TraceableHub.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ public function __construct(HubInterface $hub, Stopwatch $stopwatch)
3939
$this->stopwatch = $stopwatch;
4040
}
4141

42-
public function getName(): string
43-
{
44-
return $this->hub->getName();
45-
}
46-
4742
public function getUrl(): string
4843
{
4944
return $this->hub->getUrl();

src/Hub.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,26 @@
2626
*/
2727
final class Hub implements HubInterface
2828
{
29-
private $name;
3029
private $url;
3130
private $jwtProvider;
3231
private $jwtFactory;
3332
private $publicUrl;
3433
private $httpClient;
3534

3635
public function __construct(
37-
string $name,
3836
string $url,
3937
TokenProviderInterface $jwtProvider,
4038
TokenFactoryInterface $jwtFactory = null,
4139
string $publicUrl = null,
4240
HttpClientInterface $httpClient = null
4341
) {
44-
$this->name = $name;
4542
$this->url = $url;
4643
$this->jwtProvider = $jwtProvider;
4744
$this->publicUrl = $publicUrl;
4845
$this->jwtFactory = $jwtFactory;
4946
$this->httpClient = $httpClient ?? HttpClient::create();
5047
}
5148

52-
/**
53-
* {@inheritDoc}
54-
*/
55-
public function getName(): string
56-
{
57-
return $this->name;
58-
}
59-
6049
/**
6150
* {@inheritDoc}
6251
*/

src/HubInterface.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323
*/
2424
interface HubInterface
2525
{
26-
/**
27-
* Return the name of this Hub.
28-
*/
29-
public function getName(): string;
30-
3126
/**
3227
* Returns the Hub internal URL.
3328
*/

src/HubRegistry.php

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

1414
namespace Symfony\Component\Mercure;
1515

16-
use Psr\Container\ContainerInterface;
1716
use Symfony\Component\Mercure\Exception\InvalidArgumentException;
1817

1918
final class HubRegistry
@@ -24,15 +23,18 @@ final class HubRegistry
2423
/**
2524
* @param array<string, HubInterface> $hubs An array of hub instances, where the keys are the names
2625
*/
27-
public function __construct(string $defaultHub, array $hubs)
26+
public function __construct(HubInterface $defaultHub, array $hubs)
2827
{
2928
$this->defaultHub = $defaultHub;
3029
$this->hubs = $hubs;
3130
}
3231

3332
public function getHub(string $name = null): HubInterface
3433
{
35-
$name = $name ?? $this->defaultHub;
34+
if (null === $name) {
35+
return $this->defaultHub;
36+
}
37+
3638
if (!isset($this->hubs[$name])) {
3739
throw new InvalidArgumentException('Invalid hub name provided.');
3840
}

src/Publisher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ final class Publisher implements PublisherInterface
3636
private $httpClient;
3737

3838
/**
39-
* @param (callable(Update $update):string)|TokenProviderInterface $jwtProvider
39+
* @param TokenProviderInterface|callable(Update $update):string $jwtProvider
4040
*/
4141
public function __construct(string $hubUrl, $jwtProvider, HttpClientInterface $httpClient = null)
4242
{

tests/HubTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testPublish()
4545
});
4646

4747
$provider = new StaticTokenProvider(self::JWT);
48-
$hub = new Hub('default', self::URL, $provider, null, null, $httpClient);
48+
$hub = new Hub(self::URL, $provider, null, null, $httpClient);
4949
$id = $hub->publish(new Update(
5050
'https://demo.mercure.rocks/demo/books/1.jsonld',
5151
'Hi from Symfony!',
@@ -70,7 +70,7 @@ public function testNetworkIssue()
7070
});
7171

7272
$provider = new StaticTokenProvider(self::JWT);
73-
$hub = new Hub('default', self::URL, $provider, null, null, $httpClient);
73+
$hub = new Hub(self::URL, $provider, null, null, $httpClient);
7474

7575
$this->expectException(RuntimeException::class);
7676
$this->expectExceptionMessage('Failed to send an update.');
@@ -91,7 +91,7 @@ public function testInvalidJwt()
9191
$this->expectExceptionMessage('The provided JWT is not valid');
9292

9393
$provider = new StaticTokenProvider("invalid\r\njwt");
94-
$hub = new Hub('default', self::URL, $provider, null, null);
94+
$hub = new Hub(self::URL, $provider, null, null);
9595

9696
$hub->publish(new Update('https://demo.mercure.rocks/demo/books/1.jsonld', 'Hi from Symfony!'));
9797
}

tests/Messenger/UpdateHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testInvoke()
4242
});
4343

4444
$provider = new StaticTokenProvider(self::JWT);
45-
$hub = new Hub('default', self::URL, $provider, null, null, $httpClient);
45+
$hub = new Hub(self::URL, $provider, null, null, $httpClient);
4646
$handler = new UpdateHandler($hub);
4747

4848
$handler(new Update(

0 commit comments

Comments
 (0)