Skip to content

Commit 9d51d38

Browse files
committed
Merge branch 'release/1.1.3'
2 parents 0ce2a8e + dba963f commit 9d51d38

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ jobs:
1616
php: [
1717
'5.5', '5.6',
1818
'7.0', '7.1', '7.2', '7.3', '7.4',
19-
'8.0', '8.1', '8.2'
19+
'8.0', '8.1', '8.2', '8.3'
2020
]
2121

2222
name: PHP ${{ matrix.php }}
2323

2424
steps:
25-
- name: Setup PHP ${{ matrix.php-version }}
25+
- name: Setup PHP ${{ matrix.php }}
2626
uses: shivammathur/setup-php@v2
2727
with:
2828
php-version: ${{ matrix.php }}

src/NDJSON.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
use Generator;
66
use SplFileObject;
77

8+
/**
9+
* @template TKey as array-key
10+
* @template TValue
11+
*/
812
class NDJSON extends SplFileObject
913
{
14+
/**
15+
* @param string $filename
16+
*/
1017
public function __construct($filename)
1118
{
1219
parent::__construct($filename, 'a+');
@@ -16,7 +23,7 @@ public function __construct($filename)
1623
/**
1724
* Gets line from file and decode a JSON string
1825
*
19-
* @return array|null
26+
* @return array<TKey, TValue>|null
2027
*/
2128
public function readline()
2229
{
@@ -28,6 +35,7 @@ public function readline()
2835
return null;
2936
}
3037

38+
/** @var array<TKey, TValue>|null */
3139
return json_decode(trim($row), true);
3240
}
3341

@@ -64,9 +72,9 @@ public function readlines($lines)
6472
/**
6573
* Write the array to file with JSON encoding
6674
*
67-
* @param array $values
68-
* @param int $json_flags
69-
* @param string $separator
75+
* @param array<TKey, TValue> $values
76+
* @param int $json_flags
77+
* @param string $separator
7078
*
7179
* @return int|false
7280
*/
@@ -80,9 +88,9 @@ public function writeline($values, $json_flags = 0, $separator = "\n")
8088
/**
8189
* Write multiple arrays to a file with JSON encoding
8290
*
83-
* @param array $values
84-
* @param int $json_flags
85-
* @param string $separator
91+
* @param array<TKey, TValue> $values
92+
* @param int $json_flags
93+
* @param string $separator
8694
*
8795
* @return int|false
8896
*/

tests/NDJSONTest.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
namespace Tests;
44

5-
use Sunaoka\Ndjson\NDJSON;
65
use PHPUnit\Framework\TestCase;
6+
use Sunaoka\Ndjson\NDJSON;
77

88
class NDJSONTest extends TestCase
99
{
1010
/**
1111
* @dataProvider readlineProvider
1212
*
1313
* @param string $file
14+
*
15+
* @return void
1416
*/
1517
public function test_readline_newline_successful($file)
1618
{
@@ -23,6 +25,9 @@ public function test_readline_newline_successful($file)
2325
self::assertSame(['test' => '002'], $actual);
2426
}
2527

28+
/**
29+
* @return string[][]
30+
*/
2631
public static function readlineProvider()
2732
{
2833
return [
@@ -35,6 +40,8 @@ public static function readlineProvider()
3540
* @dataProvider emptyLineProvider
3641
*
3742
* @param string $file
43+
*
44+
* @return void
3845
*/
3946
public function test_readline_empty_line_successful($file)
4047
{
@@ -46,6 +53,9 @@ public function test_readline_empty_line_successful($file)
4653
}
4754
}
4855

56+
/**
57+
* @return string[][]
58+
*/
4959
public static function emptyLineProvider()
5060
{
5161
return [
@@ -54,6 +64,9 @@ public static function emptyLineProvider()
5464
];
5565
}
5666

67+
/**
68+
* @return void
69+
*/
5770
public function test_readline_empty_successful()
5871
{
5972
$ndjson = new NDJSON(__DIR__ . '/fixtures/empty.ndjson');
@@ -66,6 +79,8 @@ public function test_readline_empty_successful()
6679
* @dataProvider readlinesProvider
6780
*
6881
* @param string $file
82+
*
83+
* @return void
6984
*/
7085
public function test_readlines_newline_successful($file)
7186
{
@@ -120,6 +135,9 @@ public function test_readlines_newline_successful($file)
120135
self::assertSame(1, $actual);
121136
}
122137

138+
/**
139+
* @return string[][]
140+
*/
123141
public static function readlinesProvider()
124142
{
125143
return [
@@ -128,6 +146,9 @@ public static function readlinesProvider()
128146
];
129147
}
130148

149+
/**
150+
* @return void
151+
*/
131152
public function test_readlines_empty_successful()
132153
{
133154
$ndjson = new NDJSON(__DIR__ . '/fixtures/empty.ndjson');
@@ -138,6 +159,9 @@ public function test_readlines_empty_successful()
138159
self::assertNull($actual);
139160
}
140161

162+
/**
163+
* @return void
164+
*/
141165
public function test_writeline_successful()
142166
{
143167
$ndjson = new NDJSON('php://memory');
@@ -157,6 +181,9 @@ public function test_writeline_successful()
157181
self::assertSame(['test' => '002'], $actual);
158182
}
159183

184+
/**
185+
* @return void
186+
*/
160187
public function test_writelines_successful()
161188
{
162189
$ndjson = new NDJSON('php://memory');

0 commit comments

Comments
 (0)