8000 [Templating] Added type-hints to all classes. · symfony/symfony@5626830 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5626830

Browse files
committed
[Templating] Added type-hints to all classes.
1 parent b057243 commit 5626830

13 files changed

+35
-80
lines changed

src/Symfony/Component/Templating/Helper/Helper.php

Lines changed: 1 addition & 3 deletions
D7AE
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ abstract class Helper implements HelperInterface
2525

2626
/**
2727
* Sets the default charset.
28-
*
29-
* @param string $charset The charset
3028
*/
31-
public function setCharset($charset)
29+
public function setCharset(string $charset)
3230
{
3331
$this->charset = $charset;
3432
}

src/Symfony/Component/Templating/Helper/HelperInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ public function getName();
2727

2828
/**
2929
* Sets the default charset.
30-
*
31-
* @param string $charset The charset
3230
*/
33-
public function setCharset($charset);
31+
public function setCharset(string $charset);
3432

3533
/**
3634
* Gets the default charset.

src/Symfony/Component/Templating/Helper/SlotsHelper.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ class SlotsHelper extends Helper
2727
* This method starts an output buffer that will be
2828
* closed when the stop() method is called.
2929
*
30-
* @param string $name The slot name
31-
*
3230
* @throws \InvalidArgumentException if a slot with the same name is already started
3331
*/
34-
public function start($name)
32+
public function start(string $name)
3533
{
3634
if (\in_array($name, $this->openSlots)) {
3735
throw new \InvalidArgumentException(sprintf('A slot named "%s" is already started.', $name));
@@ -63,48 +61,41 @@ public function stop()
6361
/**
6462
* Returns true if the slot exists.
6563
*
66-
* @param string $name The slot name
67-
*
6864
* @return bool
6965
*/
70-
public function has($name)
66+
public function has(string $name)
7167
{
7268
return isset($this->slots[$name]);
7369
}
7470

7571
/**
7672
* Gets the slot value.
7773
*
78-
* @param string $name The slot name
7974
* @param bool|string $default The default slot content
8075
*
8176
* @return string The slot content
8277
*/
83-
public function get($name, $default = false)
78+
public function get(string $name, $default = false)
8479
{
8580
return isset($this->slots[$name]) ? $this->slots[$name] : $default;
8681
}
8782

8883
/**
8984
* Sets a slot value.
90-
*
91-
* @param string $name The slot name
92-
* @param string $content The slot content
9385
*/
94-
public function set($name, $content)
86+
public function set(string $name, string $content)
9587
{
9688
$this->slots[$name] = $content;
9789
}
9890

9991
/**
10092
* Outputs a slot.
10193
*
102-
* @param string $name The slot name
10394
* @param bool|string $default The default slot content
10495
*
10596
* @return bool true if the slot is defined or if a default content has been provided, false otherwise
10697
*/
107-
public function output($name, $default = false)
98+
public function output(string $name, $default = false)
10899
{
109100
if (!isset($this->slots[$name])) {
110101
if (false !== $default) {

src/Symfony/Component/Templating/Loader/CacheLoader.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,11 @@ public function load(TemplateReferenceInterface $template)
8181
/**
8282
* Returns true if the template is still fresh.
8383
*
84-
* @param TemplateReferenceInterface $template A template
85-
* @param int $time The last modification time of the cached template (timestamp)
84+
* @param int $time The last modification time of the cached template (timestamp)
8685
*
8786
* @return bool
8887
*/
89-
public function isFresh(TemplateReferenceInterface $template, $time)
88+
public function isFresh(TemplateReferenceInterface $template, int $time)
9089
{
9190
return $this->loader->isFresh($template, $time);
9291
}

src/Symfony/Component/Templating/Loader/ChainLoader.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,11 @@ public function load(TemplateReferenceInterface $template)
6060
/**
6161
* Returns true if the template is still fresh.
6262
*
63-
* @param TemplateReferenceInterface $template A template
64-
* @param int $time The last modification time of the cached template (timestamp)
63+
* @param int $time The last modification time of the cached template (timestamp)
6564
*
6665
* @return bool
6766
*/
68-
public function isFresh(TemplateReferenceInterface $template, $time)
67+
public function isFresh(TemplateReferenceInterface $template, int $time)
6968
{
7069
foreach ($this->loaders as $loader) {
7170
return $loader->isFresh($template, $time);

src/Symfony/Component/Templating/Loader/FilesystemLoader.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@ public function load(TemplateReferenceInterface $template)
7878
/**
7979
* Returns true if the template is still fresh.
8080
*
81-
* @param TemplateReferenceInterface $template A template
82-
* @param int $time The last modification time of the cached template (timestamp)
81+
* @param int $time The last modification time of the cached template (timestamp)
8382
*
8483
* @return bool true if the template is still fresh, false otherwise
8584
*/
86-
public function isFresh(TemplateReferenceInterface $template, $time)
85+
public function isFresh(TemplateReferenceInterface $template, int $time)
8786
{
8887
if (false === $storage = $this->load($template)) {
8988
return false;
@@ -95,11 +94,9 @@ public function isFresh(TemplateReferenceInterface $template, $time)
9594
/**
9695
* Returns true if the file is an existing absolute path.
9796
*
98-
* @param string $file A path
99-
*
10097
* @return bool true if the path exists and is absolute, false otherwise
10198
*/
102-
protected static function isAbsolutePath($file)
99+
protected static function isAbsolutePath(string $file)
103100
{
104101
if ('/' == $file[0] || '\\' == $file[0]
105102
|| (\strlen($file) > 3 && ctype_alpha($file[0])

src/Symfony/Component/Templating/Loader/LoaderInterface.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ public function load(TemplateReferenceInterface $template);
3131
/**
3232
* Returns true if the template is still fresh.
3333
*
34-
* @param TemplateReferenceInterface $template A template
35-
* @param int $time The last modification time of the cached template (timestamp)
34+
* @param int $time The last modification time of the cached template (timestamp)
3635
*
3736
* @return bool
3837
*/
39-
public function isFresh(TemplateReferenceInterface $template, $time);
38+
public function isFresh(TemplateReferenceInterface $template, int $time);
4039
}

src/Symfony/Component/Templating/PhpEngine.php

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess
4343
private $evalParameters;
4444

4545
/**
46-
* @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
47-
* @param LoaderInterface $loader A loader instance
48-
* @param HelperInterface[] $helpers An array of helper instances
46+
* @param HelperInterface[] $helpers An array of helper instances
4947
*/
5048
public function __construct(TemplateNameParserInterface $parser, LoaderInterface $loader, array $helpers = [])
5149
{
@@ -120,9 +118,6 @@ public function supports($name)
120118
/**
121119
* Evaluates a template.
122120
*
123-
* @param Storage $template The template to render
124-
* @param array $parameters An array of parameters to pass to the template
125-
*
126121
* @return string|false The evaluated template, or false if the engine is unable to render the template
127122
*
128123
* @throws \InvalidArgumentException
@@ -241,11 +236,8 @@ public function setHelpers(array $helpers)
241236

242237
/**
243238
* Sets a helper.
244-
*
245-
* @param HelperInterface $helper The helper instance
246-
* @param string $alias An alias
247239
*/
248-
public function set(HelperInterface $helper, $alias = null)
240+
public function set(HelperInterface $helper, string $alias = null)
249241
{
250242
$this->helpers[$helper->getName()] = $helper;
251243
if (null !== $alias) {
@@ -258,25 +250,21 @@ public function set(HelperInterface $helper, $alias = null)
258250
/**
259251
* Returns true if the helper if defined.
260252
*
261-
* @param string $name The helper name
262-
*
263253
* @return bool true if the helper is defined, false otherwise
264254
*/
265-
public function has($name)
255+
public function has(string $name)
266256
{
267257
return isset($this->helpers[$name]);
268258
}
269259

270260
/**
271261
* Gets a helper value.
272262
*
273-
* @param string $name The helper name
274-
*
275263
* @return HelperInterface The helper instance
276264
*
277265
* @throws \InvalidArgumentException if the helper is not defined
278266
*/
279-
public function get($name)
267+
public function get(string $name)
280268
{
281269
if (!isset($this->helpers[$name])) {
282270
throw new \InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name));
@@ -290,20 +278,19 @@ public function get($name)
290278
*
291279
* @param string $template The decorator logical name
292280
*/
293-
public function extend($template)
281+
public function extend(string $template)
294282
{
295283
$this->parents[$this->current] = $template;
296284
}
297285

298286
/**
299287
* Escapes a string by using the current charset.
300288
*
301-
* @param mixed $value A variable to escape
302-
* @param string $context The context name
289+
* @param mixed $value A variable to escape
303290
*
304291
* @return string The escaped value
305292
*/
306-
public function escape($value, $context = 'html')
293+
public function escape($value, string $context = 'html')
307294
{
308295
if (is_numeric($value)) {
309296
return $value;
@@ -324,10 +311,8 @@ public function escape($value, $context = 'html')
324311

325312
/**
326313
* Sets the charset to use.
327-
*
328-
* @param string $charset The charset
329314
*/
330-
public function setCharset($charset)
315+
public function setCharset(string $charset)
331316
{
332317
if ('UTF8' === $charset = strtoupper($charset)) {
333318
$charset = 'UTF-8'; // iconv on Windows requires "UTF-8" instead of "UTF8"
@@ -351,11 +336,8 @@ public function getCharset()
351336

352337
/**
353338
* Adds an escaper for the given context.
354-
*
355-
* @param string $context The escaper context (html, js, ...)
356-
* @param callable $escaper A PHP callable
357339
*/
358-
public function setEscaper($context, callable $escaper)
340+
public function setEscaper(string $context, callable $escaper)
359341
{
360342
$this->escapers[$context] = $escaper;
361343
self::$escaperCache[$context] = [];
@@ -364,13 +346,11 @@ public function setEscaper($context, callable $escaper)
364346
/**
365347
* Gets an escaper for a given context.
366348
*
367-
* @param string $context The context name
368-
*
369349
* @return callable A PHP callable
370350
*
371351
* @throws \InvalidArgumentException
372352
*/
373-
public function getEscaper($context)
353+
public function getEscaper(string $context)
374354
{
375355
if (!isset($this->escapers[$context])) {
376356
throw new \InvalidArgumentException(sprintf('No registered escaper for context "%s".', $context));
@@ -380,10 +360,9 @@ public function getEscaper($context)
380360
}
381361

382362
/**
383-
* @param string $name
384-
* @param mixed $value
363+
* @param mixed $value
385364
*/
386-
public function addGlobal($name, $value)
365+
public function addGlobal(string $name, $value)
387366
{
388367
$this->globals[$name] = $value;
389368
}

src/Symfony/Component/Templating/TemplateReference.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __toString()
3939
/**
4040
* {@inheritdoc}
4141
*/
42-
public function set($name, $value)
42+
public function set(string $name, string $value)
4343
{
4444
if (\array_key_exists($name, $this->parameters)) {
4545
$this->parameters[$name] = $value;
@@ -53,7 +53,7 @@ public function set($name, $value)
5353
/**
5454
* {@inheritdoc}
5555
*/
56-
public function get($name)
56+
public function get(string $name)
5757
{
5858
if (\array_key_exists($name, $this->parameters)) {
5959
return $this->parameters[$name];

src/Symfony/Component/Templating/TemplateReferenceInterface.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,20 @@ public function all();
2828
/**
2929
* Sets a template parameter.
3030
*
31-
* @param string $name The parameter name
32-
* @param string $value The parameter value
33-
*
3431
* @return $this
3532
*
3633
* @throws \InvalidArgumentException if the parameter name is not supported
3734
*/
38-
public function set($name, $value);
35+
public function set(string $name, string $value);
3936

4037
/**
4138
* Gets a template parameter.
4239
*
43-
* @param string $name The parameter name
44-
*
4540
* @return string The parameter value
4641
*
4742
* @throws \InvalidArgumentException if the parameter name is not supported
4843
*/
49-
public function get($name);
44+
public function get(string $name);
5045

5146
/**
5247
* Returns the path to the template.

src/Symfony/Component/Templating/Tests/Loader/CacheLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function load(TemplateReferenceInterface $template)
8787
return false;
8888
}
8989

90-
public function isFresh(TemplateReferenceInterface $template, $time)
90+
public function isFresh(TemplateReferenceInterface $template, int $time)
9191
{
9292
return false;
9393
}

src/Symfony/Component/Templating/Tests/Loader/LoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getDebugger()
4242
return $this->debugger;
4343
}
4444

45-
public function isFresh(TemplateReferenceInterface $template, $time)
45+
public function isFresh(TemplateReferenceInterface $template, int $time)
4646
{
4747
return false;
4848
}

src/Symfony/Component/Templating/Tests/PhpEngineTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public function load(TemplateReferenceInterface $template)
219219
return false;
220220
}
221221

222-
public function isFresh(TemplateReferenceInterface $template, $time)
222+
public function isFresh(TemplateReferenceInterface $template, int $time)
223223
{
224224
return false;
225225
}

0 commit comments

Comments
 (0)
0