Skip to content

Commit

Permalink
minor #33294 Add return types to internal & magic methods when possib…
Browse files Browse the repository at this point in the history
…le (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

Add return types to internal & magic methods when possible

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #33236 #33228
| License       | MIT
| Doc PR        | -

Commits
-------

962dcfe Add return types to internal & magic methods when possible
  • Loading branch information
nicolas-grekas committed Aug 22, 2019
2 parents 3051c59 + 962dcfe commit 47322db
Show file tree
Hide file tree
Showing 80 changed files with 171 additions and 138 deletions.
Expand Up @@ -205,7 +205,7 @@ private function createCollector($queries)

class StringRepresentableClass
{
public function __toString()
public function __toString(): string
{
return 'string representation';
}
Expand Down
Expand Up @@ -34,7 +34,7 @@ public function __construct($id1, $id2, $name)
$this->name = $name;
}

public function __toString()
public function __toString(): string
{
return $this->name;
}
Expand Down
Expand Up @@ -34,7 +34,7 @@ public function __construct($id1, $id2, $name)
$this->name = $name;
}

public function __toString()
public function __toString(): string
{
return $this->name;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/Tests/Fixtures/Person.php
Expand Up @@ -38,7 +38,7 @@ public function __construct($id, $name)
$this->name = $name;
}

public function __toString()
public function __toString(): string
{
return (string) $this->name;
}
Expand Down
Expand Up @@ -31,7 +31,7 @@ public function __construct(SingleIntIdNoToStringEntity $entity, $name)
$this->name = $name;
}

public function __toString()
public function __toString(): string
{
return (string) $this->name;
}
Expand Down
Expand Up @@ -33,7 +33,7 @@ public function __construct($id, $name)
$this->name = $name;
}

public function __toString()
public function __toString(): string
{
return (string) $this->name;
}
Expand Down
Expand Up @@ -35,7 +35,7 @@ public function __construct($id, $name)
$this->name = $name;
}

public function __toString()
public function __toString(): string
{
return (string) $this->name;
}
Expand All @@ -50,7 +50,7 @@ public function __construct($id)
$this->id = $id;
}

public function __toString()
public function __toString(): string
{
return (string) $this->id;
}
Expand Down
Expand Up @@ -30,7 +30,7 @@ public function __construct($id, $name)
$this->name = $name;
}

public function __toString()
public function __toString(): string
{
return $this->name;
}
Expand Down
Expand Up @@ -79,7 +79,7 @@ protected function build(ContainerBuilder $container)
$container->register('logger', NullLogger::class);
}

public function __sleep()
public function __sleep(): array
{
return ['varDir', 'testCase', 'rootConfig', 'environment', 'debug'];
}
Expand Down
Expand Up @@ -64,7 +64,7 @@ public function getLogDir(): string
return $this->cacheDir;
}

public function __sleep()
public function __sleep(): array
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/TwigBundle/TemplateIterator.php
Expand Up @@ -43,7 +43,7 @@ public function __construct(KernelInterface $kernel, string $rootDir, array $pat
}

/**
* {@inheritdoc}
* @return \Traversable
*/
public function getIterator()
{
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Config/Resource/GlobResource.php
Expand Up @@ -91,6 +91,9 @@ public function __sleep(): array
return ['prefix', 'pattern', 'recursive', 'hash', 'forExclusion', 'excludedPrefixes'];
}

/**
* @return \Traversable
*/
public function getIterator()
{
if (!file_exists($this->prefix) || (!$this->recursive && '' === $this->pattern)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Helper/TableRows.php
Expand Up @@ -23,7 +23,7 @@ public function __construct(callable $generator)
$this->generator = $generator;
}

public function getIterator()
public function getIterator(): \Traversable
{
$g = $this->generator;

Expand Down
Expand Up @@ -339,7 +339,7 @@ public function testFormatAndWrap()

class TableCell
{
public function __toString()
public function __toString(): string
{
return '<info>some info</info>';
}
Expand Down
Expand Up @@ -835,7 +835,7 @@ public function __construct(array $values)
$this->values = $values;
}

public function getIterator()
public function getIterator(): \Traversable
{
return new \ArrayIterator($this->values);
}
Expand Down
Expand Up @@ -204,7 +204,7 @@ public function testContextExceptionKeyCanBeExceptionOrOtherValues()

class DummyTest
{
public function __toString()
public function __toString(): string
{
}
}
Expand Up @@ -28,14 +28,14 @@ public function __construct(callable $generator, $count)
$this->count = $count;
}

public function getIterator()
public function getIterator(): \Traversable
{
$g = $this->generator;

return $g();
}

public function count()
public function count(): int
{
if (\is_callable($count = $this->count)) {
$this->count = $count();
Expand Down
Expand Up @@ -25,17 +25,17 @@ public function load(array $configs, ContainerBuilder $configuration)
return $configuration;
}

public function getXsdValidationBasePath()
public function getXsdValidationBasePath(): string
{
return false;
}

public function getNamespace()
public function getNamespace(): string
{
return 'http://www.example.com/schema/project';
}

public function getAlias()
public function getAlias(): string
{
return 'project';
}
Expand Down
Expand Up @@ -2,17 +2,17 @@

class ProjectWithXsdExtension extends ProjectExtension
{
public function getXsdValidationBasePath()
public function getXsdValidationBasePath(): string
{
return __DIR__.'/schema';
}

public function getNamespace()
public function getNamespace(): string
{
return 'http://www.example.com/schema/projectwithxsd';
}

public function getAlias()
public function getAlias(): string
{
return 'projectwithxsd';
}
Expand Down
Binary file not shown.
Expand Up @@ -83,17 +83,17 @@ public function callPassed()

class DummyProxyDumper implements ProxyDumper
{
public function isProxyCandidate(Definition $definition)
public function isProxyCandidate(Definition $definition): bool
{
return $definition->isLazy();
}

public function getProxyFactoryCode(Definition $definition, $id, $factoryCall = null)
public function getProxyFactoryCode(Definition $definition, $id, $factoryCall = null): string
{
return " // lazy factory for {$definition->getClass()}\n\n";
}

public function getProxyCode(Definition $definition)
public function getProxyCode(Definition $definition): string
{
return "// proxy code for {$definition->getClass()}\n";
}
Expand Down
Expand Up @@ -11,17 +11,17 @@
class ProjectWithXsdExtensionInPhar extends ProjectExtension
{
public function getXsdValidationBasePath()
public function getXsdValidationBasePath(): string
{
return __DIR__.'/schema';
}
public function getNamespace()
public function getNamespace(): string
{
return 'http://www.example.com/schema/projectwithxsdinphar';
}
public function getAlias()
public function getAlias(): string
{
return 'projectwithxsdinphar';
}
Expand Down
Expand Up @@ -68,6 +68,9 @@ public function accept()
return true;
}

/**
* @return bool
*/
public function hasChildren()
{
return $this->isRecursive && $this->iterator->hasChildren();
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Finder/Iterator/SortableIterator.php
Expand Up @@ -80,6 +80,9 @@ public function __construct(\Traversable $iterator, $sort, bool $reverseOrder =
}
}

/**
* @return \Traversable
*/
public function getIterator()
{
if (1 === $this->sort) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Finder/Tests/Iterator/Iterator.php
Expand Up @@ -33,7 +33,7 @@ public function rewind()
reset($this->values);
}

public function valid()
public function valid(): bool
{
return false !== $this->current();
}
Expand Down
Expand Up @@ -234,7 +234,7 @@ public function getData()
/**
* @internal
*/
public function __sleep()
public function __sleep(): array
{
foreach ($this->data['forms_by_hash'] as &$form) {
if (isset($form['type_class']) && !$form['type_class'] instanceof ClassStub) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/FormBuilder.php
Expand Up @@ -158,7 +158,7 @@ public function all()
}

/**
* {@inheritdoc}
* @return int
*/
public function count()
{
Expand Down
Expand Up @@ -860,7 +860,7 @@ public function __construct($property)
$this->property = $property;
}

public function __toString()
public function __toString(): string
{
return $this->property;
}
Expand Down
Expand Up @@ -24,7 +24,7 @@ public function __construct(array $array = null)
$this->array = $array ?: [];
}

public function offsetExists($offset)
public function offsetExists($offset): bool
{
return \array_key_exists($offset, $this->array);
}
Expand All @@ -48,12 +48,12 @@ public function offsetUnset($offset)
unset($this->array[$offset]);
}

public function getIterator()
public function getIterator(): \Traversable
{
return new \ArrayIterator($this->array);
}

public function count()
public function count(): int
{
return \count($this->array);
}
Expand All @@ -63,7 +63,7 @@ public function __serialize(): array
return $this->array;
}

public function serialize()
public function serialize(): string
{
return serialize($this->__serialize());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/Tests/SimpleFormTest.php
Expand Up @@ -32,7 +32,7 @@ public function __construct($count)
$this->count = $count;
}

public function count()
public function count(): int
{
return $this->count;
}
Expand All @@ -47,7 +47,7 @@ public function __construct($count)
$this->iterator = new \ArrayIterator($count > 0 ? array_fill(0, $count, 'Foo') : []);
}

public function getIterator()
public function getIterator(): \Traversable
{
return $this->iterator;
}
Expand Down
Expand Up @@ -34,7 +34,7 @@ public function getChildren()
}

/**
* {@inheritdoc}
* @return bool
*/
public function hasChildren()
{
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Form/Util/OrderedHashMap.php
Expand Up @@ -99,7 +99,7 @@ public function __construct(array $elements = [])
}

/**
* {@inheritdoc}
* @return bool
*/
public function offsetExists($key)
{
Expand Down Expand Up @@ -157,15 +157,15 @@ public function offsetUnset($key)
}

/**
* {@inheritdoc}
* @return \Traversable
*/
public function getIterator()
{
return new OrderedHashMapIterator($this->elements, $this->orderedKeys, $this->managedCursors);
}

/**
* {@inheritdoc}
* @return int
*/
public function count()
{
Expand Down

0 comments on commit 47322db

Please sign in to comment.