Skip to content

Commit

Permalink
Merge pull request #272 from sabre-io/staabm-patch-1
Browse files Browse the repository at this point in the history
More precise `parseClarkNotation` return type
  • Loading branch information
phil-davis authored Apr 18, 2024
2 parents 43cea9f + 51eb072 commit 3e499be
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
3 changes: 1 addition & 2 deletions lib/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ public function write(string $rootElementName, $value, ?string $contextUri = nul
public function mapValueObject(string $elementName, string $className): void
{
list($namespace) = self::parseClarkNotation($elementName);
$namespace = $namespace ?? '';

$this->elementMap[$elementName] = function (Reader $reader) use ($className, $namespace) {
return \Sabre\Xml\Deserializer\valueObject($reader, $className, $namespace);
Expand Down Expand Up @@ -282,7 +281,7 @@ public function writeValueObject(object $object, ?string $contextUri = null): st
*
* If the string was invalid, it will throw an InvalidArgumentException.
*
* @return array{string|null, string}
* @return array{string, string}
*
* @throws \InvalidArgumentException
*/
Expand Down
2 changes: 0 additions & 2 deletions lib/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public function startElement($name): bool
if ('{' === $name[0]) {
list($namespace, $localName) =
Service::parseClarkNotation($name);
$namespace = $namespace ?? '';

if (array_key_exists($namespace, $this->namespaceMap)) {
$result = $this->startElementNS(
Expand Down Expand Up @@ -239,7 +238,6 @@ public function writeAttribute($name, $value): bool
$localName
) = Service::parseClarkNotation($name);

$namespace = $namespace ?? '';
if (array_key_exists($namespace, $this->namespaceMap)) {
// It's an attribute with a namespace we know
return $this->writeAttribute(
Expand Down
23 changes: 18 additions & 5 deletions tests/Sabre/Xml/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,14 @@ public function testWriteVoNotFound(): void
$service->writeValueObject(new \stdClass());
}

public function testParseClarkNotation(): void
/**
* @param array<string> $expected
*
* @dataProvider provideParseClarkNotationInput
*/
public function testParseClarkNotation(string $clark, array $expected): void
{
self::assertEquals([
'http://sabredav.org/ns',
'elem',
], Service::parseClarkNotation('{http://sabredav.org/ns}elem'));
self::assertEquals($expected, Service::parseClarkNotation($clark));
}

public function testParseClarkNotationFail(): void
Expand All @@ -366,6 +368,17 @@ public function testParseClarkNotationFail(): void
Service::parseClarkNotation('http://sabredav.org/ns}elem');
}

/**
* @return array<int, list{string, array<string>}>
*/
public function provideParseClarkNotationInput(): iterable
{
return [
['{http://sabredav.org/ns}elem', ['http://sabredav.org/ns', 'elem']],
['{}elem', ['', 'elem']],
];
}

/**
* @return array<int, array<int, string|resource|false>>
*/
Expand Down

0 comments on commit 3e499be

Please sign in to comment.