Skip to content

Commit e2cd7ab

Browse files
committed
Merge branch 'php8' PR #83
* php8: improved types for phpstan PHP8 support
2 parents fa7ec08 + 1be17d6 commit e2cd7ab

12 files changed

+81
-19
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
/node_modules
55

66
/.php_cs.cache
7+
8+
php-cs-fixer.phar

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ matrix:
2424
- php: '7.4'
2525
env: YAML=^5.0
2626
- php: nightly
27-
env: YAML=~4.3.0
27+
env: YAML=~4.4.0
2828
# windows tests
2929
# https://travis-ci.community/t/where-to-contribute-php-support-for-windows/304
3030
- os: windows
@@ -57,6 +57,6 @@ script:
5757
- make lint
5858
- make stan
5959
- make test
60-
- if [[ $TRAVIS_PHP_VERSION = "7.3" || $TRAVIS_PHP_VERSION = "nightly" ]]; then true; else make check-style; fi
60+
- make check-style
6161
- make coverage
6262

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ endif
88

99
all:
1010

11-
check-style:
12-
vendor/bin/php-cs-fixer fix src/ --diff --dry-run
11+
check-style: php-cs-fixer.phar
12+
PHP_CS_FIXER_IGNORE_ENV=1 ./php-cs-fixer.phar fix src/ --diff --dry-run
1313

1414
fix-style:
1515
vendor/bin/indent --tabs composer.json
@@ -42,6 +42,8 @@ schemas/openapi-v3.0.json: vendor/oai/openapi-specification/schemas/v3.0/schema.
4242
schemas/openapi-v3.0.yaml: vendor/oai/openapi-specification/schemas/v3.0/schema.yaml
4343
cp $< $@
4444

45+
php-cs-fixer.phar:
46+
wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.16.7/php-cs-fixer.phar && chmod +x php-cs-fixer.phar
4547

4648
# find spec classes that are not mentioned in tests with @covers yet
4749
coverage: .php-openapi-covA .php-openapi-covB

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
},
2626
"require-dev": {
2727
"cebe/indent": "*",
28-
"friendsofphp/php-cs-fixer": "~2.16.1",
29-
"phpunit/phpunit": "^6.5",
28+
"phpunit/phpunit": "^6.5 || ^7.5 || ^8.5 || ^9.4",
3029

3130
"oai/openapi-specification": "3.0.2",
3231
"mermade/openapi3-examples": "1.0.0",

src/Reader.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ public static function readFromJsonFile(string $fileName, string $baseType = Ope
8585
if (is_string($resolveReferences)) {
8686
$context->mode = $resolveReferences;
8787
}
88-
$spec->setDocumentContext($spec, new JsonPointer(''));
88+
if ($spec instanceof DocumentContextInterface) {
89+
$spec->setDocumentContext($spec, new JsonPointer(''));
90+
}
8991
$spec->resolveReferences();
9092
}
9193
return $spec;
@@ -126,7 +128,9 @@ public static function readFromYamlFile(string $fileName, string $baseType = Ope
126128
if (is_string($resolveReferences)) {
127129
$context->mode = $resolveReferences;
128130
}
129-
$spec->setDocumentContext($spec, new JsonPointer(''));
131+
if ($spec instanceof DocumentContextInterface) {
132+
$spec->setDocumentContext($spec, new JsonPointer(''));
133+
}
130134
$spec->resolveReferences();
131135
}
132136
return $spec;

src/ReferenceContext.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public function fetchReferencedFile($uri)
238238
* @param JsonPointer $pointer
239239
* @param array $data
240240
* @param string|null $toType
241-
* @return SpecObjectInterface|array
241+
* @return SpecObjectInterface|array|null
242242
*/
243243
public function resolveReferenceData($uri, JsonPointer $pointer, $data, $toType)
244244
{
@@ -255,7 +255,6 @@ public function resolveReferenceData($uri, JsonPointer $pointer, $data, $toType)
255255

256256
// transitive reference
257257
if (isset($referencedData['$ref'])) {
258-
/** @var Reference $referencedObject */
259258
return new Reference($referencedData, $toType);
260259
} else {
261260
/** @var SpecObjectInterface|array $referencedObject */

src/spec/Callback.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,25 @@
2222
*/
2323
class Callback implements SpecObjectInterface, DocumentContextInterface
2424
{
25+
/**
26+
* @var string|null
27+
*/
2528
private $_url;
29+
/**
30+
* @var PathItem
31+
*/
2632
private $_pathItem;
27-
33+
/**
34+
* @var array
35+
*/
2836
private $_errors = [];
29-
37+
/**
38+
* @var SpecObjectInterface|null
39+
*/
3040
private $_baseDocument;
41+
/**
42+
* @var JsonPointer|null
43+
*/
3144
private $_jsonPointer;
3245

3346

src/spec/Paths.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,17 @@ class Paths implements SpecObjectInterface, DocumentContextInterface, ArrayAcces
3434
* @var (PathItem|null)[]
3535
*/
3636
private $_paths = [];
37-
37+
/**
38+
* @var array
39+
*/
3840
private $_errors = [];
39-
41+
/**
42+
* @var SpecObjectInterface|null
43+
*/
4044
private $_baseDocument;
45+
/**
46+
* @var JsonPointer|null
47+
*/
4148
private $_jsonPointer;
4249

4350

src/spec/Reference.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,33 @@
2929
*/
3030
class Reference implements SpecObjectInterface, DocumentContextInterface
3131
{
32+
/**
33+
* @var string
34+
*/
3235
private $_to;
36+
/**
37+
* @var string
38+
*/
3339
private $_ref;
40+
/**
41+
* @var JsonReference|null
42+
*/
3443
private $_jsonReference;
44+
/**
45+
* @var ReferenceContext
46+
*/
3547
private $_context;
36-
48+
/**
49+
* @var SpecObjectInterface|null
50+
*/
3751
private $_baseDocument;
52+
/**
53+
* @var JsonPointer|null
54+
*/
3855
private $_jsonPointer;
39-
56+
/**
57+
* @var array
58+
*/
4059
private $_errors = [];
4160

4261
/**

tests/ReaderTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,13 @@ public function testSymfonyYamlBugHunt()
112112
$openapi = \cebe\openapi\Reader::readFromYamlFile($openApiFile);
113113

114114
$inlineYamlExample = $openapi->paths['/']->get->responses['200']->content['application/json']->example;
115-
$this->assertInternalType('array', $inlineYamlExample);
115+
116+
if (method_exists($this, 'assertIsArray')) {
117+
$this->assertIsArray($inlineYamlExample);
118+
} else {
119+
$this->assertInternalType('array', $inlineYamlExample);
120+
}
121+
116122
$expectedArray = json_decode(<<<JSON
117123
{
118124
"total": 2,

tests/spec/MediaTypeTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ public function testRead()
4646
$this->assertTrue($result);
4747

4848
$this->assertInstanceOf(Reference::class, $mediaType->schema);
49-
$this->assertInternalType('array', $mediaType->examples);
49+
50+
if (method_exists($this, 'assertIsArray')) {
51+
$this->assertIsArray($mediaType->examples);
52+
} else {
53+
$this->assertInternalType('array', $mediaType->examples);
54+
}
55+
5056
$this->assertCount(3, $mediaType->examples);
5157
$this->assertArrayHasKey('cat', $mediaType->examples);
5258
$this->assertArrayHasKey('dog', $mediaType->examples);

tests/spec/OpenApiTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ public function testReadPetStore()
5252

5353

5454
// servers
55-
$this->assertInternalType('array', $openapi->servers);
55+
if (method_exists($this, 'assertIsArray')) {
56+
$this->assertIsArray($openapi->servers);
57+
} else {
58+
$this->assertInternalType('array', $openapi->servers);
59+
}
60+
5661
$this->assertCount(1, $openapi->servers);
5762
foreach ($openapi->servers as $server) {
5863
$this->assertInstanceOf(\cebe\openapi\spec\Server::class, $server);

0 commit comments

Comments
 (0)