8000 Add parameter type declarations to contracts. · symfony/symfony@a2fcebc · GitHub
[go: up one dir, main page]

Skip to content

Commit a2fcebc

Browse files
committed
Add parameter type declarations to contracts.
1 parent 6b6562c commit a2fcebc

28 files changed

+99
-174
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
"twig/twig": "^2.10|^3",
2424
"psr/cache": "~1.0",
2525
"psr/container": "^1.0",
26+
"psr/event-dispatcher": "^1.0",
2627
"psr/link": "^1.0",
2728
"psr/log": "~1.0",
28-
"symfony/contracts": "^1.1.3|^2",
29+
"symfony/contracts": "^2",
2930
"symfony/polyfill-ctype": "~1.8",
3031
"symfony/polyfill-intl-icu": "~1.0",
3132
"symfony/polyfill-intl-idn": "^1.10",

src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubTranslator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class StubTranslator implements TranslatorInterface
1717
{
18-
public function trans($id, array $parameters = [], $domain = null, $locale = null): string
18+
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string
1919
{
2020
return '[trans]'.strtr($id, $parameters).'[/trans]';
2121
}

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^7.2.9",
20-
"symfony/translation-contracts": "^1.1|^2",
20+
"symfony/translation-contracts": "^2",
2121
"twig/twig": "^2.10|^3"
2222
},
2323
"require-dev": {

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function getNotImplementingTranslatorBagInterfaceTranslatorClassNames()
108108

109109
class TranslatorWithTranslatorBag implements TranslatorInterface
110110
{
111-
public function trans($id, array $parameters = [], $domain = null, $locale = null): string
111+
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string
112112
{
113113
}
114114
}

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"symfony/serializer": "^4.4|^5.0",
5252
"symfony/stopwatch": "^4.4|^5.0",
5353
"symfony/translation": "^5.0",
54+
"symfony/translation-contracts": "^2",
5455
"symfony/twig-bundle": "^4.4|^5.0",
5556
"symfony/validator": "^4.4|^5.0",
5657
"symfony/var-dumper": "^4.4|^5.0",

src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Component\HttpFoundation\Request;
1919
use Symfony\Component\HttpFoundation\RequestStack;
2020
use Symfony\Component\Stopwatch\Stopwatch;
21-
use Symfony\Contracts\EventDispatcher\Event;
2221
use Symfony\Contracts\Service\ResetInterface;
2322

2423
/**
@@ -129,12 +128,8 @@ public function hasListeners(string $eventName = null)
129128
/**
130129
* {@inheritdoc}
131130
*/
132-
public function dispatch($event, string $eventName = null): object
131+
public function dispatch(object $event, string $eventName = null): object
133132
{
134-
if (!\is_object($event)) {
135-
throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an object, %s given.', EventDispatcherInterface::class, \gettype($event)));
136-
}
137-
138133
$eventName = $eventName ?? \get_class($event);
139134

140135
if (null === $this->callStack) {
@@ -143,7 +138,7 @@ public function dispatch($event, string $eventName = null): object
143138

144139
$currentRequestHash = $this->currentRequestHash = $this->requestStack && ($request = $this->requestStack->getCurrentRequest()) ? spl_object_hash($request) : '';
145140

146-
if (null !== $this->logger && ($event instanceof Event || $event instanceof StoppableEventInterface) && $event->isPropagationStopped()) {
141+
if (null !== $this->logger && $event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
147142
$this->logger->debug(sprintf('The "%s" event is already stopped. No listeners have been called.', $eventName));
148143
}
149144

src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1616
use Symfony\Component\Stopwatch\Stopwatch;
1717
use Symfony\Component\VarDumper\Caster\ClassStub;
18-
use Symfony\Contracts\EventDispatcher\Event;
1918

2019
/**
2120
* @author Fabien Potencier <fabien@symfony.com>
@@ -121,7 +120,7 @@ public function __invoke(object $event, string $eventName, EventDispatcherInterf
121120
$e->stop();
122121
}
123122

124-
if (($event instanceof Event || $event instanceof StoppableEventInterface) && $event->isPropagationStopped()) {
123+
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
125124
$this->stoppedPropagation = true;
126125
}
127126
}

src/Symfony/Component/EventDispatcher/EventDispatcher.php

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

1414
use Psr\EventDispatcher\StoppableEventInterface;
1515
use Symfony\Component\EventDispatcher\Debug\WrappedListener;
16-
use Symfony\Contracts\EventDispatcher\Event;
1716

1817
/**
1918
* The EventDispatcherInterface is the central point of Symfony's event listener system.
@@ -46,12 +45,8 @@ public function __construct()
4645
/**
4746
* {@inheritdoc}
4847
*/
49-
public function dispatch($event, string $eventName = null): object
48+
public function dispatch(object $event, string $eventName = null): object
5049
{
51-
if (!\is_object($event)) {
52-
throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an object, %s given.', EventDispatcherInterface::class, \gettype($event)));
53-
}
54-
5550
$eventName = $eventName ?? \get_class($event);
5651

5752
if (null !== $this->optimized && null !== $eventName) {
@@ -222,7 +217,7 @@ public function removeSubscriber(EventSubscriberInterface $subscriber)
222217
*/
223218
protected function callListeners(iterable $listeners, string $eventName, object $event)
224219
{
225-
$stoppable = $event instanceof Event || $event instanceof StoppableEventInterface;
220+
$stoppable = $event instanceof StoppableEventInterface;
226221

227222
foreach ($listeners as $listener) {
228223
if ($stoppable && $event->isPropagationStopped()) {

src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface EventDispatcherInterface extends ContractsEventDispatcherInterface
2525
/**
2626
* {@inheritdoc}
2727
*/
28-
public function dispatch($event, string $eventName = null): object;
28+
public function dispatch(object $event, string $eventName = null): object;
2929

3030
/**
3131
* Adds an event listener that listens on the specified events.

src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(EventDispatcherInterface $dispatcher)
2828
/**
2929
* {@inheritdoc}
3030
*/
31-
public function dispatch($event, string $eventName = null): object
31+
public function dispatch(object $event, string $eventName = null): object
3232
{
3333
return $this->dispatcher->dispatch($event, $eventName);
3434
}

src/Symfony/Component/EventDispatcher/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^7.2.9",
20-
"symfony/event-dispatcher-contracts": "^1.1|^2"
20+
"symfony/event-dispatcher-contracts": "^2"
2121
},
2222
"require-dev": {
2323
"symfony/dependency-injection": "^4.4|^5.0",
@@ -33,7 +33,7 @@
3333
},
3434
"provide": {
3535
"psr/event-dispatcher-implementation": "1.0",
36-
"symfony/event-dispatcher-implementation": "1.1"
36+
"symfony/event-dispatcher-implementation": "2.0"
3737
},
3838
"suggest": {
3939
"symfony/dependency-injection": "",

src/Symfony/Component/Form/Tests/Extension/Validator/Type/UploadValidatorExtensionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public function testPostMaxSizeTranslation()
4141

4242
class DummyTranslator implements TranslatorInterface, LocaleAwareInterface
4343
{
44-
public function trans($id, array $parameters = [], $domain = null, $locale = null): string
44+
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string
4545
{
4646
return 'translated max {{ max }}!';
4747
}
4848

49-
public function setLocale($locale)
49+
public function setLocale(string $locale)
5050
{
5151
}
5252

src/Symfony/Component/Form/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"symfony/http-kernel": "^4.4|^5.0",
3636
"symfony/security-csrf": "^4.4|^5.0",
3737
"symfony/translation": "^4.4|^5.0",
38+
"symfony/translation-contracts": "^2",
3839
"symfony/var-dumper": "^4.4|^5.0"
3940
},
4041
"conflict": {

src/Symfony/Component/Translation/DataCollectorTranslator.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public function __construct(TranslatorInterface $translator)
4747
/**
4848
* {@inheritdoc}
4949
*/
50-
public function trans($id, array $parameters = [], $domain = null, $locale = null)
50+
public function trans(?string $id, array $parameters = [], string $domain = null, string $locale = null)
5151
{
52-
$trans = $this->translator->trans($id, $parameters, $domain, $locale);
52+
$trans = $this->translator->trans($id = (string) $id, $parameters, $domain, $locale);
5353
$this->collectMessage($locale, $domain, $id, $trans, $parameters);
5454

5555
return $trans;
@@ -58,7 +58,7 @@ public function trans($id, array $parameters = [], $domain = null, $locale = nul
5858
/**
5959
* {@inheritdoc}
6060
*/
61-
public function setLocale($locale)
61+
public function setLocale(string $locale)
6262
{
6363
$this->translator->setLocale($locale);
6464
}
@@ -119,13 +119,12 @@ public function getCollectedMessages()
119119
return $this->messages;
120120
}
121121

122-
private function collectMessage(?string $locale, ?string $domain, ?string $id, string $translation, ?array $parameters = [])
122+
private function collectMessage(?string $locale, ?string $domain, string $id, string $translation, ?array $parameters = [])
123123
{
124124
if (null === $domain) {
125125
$domain = 'messages';
126126
}
127127

128-
$id = (string) $id;
129128
$catalogue = $this->translator->getCatalogue($locale);
130129
$locale = $catalogue->getLocale();
131130
if ($catalogue->defines($id, $domain)) {

src/Symfony/Component/Translation/LoggingTranslator.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public function __construct(TranslatorInterface $translator, LoggerInterface $lo
4444
/**
4545
* {@inheritdoc}
4646
*/
47-
public function trans($id, array $parameters = [], $domain = null, $locale = null)
47+
public function trans(?string $id, array $parameters = [], string $domain = null, string $locale = null)
4848
{
49-
$trans = $this->translator->trans($id, $parameters, $domain, $locale);
49+
$trans = $this->translator->trans($id = (string) $id, $parameters, $domain, $locale);
5050
$this->log($id, $domain, $locale);
5151

5252
return $trans;
@@ -55,7 +55,7 @@ public function trans($id, array $parameters = [], $domain = null, $locale = nul
5555
/**
5656
* {@inheritdoc}
5757
*/
58-
public function setLocale($locale)
58+
public function setLocale(string $locale)
5959
{
6060
$prev = $this->translator->getLocale();
6161
$this->translator->setLocale($locale);
@@ -107,13 +107,12 @@ public function __call(string $method, array $args)
107107
/**
108108
* Logs for missing translations.
109109
*/
110-
private function log(?string $id, ?string $domain, ?string $locale)
110+
private function log(string $id, ?string $domain, ?string $locale)
111111
{
112112
if (null === $domain) {
113113
$domain = 'messages';
114114
}
115115

116-
$id = (string) $id;
117116
$catalogue = $this->translator->getCatalogue($locale);
118117
if ($catalogue->defines($id, $domain)) {
119118
return;

src/Symfony/Component/Translation/Translator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function addResource(string $format, $resource, string $locale, string $d
141141
/**
142142
* {@inheritdoc}
143143
*/
144-
public function setLocale($locale)
144+
public function setLocale(string $locale)
145145
{
146146
$this->assertValidLocale($locale);
147147
$this->locale = $locale;
@@ -187,9 +187,9 @@ public function getFallbackLocales(): array
187187
/**
188188
* {@inheritdoc}
189189
*/
190-
public function trans($id, array $parameters = [], $domain = null, $locale = null)
190+
public function trans(?string $id, array $parameters = [], string $domain = null, string $locale = null)
191191
{
192-
if ('' === $id = (string) $id) {
192+
if (null === $id || '' === $id) {
193193
return '';
194194
}
195195

src/Symfony/Component/Translation/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": "^7.2.9",
2020
"symfony/polyfill-mbstring": "~1.0",
21-
"symfony/translation-contracts": "^1.1.6|^2"
21+
"symfony/translation-contracts": "^2"
2222
},
2323
"require-dev": {
2424
"symfony/config": "^4.4|^5.0",
@@ -40,7 +40,7 @@
4040
"symfony/yaml": "<4.4"
4141
},
4242
"provide": {
43-
"symfony/translation-implementation": "1.0"
43+
"symfony/translation-implementation": "2.0"
4444
},
4545
"suggest": {
4646
"symfony/config": "",

src/Symfony/Contracts/Cache/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^7.1.3",
19+
"php": "^7.2.9",
2020
"psr/cache": "^1.0"
2121
},
2222
"suggest": {
@@ -28,7 +28,7 @@
2828
"minimum-stability": "dev",
2929
"extra": {
3030
"branch-alias": {
31-
"dev-master": "1.1-dev"
31+
"dev-master": "2.0-dev"
3232
}
3333
}
3434
}

0 commit comments

Comments
 (0)
0