8000 Merge branch '4.4' · symfony/symfony@d400aeb · GitHub
[go: up one dir, main page]

Skip to content

Commit d400aeb

Browse files
Merge branch '4.4'
* 4.4: Add return types to internal & magic methods when possible fixed CSC Add Address::fromString [DomCrawler] Added Crawler::matches(), ::closest(), ::outerHtml()
2 parents a84a7f0 + 47322db commit d400aeb
  • Tests
  • HttpKernel/Tests
  • Intl/Data/Util
  • Ldap
  • Mime
  • Process
  • PropertyAccess/Tests/Fixtures
  • Security
  • Serializer/Tests/Fixtures
  • Templating/Tests/Fixtures
  • Translation/Tests
  • Validator
  • VarDumper/Cloner
  • VarExporter/Tests
  • Some content is hidden

    Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

    77 files changed

    +414
    -131
    lines changed

    src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -205,7 +205,7 @@ private function createCollector($queries)
    205205

    206206
    class StringRepresentableClass
    207207
    {
    208-
    public function __toString()
    208+
    public function __toString(): string
    209209
    {
    210210
    return 'string representation';
    211211
    }

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeIntIdEntity.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -34,7 +34,7 @@ public function __construct($id1, $id2, $name)
    3434
    $this->name = $name;
    3535
    }
    3636

    37-
    public function __toString()
    37+
    public function __toString(): string
    3838
    {
    3939
    return $this->name;
    4040
    }

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeStringIdEntity.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -34,7 +34,7 @@ public function __construct($id1, $id2, $name)
    3434
    $this->name = $name;
    3535
    }
    3636

    37-
    public function __toString()
    37+
    public function __toString(): string
    3838
    {
    3939
    return $this->name;
    4040
    }

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/Person.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -38,7 +38,7 @@ public function __construct($id, $name)
    3838
    $this->name = $name;
    3939
    }
    4040

    41-
    public function __toString()
    41+
    public function __toString(): string
    4242
    {
    4343
    return (string) $this->name;
    4444
    }

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleAssociationToIntIdEntity.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -31,7 +31,7 @@ public function __construct(SingleIntIdNoToStringEntity $entity, $name)
    3131
    $this->name = $name;
    3232
    }
    3333

    34-
    public function __toString()
    34+
    public function __toString(): string
    3535
    {
    3636
    return (string) $this->name;
    3737
    }

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleIntIdEntity.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -33,7 +33,7 @@ public function __construct($id, $name)
    3333
    $this->name = $name;
    3434
    }
    3535

    36-
    public function __toString()
    36+
    public function __toString(): string
    3737
    {
    3838
    return (string) $this->name;
    3939
    }

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleStringCastableIdEntity.php

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -35,7 +35,7 @@ public function __construct($id, $name)
    3535
    $this->name = $name;
    3636
    }
    3737

    38-
    public function __toString()
    38+
    public function __toString(): string
    3939
    {
    4040
    return (string) $this->name;
    4141
    }
    @@ -50,7 +50,7 @@ public function __construct($id)
    5050
    $this->id = $id;
    5151
    }
    5252

    53-
    public function __toString()
    53+
    public function __toString(): string
    5454
    {
    5555
    return (string) $this->id;
    5656
    }

    src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleStringIdEntity.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -30,7 +30,7 @@ public function __construct($id, $name)
    3030
    $this->name = $name;
    3131
    }
    3232

    33-
    public function __toString()
    33+
    public function __toString(): string
    3434
    {
    3535
    return $this->name;
    3636
    }

    src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -79,7 +79,7 @@ protected function build(ContainerBuilder $container)
    7979
    $container->register('logger', NullLogger::class);
    8080
    }
    8181

    82-
    public function __sleep()
    82+
    public function __sleep(): array
    8383
    {
    8484
    return ['varDir', 'testCase', 'rootConfig', 'environment', 'debug'];
    8585
    }

    src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/ConcreteMicroKernel.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -64,7 +64,7 @@ public function getLogDir(): string
    6464
    return $this->cacheDir;
    6565
    }
    6666

    67-
    public function __sleep()
    67+
    public function __sleep(): array
    6868
    {
    6969
    throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
    7070
    }

    src/Symfony/Bundle/TwigBundle/TemplateIterator.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -40,7 +40,7 @@ public function __construct(KernelInterface $kernel, array $paths = [], string $
    4040
    }
    4141

    4242
    /**
    43-
    * {@inheritdoc}
    43+
    * @return \Traversable
    4444
    */
    4545
    public function getIterator()
    4646
    {

    src/Symfony/Component/Console/Helper/TableRows.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -23,7 +23,7 @@ public function __construct(callable $generator)
    2323
    $this->generator = $generator;
    2424
    }
    2525

    26-
    public function getIterator()
    26+
    public function getIterator(): \Traversable
    2727
    {
    2828
    $g = $this->generator;
    2929

    src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -339,7 +339,7 @@ public function testFormatAndWrap()
    339339

    340340
    class TableCell
    341341
    {
    342-
    public function __toString()
    342+
    public function __toString(): string
    343343
    {
    344344
    return '<info>some info</info>';
    345345
    }

    src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -835,7 +835,7 @@ public function __construct(array $values)
    835835
    $this->values = $values;
    836836
    }
    837837

    838-
    public function getIterator()
    838+
    public function getIterator(): \Traversable
    839839
    {
    840840
    return new \ArrayIterator($this->values);
    841841
    }

    src/Symfony/Component/Console/Tests/Logger/ConsoleLoggerTest.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -204,7 +204,7 @@ public function testContextExceptionKeyCanBeExceptionOrOtherValues()
    204204

    205205
    class DummyTest
    206206
    {
    207-
    public function __toString()
    207+
    public function __toString(): string
    208208
    {
    209209
    }
    210210
    }

    src/Symfony/Component/DependencyInjection/Argument/RewindableGenerator.php

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -28,14 +28,14 @@ public function __construct(callable $generator, $count)
    2828
    $this->count = $count;
    2929
    }
    3030

    31-
    public function getIterator()
    31+
    public function getIterator(): \Traversable
    3232
    {
    3333
    $g = $this->generator;
    3434

    3535
    return $g();
    3636
    }
    3737

    38-
    public function count()
    38+
    public function count(): int
    3939
    {
    4040
    if (\is_callable($count = $this->count)) {
    4141
    $this->count = $count();

    src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/ProjectExtension.php

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -25,17 +25,17 @@ public function load(array $configs, ContainerBuilder $configuration)
    2525
    return $configuration;
    2626
    }
    2727

    28-
    public function getXsdValidationBasePath()
    28+
    public function getXsdValidationBasePath(): string
    2929
    {
    3030
    return false;
    3131
    }
    3232

    33-
    public function getNamespace()
    33+
    public function getNamespace(): string
    3434
    {
    3535
    return 'http://www.example.com/schema/project';
    3636
    }
    3737

    38-
    public function getAlias()
    38+
    public function getAlias(): string
    3939
    {
    4040
    return 'project';
    4141
    }

    src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/ProjectWithXsdExtension.php

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -2,17 +2,17 @@
    22

    33
    class ProjectWithXsdExtension extends ProjectExtension
    44
    {
    5-
    public function getXsdValidationBasePath()
    5+
    public function getXsdValidationBasePath(): string
    66
    {
    77
    return __DIR__.'/schema';
    88
    }
    99

    10-
    public function getNamespace()
    10+
    public function getNamespace(): string
    1111
    {
    1212
    return 'http://www.example.com/schema/projectwithxsd';
    1313
    }
    1414

    15-
    public function getAlias()
    15+
    public function getAlias(): string
    1616
    {
    1717
    return 'projectwithxsd';
    1818
    }

    src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/classes.php

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -83,17 +83,17 @@ public function callPassed()
    8383

    8484
    class DummyProxyDumper implements ProxyDumper
    8585
    {
    86-
    public function isProxyCandidate(Definition $definition)
    86+
    public function isProxyCandidate(Definition $definition): bool
    8787
    {
    8888
    return $definition->isLazy();
    8989
    }
    9090

    91-
    public function getProxyFactoryCode(Definition $definition, string $id, string $factoryCode)
    91+
    public function getProxyFactoryCode(Definition $definition, string $id, string $factoryCode): string
    9292
    {
    9393
    return " // lazy factory for {$definition->getClass()}\n\n";
    9494
    }
    9595

    96-
    public function getProxyCode(Definition $definition)
    96+
    public function getProxyCode(Definition $definition): string
    9797
    {
    9898
    return "// proxy code for {$definition->getClass()}\n";
    9999
    }

    src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/createphar.php

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -11,17 +11,17 @@
    1111
    1212
    class ProjectWithXsdExtensionInPhar extends ProjectExtension
    1313
    {
    14-
    public function getXsdValidationBasePath()
    14+
    public function getXsdValidationBasePath(): string
    1515
    {
    1616
    return __DIR__.'/schema';
    1717
    }
    1818
    19-
    public function getNamespace()
    19+
    public function getNamespace(): string
    2020
    {
    2121
    return 'http://www.example.com/schema/projectwithxsdinphar';
    2222
    }
    2323
    24-
    public function getAlias()
    24+
    public function getAlias(): string
    2525
    {
    2626
    return 'projectwithxsdinphar';
    2727
    }

    src/Symfony/Component/DomCrawler/CHANGELOG.md

    Lines changed: 3 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -11,6 +11,9 @@ CHANGELOG
    1111
    -----
    1212

    1313
    * Added `Form::getName()` method.
    14+
    * Added `Crawler::matches()` method.
    15+
    * Added `Crawler::closest()` method.
    16+
    * Added `Crawler::outerHtml()` method.
    1417

    1518
    4.3.0
    1619
    -----

    src/Symfony/Component/DomCrawler/Crawler.php

    Lines changed: 55 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -412,6 +412,45 @@ public function siblings()
    412412
    return $this->createSubCrawler($this->sibling($this->getNode(0)->parentNode->firstChild));
    413413
    }
    414414

    415+
    public function matches(string $selector): bool
    416+
    {
    417+
    if (!$this->nodes) {
    418+
    return false;
    419+
    }
    420+
    421+
    $converter = $this->createCssSelectorConverter();
    422+
    $xpath = $converter->toXPath($selector, 'self::');
    423+
    424+
    return 0 !== $this->filterRelativeXPath($xpath)->count();
    425+
    }
    426+
    427+
    /**
    428+
    * Return first parents (heading toward the document root) of the Element that matches the provided selector.
    429+
    *
    430+
    * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill
    431+
    *
    432+
    * @throws \InvalidArgumentException When current node is empty
    433+
    */
    434+
    public function closest(string $selector): ?self
    435+
    {
    436+
    if (!$this->nodes) {
    437+
    throw new \InvalidArgumentException('The current node list is empty.');
    438+
    }
    439+
    440+
    $domNode = $this->getNode(0);
    441+
    442+
    while (XML_ELEMENT_NODE === $domNode->nodeType) {
    443+
    $node = $this->createSubCrawler($domNode);
    444+
    if ($node->matches($selector)) {
    445+
    return $node;
    446+
    }
    447+
    448+
    $domNode = $node->getNode(0)->parentNode;
    449+
    }
    450+
    451+
    return null;
    452+
    }
    453+
    415454
    /**
    416455
    * Returns the next siblings nodes of the current selection.
    417456
    *
    @@ -585,6 +624,22 @@ public function html($default = null)
    585624
    return $html;
    586625
    }
    587626

    627+
    public function outerHtml(): string
    628+
    {
    629+
    if (!\count($this)) {
    630+
    throw new \InvalidArgumentException('The current node list is empty.');
    631+
    }
    632+
    633+
    $node = $this->getNode(0);
    634+
    $owner = $node->ownerDocument;
    635+
    636+
    if (null !== $this->html5Parser && '<!DOCTYPE html>' === $owner->saveXML($owner->childNodes[0])) {
    637+
    $owner = $this->html5Parser;
    638+
    }
    639+
    640+
    return $owner->saveHTML($node);
    641+
    }
    642+
    588643
    /**
    589644
    * Evaluates an XPath expression.
    590645
    *

    0 commit comments

    Comments
     (0)
    0