Skip to content

Commit

Permalink
add tolines, toarray
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Jan 4, 2025
1 parent 2726065 commit 62e9719
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

![Chevere](chevere.svg)

[![Build](https://img.shields.io/github/actions/workflow/status/chevere/http/test.yml?branch=0.4&style=flat-square)](https://github.com/chevere/http/actions)
[![Build](https://img.shields.io/github/actions/workflow/status/chevere/http/test.yml?branch=0.5&style=flat-square)](https://github.com/chevere/http/actions)
![Code size](https://img.shields.io/github/languages/code-size/chevere/http?style=flat-square)
[![Apache-2.0](https://img.shields.io/github/license/chevere/http?style=flat-square)](LICENSE)
[![PHPStan](https://img.shields.io/badge/PHPStan-level%209-blueviolet?style=flat-square)](https://phpstan.org/)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat-square&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fchevere%2Fhttp%2F0.4)](https://dashboard.stryker-mutator.io/reports/github.com/chevere/http/0.4)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat-square&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fchevere%2Fhttp%2F0.5)](https://dashboard.stryker-mutator.io/reports/github.com/chevere/http/0.5)

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=chevere_http&metric=alert_status)](https://sonarcloud.io/dashboard?id=chevere_http)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=chevere_http&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=chevere_http)
Expand Down
15 changes: 14 additions & 1 deletion src/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(Header ...$header)
/**
* @return array<string>
*/
public function toArray(): array
public function toLines(): array
{
$return = [];
foreach ($this->getIterator() as $header) {
Expand All @@ -43,6 +43,19 @@ public function toArray(): array
return $return;
}

/**
* @return array<string, string>
*/
public function toArray(): array
{
$return = [];
foreach ($this->getIterator() as $header) {
$return[$header->name] = $header->value;
}

return $return;

Check warning on line 56 in src/Headers.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 test on ubuntu-latest

Escaped Mutant for Mutator "ArrayOneItem": @@ @@ foreach ($this->getIterator() as $header) { $return[$header->name] = $header->value; } - return $return; + return count($return) > 1 ? array_slice($return, 0, 1, true) : $return; } /** * @return VectorInterface<Headers>

Check warning on line 56 in src/Headers.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 test on ubuntu-latest

Escaped Mutant for Mutator "ArrayOneItem": @@ @@ foreach ($this->getIterator() as $header) { $return[$header->name] = $header->value; } - return $return; + return count($return) > 1 ? array_slice($return, 0, 1, true) : $return; } /** * @return VectorInterface<Headers>

Check warning on line 56 in src/Headers.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 test on ubuntu-latest

Escaped Mutant for Mutator "ArrayOneItem": @@ @@ foreach ($this->getIterator() as $header) { $return[$header->name] = $header->value; } - return $return; + return count($return) > 1 ? array_slice($return, 0, 1, true) : $return; } /** * @return VectorInterface<Headers>
}

/**
* @return VectorInterface<Headers>
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testGetRequest(): void
[
$header->line,
],
$request->headers->toArray()
$request->headers->toLines()
);
}

Expand All @@ -68,7 +68,7 @@ public function testGetResponse(): void
$contentType->line,
$contentType2->line,
],
$response->headers->toArray()
$response->headers->toLines()
);
}
}
4 changes: 4 additions & 0 deletions tests/HeadersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public function testHeaders(): void
$this->assertSame([
'foo: bar',
'foo: baz',
], $headers->toLines());
$this->assertSame([
'foo' => 'bar',
'foo' => 'baz',
], $headers->toArray());
}
}

0 comments on commit 62e9719

Please sign in to comment.