Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit 17fd9dd

Browse files
authored
Use more strict code (comparisions, assertions, typehints) (#35)
* Use strict comparisions * Add missing void return-type * Add strict-type for argument in HeadersConstraint * Use strict assertions in tests
1 parent d9b096a commit 17fd9dd

File tree

5 files changed

+7
-10
lines changed

5 files changed

+7
-10
lines changed

src/PhpUnit/HeadersConstraint.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,9 @@ private static function normalizeJsonSchema($schema): stdClass
8484
* but OpenAPI allow scalar values. So if scalar value expected,
8585
* we try to cast array to scalar, using first element.
8686
*
87-
* @param array $value
88-
* @param string $type
89-
*
90-
* @return array
87+
* @return mixed
9188
*/
92-
private static function normalizeHeaderValue(array $value, $type)
89+
private static function normalizeHeaderValue(array $value, string $type)
9390
{
9491
if ($type !== 'array') {
9592
$value = empty($value) ? null : reset($value);

src/PhpUnit/MethodsAllowedConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(array $allowedMethods)
2828
protected function matches($other): bool
2929
{
3030
if (is_string($other)) {
31-
return in_array(mb_strtoupper($other), $this->allowedMethods);
31+
return in_array(mb_strtoupper($other), $this->allowedMethods, true);
3232
}
3333

3434
return empty(array_diff($this->allowedMethods, array_map('mb_strtoupper', $other)));

src/PhpUnit/UriConstraint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct(
4949
$this->validator = new Validator('undefined');
5050
}
5151

52-
private function assertPathSegment(string $expectedSegment, string $actualSegment)
52+
private function assertPathSegment(string $expectedSegment, string $actualSegment): void
5353
{
5454
if ($actualSegment !== $expectedSegment) {
5555
$this->errors[] = [
@@ -59,7 +59,7 @@ private function assertPathSegment(string $expectedSegment, string $actualSegmen
5959
}
6060
}
6161

62-
private function assertPathParam(string $expectedSegment, string $actualSegment)
62+
private function assertPathParam(string $expectedSegment, string $actualSegment): void
6363
{
6464
$pathParamSchema = $this->pathParameters[mb_substr($expectedSegment, 1, -1)];
6565

tests/PhpUnit/MethodsAllowedConstraintTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MethodsAllowedConstraintTest extends TestCase
1818
/** @var MethodsAllowedConstraint */
1919
private $constraint;
2020

21-
protected function setUp()
21+
protected function setUp(): void
2222
{
2323
parent::setUp();
2424
$this->constraint = new MethodsAllowedConstraint(['OPTIONS', 'HEAD', 'GET']);

tests/SchemaTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function failOnLoadUnsupportedVersion(): void
4343
*/
4444
public function howToUseSwagger(Schema $schema): void
4545
{
46-
$this->assertEquals(['https://api.example.com/v1'], $schema->getServers());
46+
$this->assertSame(['https://api.example.com/v1'], $schema->getServers());
4747

4848
$definitions = $schema->getDefinitionNames();
4949
$this->assertGreaterThan(0, count($definitions));

0 commit comments

Comments
 (0)