Skip to content

Commit e2570f3

Browse files
committed
Updated to PHP 7.4
- Removed dependency on tale-dev-tool - Added property types - Some minor fixes
1 parent 47a37b7 commit e2570f3

File tree

12 files changed

+71
-78
lines changed

12 files changed

+71
-78
lines changed

.travis.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
21
language: php
3-
42
git:
53
depth: 5
6-
74
php:
8-
- 7.1
9-
- 7.2
10-
- 7.3
11-
5+
- 7.4
126
install:
137
- travis_retry composer clear-cache
148
- travis_retry composer self-update
159
- travis_retry composer install
16-
1710
script:
18-
- vendor/bin/tale-dev check --report --coverage-php-version=7.1
19-
20-
addons:
21-
code_climate:
22-
repo_token: 9c681c931a1a0411dfc5f0ed09cb647976fc142692b5141f444a336c1dadc2ec
11+
- composer lint
12+
- composer test

composer.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,26 @@
55
"description": "A reading library that can read and parse strings and PSR-7 streams",
66
"license": "MIT",
77
"homepage": "http://docs.talesoft.codes/php/tale/reader",
8+
"scripts": {
9+
"test": "phpunit",
10+
"test:coverage-html": "phpunit --coverage-html=coverage",
11+
"lint": "phpcs",
12+
"lint:fix": "phpcbf"
13+
},
814
"authors": [
915
{
1016
"name": "Torben Koehn",
1117
"email": "torben@talesoft.codes"
1218
}
1319
],
1420
"require": {
15-
"php": ">=7.1.0",
21+
"php": ">=7.4.0",
22+
"ext-ctype": "*",
1623
"psr/http-message": "^1.0"
1724
},
1825
"require-dev": {
19-
"talesoft/tale-dev-tool": "dev-master",
26+
"phpunit/phpunit": "^8.4",
27+
"squizlabs/php_codesniffer": "^3.5",
2028
"talesoft/tale-stream": "dev-master"
2129
},
2230
"autoload": {

phpcs.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PSR-2">
3+
<rule ref="PSR2"/>
4+
<file>./src</file>
5+
<file>./tests</file>
6+
</ruleset>

phpunit.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.4/phpunit.xsd"
4+
colors="true"
5+
bootstrap="./vendor/autoload.php"
6+
forceCoversAnnotation="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
verbose="true">
11+
<testsuites>
12+
<testsuite name="Talesoft - Tale Reader">
13+
<directory>./tests</directory>
14+
</testsuite>
15+
</testsuites>
16+
<filter>
17+
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
18+
<directory suffix=".php">./src</directory>
19+
</whitelist>
20+
</filter>
21+
</phpunit>

src/Reader/StreamReader.php

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,10 @@
77

88
final class StreamReader implements ReaderInterface
99
{
10-
/**
11-
* @var StreamInterface
12-
*/
13-
private $stream;
14-
15-
/**
16-
* @var string
17-
*/
18-
private $buffer = '';
19-
20-
/**
21-
* @var int
22-
*/
23-
private $bufferSize;
24-
25-
/**
26-
* @var int
27-
*/
28-
private $nextConsumeLength = 0;
10+
private StreamInterface $stream;
11+
private string $buffer = '';
12+
private int $bufferSize;
13+
private int $nextConsumeLength = 0;
2914

3015
/**
3116
* creates a new streamReader instance.
@@ -81,8 +66,10 @@ public function consume(int $length = 0): string
8166
return '';
8267
}
8368
$this->expandBuffer($length);
69+
$length = min(strlen($this->buffer), $length);
8470
$consumedBytes = substr($this->buffer, 0, $length);
85-
$this->buffer = substr($this->buffer, $length);
71+
$newBuffer = substr($this->buffer, $length);
72+
$this->buffer = $newBuffer !== false ? $newBuffer : '';
8673
$this->nextConsumeLength = 0;
8774
return $consumedBytes;
8875
}
@@ -94,9 +81,8 @@ public function consume(int $length = 0): string
9481
*/
9582
private function expandBuffer(int $length): void
9683
{
97-
if (\strlen($this->buffer) >= $length || $this->stream->eof()) {
98-
return;
84+
while (\strlen($this->buffer) < $length && !$this->stream->eof()) {
85+
$this->buffer .= $this->stream->read($this->bufferSize);
9986
}
100-
$this->buffer .= $this->stream->read($this->bufferSize);
10187
}
10288
}

src/Reader/StringReader.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,8 @@
66

77
final class StringReader implements ReaderInterface
88
{
9-
/**
10-
* @var string
11-
*/
12-
private $string;
13-
14-
/**
15-
* @var int
16-
*/
17-
private $nextConsumeLength = 0;
9+
private string $string;
10+
private int $nextConsumeLength = 0;
1811

1912
public function __construct(string $string)
2013
{

src/Reader/Text/Expression/NumberExpression.php

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

55
final class NumberExpression
66
{
7-
private $integerPart;
8-
private $decimalPart;
7+
private string $integerPart;
8+
private string $decimalPart;
99

1010
/**
1111
* NumberValue constructor.

src/Reader/Text/ExpressionReader.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ final class ExpressionReader
99
{
1010
public const DEFAULT_ESCAPE_TEXT = '\\';
1111

12-
/** @var TextReader */
13-
private $textReader;
12+
private TextReader $textReader;
1413

1514
public function __construct(TextReader $textReader)
1615
{
@@ -96,9 +95,8 @@ public function readNumber(?string $decimalDelimiter = '.', ?string $thousandsDe
9695
return null;
9796
}
9897

99-
$isDigit = function (string $byte) use ($thousandsDelimiter) {
100-
return ctype_digit($byte) || ($thousandsDelimiter !== null && $byte === $thousandsDelimiter);
101-
};
98+
$isDigit = fn (string $byte) =>
99+
ctype_digit($byte) || ($thousandsDelimiter !== null && $byte === $thousandsDelimiter);
102100

103101
$integer = $this->textReader->readWhile($isDigit) ?: '0';
104102
$decimal = '0';

src/Reader/Text/Location.php

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

55
final class Location
66
{
7-
/**
8-
* @var int
9-
*/
10-
private $line;
11-
/**
12-
* @var int
13-
*/
14-
private $offset;
7+
private int $line;
8+
private int $offset;
159

1610
/**
1711
* TextLocation constructor.

src/Reader/Text/ReadException.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
final class ReadException extends \RuntimeException
88
{
9-
/**
10-
* @var Location
11-
*/
12-
private $location;
9+
private Location $location;
1310

1411
public function __construct(Location $location, string $message = '', int $code = 0, Throwable $previous = null)
1512
{

0 commit comments

Comments
 (0)