Skip to content

Commit ba474db

Browse files
designciseDaniyal HamidDaniyal Hamid
authored
3.5x (#3)
* 3.5: Bumped up php version to 8 + Updated test * Removed deprecated libxml_* functions + Updated media parsers and tests * Fixed HttpFactoryTest::testSkipsAndRemovesNonExistingFactory * Updated version info in readme Co-authored-by: Daniyal Hamid <danielli@daniellis-MacBook-Pro.local> Co-authored-by: Daniyal Hamid <hello@designcise.com>
1 parent 9e09402 commit ba474db

File tree

10 files changed

+15
-30
lines changed

10 files changed

+15
-30
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Install BitFrame and its required dependencies using composer:
3131
$ composer require "designcise/bitframe"
3232
```
3333

34-
Please note that BitFrame v2+ requires PHP 7.4.0 or newer.
34+
Please note that BitFrame v3+ requires PHP 8.0.0 or newer.
3535

3636
## Quickstart
3737

@@ -139,7 +139,7 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
139139

140140
### Documentation
141141

142-
Complete documentation for v2.0 will be released soon.
142+
Complete documentation for v3 will be released soon.
143143

144144
### License
145145

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=7.4",
13+
"php": ">=8.0",
1414
"ext-json": "*",
1515
"psr/container": "^1.0",
1616
"psr/http-server-middleware": "~1.0"

src/Parser/DefaultMediaParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DefaultMediaParser implements MediaParserInterface
2525
/**
2626
* {@inheritdoc}
2727
*/
28-
public function parse(string $input)
28+
public function parse(string $input): mixed
2929
{
3030
parse_str($input, $data);
3131
return $data;

src/Parser/JsonMediaParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class JsonMediaParser implements MediaParserInterface
3636
*
3737
* @throws \JsonException
3838
*/
39-
public function parse(string $input)
39+
public function parse(string $input): mixed
4040
{
4141
$result = json_decode($input, true, 512, self::OPTIONS);
4242
return ((is_array($result)) ? $result : null);

src/Parser/MediaParserInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ interface MediaParserInterface
2424
*
2525
* @return mixed
2626
*/
27-
public function parse(string $input);
27+
public function parse(string $input): mixed;
2828
}

src/Parser/MediaParserNegotiator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function add(string $type, string $parser): void
6363
/**
6464
* {@inheritdoc}
6565
*/
66-
public function parse(string $input)
66+
public function parse(string $input): mixed
6767
{
6868
return $this->getPreferredMediaParser()->parse($input);
6969
}

src/Parser/XmlMediaParser.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212

1313
namespace BitFrame\Parser;
1414

15-
use function libxml_clear_errors;
16-
use function libxml_disable_entity_loader;
17-
use function libxml_use_internal_errors;
18-
use function simplexml_load_string;
15+
use SimpleXMLElement;
1916

2017
use const LIBXML_NOCDATA;
2118

@@ -33,20 +30,8 @@ class XmlMediaParser implements MediaParserInterface
3330
/**
3431
* {@inheritdoc}
3532
*/
36-
public function parse(string $input)
33+
public function parse(string $input): ?SimpleXMLElement
3734
{
38-
$backup = libxml_disable_entity_loader(true);
39-
$backupErrors = libxml_use_internal_errors(true);
40-
$result = simplexml_load_string(
41-
$input,
42-
'SimpleXMLElement',
43-
self::OPTIONS
44-
);
45-
46-
libxml_disable_entity_loader($backup);
47-
libxml_clear_errors();
48-
libxml_use_internal_errors($backupErrors);
49-
50-
return $result ?: null;
35+
return new SimpleXMLElement($input, self::OPTIONS) ?: null;
5136
}
5237
}

test/Emitter/SapiStreamEmitterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testEmitTextResponse()
4949
public function testReturnsBodyWhenNotReadableButIsSeekable(): void
5050
{
5151
$stream = HttpFactory::createStream('Hello world!');
52-
$mockedStream = Mockery::mock($stream, StreamInterface::class)->makePartial();
52+
$mockedStream = Mockery::mock($stream, $stream::class)->makePartial();
5353
$mockedStream->shouldReceive('isSeekable')->andReturn(true);
5454
$mockedStream->shouldReceive('isReadable')->andReturn(false);
5555

test/Factory/HttpFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ public function testSkipsAndRemovesNonExistingFactory(): void
122122
$property->setAccessible(true);
123123
$property->setValue([
124124
'\Non\Existent\Factory',
125-
...$property->getValue('factoriesList'),
125+
...$property->getValue(),
126126
]);
127127

128128
HttpFactory::getFactory();
129129

130130
$propertyAfter = $reflection->getProperty('factoriesList');
131131
$propertyAfter->setAccessible(true);
132-
$activeFactoriesList = $propertyAfter->getValue('factoriesList');
132+
$activeFactoriesList = $propertyAfter->getValue();
133133

134134
$this->assertNotContains('\Non\Existent\Factory', $activeFactoriesList);
135135
}

test/Parser/MediaParserNegotiatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testAddNewOrUpdateExistingParser(string $parserName): void
5858

5959
$parser = new class implements MediaParserInterface {
6060
public const MIMES = ['text/made-up'];
61-
public function parse(string $input)
61+
public function parse(string $input): string
6262
{
6363
return "foo({$input})";
6464
}
@@ -84,7 +84,7 @@ public function testParse(): void
8484

8585
$parser = new class implements MediaParserInterface {
8686
public const MIMES = ['application/json'];
87-
public function parse(string $input)
87+
public function parse(string $input): mixed
8888
{
8989
return json_decode('{"arg":"' . $input . '"}', true);
9090
}

0 commit comments

Comments
 (0)