Skip to content

Commit 77723e6

Browse files
committed
Refactoring naming
1 parent 3526092 commit 77723e6

File tree

7 files changed

+22
-18
lines changed

7 files changed

+22
-18
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ composer require terremoth/php-dsv
2626
```php
2727
require_once 'vendor/autoload.php';
2828

29-
use DSV\DSVWriter;
30-
use DSV\DSVReader;
29+
use DSV\Writer;
30+
use DSV\Reader;
3131

3232
$data = [
3333
['Name', 'Comment'],
@@ -38,9 +38,9 @@ $data = [
3838
['Edward', 'アップル'],
3939
];
4040

41-
$writer = new DSVWriter('demos/data.dsv');
41+
$writer = new Writer('demos/data.dsv');
4242
$writer->write($data); // will write the $data to file in DSV format
4343

44-
$reader = new DSVReader('demos/data.dsv');
44+
$reader = new Reader('demos/data.dsv');
4545
print_r($reader->read()); // will read the demos/data.dsv file and put it in array format
4646
```

demos/demo.php

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

33
require_once 'vendor/autoload.php';
44

5-
use DSV\DSVWriter;
6-
use DSV\DSVReader;
5+
use DSV\Writer;
6+
use DSV\Reader;
77

88
$data = [
99
['Name', 'Comment'],
@@ -14,9 +14,9 @@
1414
['Edward', 'アップル'],
1515
];
1616

17-
$writer = new DSVWriter('demos/data.dsv');
17+
$writer = new Writer('demos/data.dsv');
1818
$writer->write($data);
1919

20-
$reader = new DSVReader('demos/data.dsv');
20+
$reader = new Reader('demos/data.dsv');
2121

2222
print_r($reader->read());

src/DSV/DSV.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace DSV;
44

5-
abstract class DSV
5+
trait DSV
66
{
77
/**
88
* @var non-empty-string

src/DSV/DSVReader.php renamed to src/DSV/Reader.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
use Exception;
66

7-
class DSVReader extends DSV
7+
class Reader
88
{
9+
use DSV;
10+
911
/**
1012
* @throws Exception
1113
*/

src/DSV/DSVWriter.php renamed to src/DSV/Writer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace DSV;
44

5-
class DSVWriter extends DSV
5+
class Writer
66
{
7+
use DSV;
8+
79
public function __construct(protected string $outputFile)
810
{
911
}

tests/DSV/DSVReaderTest.php renamed to tests/DSV/ReaderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use PHPUnit\Framework\Attributes\CoversClass;
77
use PHPUnit\Framework\TestCase;
88

9-
#[CoversClass(DSVReader::class)]
10-
class DSVReaderTest extends TestCase
9+
#[CoversClass(Reader::class)]
10+
class ReaderTest extends TestCase
1111
{
1212
/**
1313
* @throws Exception
@@ -25,7 +25,7 @@ public function testRead(): void
2525

2626
$totalFileLines = 6;
2727

28-
$reader = new DSVReader($tempFile);
28+
$reader = new Reader($tempFile);
2929
$result = $reader->read();
3030
$this->assertEquals(count($result), $totalFileLines);
3131
unlink($tempFile);
@@ -37,7 +37,7 @@ public function testRead(): void
3737
public function testException(): void
3838
{
3939
$this->expectException(Exception::class);
40-
$reader = new DSVReader(random_int(0, 999999) . '.dsv');
40+
$reader = new Reader(random_int(0, 999999) . '.dsv');
4141
$reader->read();
4242
}
4343
}

tests/DSV/DSVWriterTest.php renamed to tests/DSV/WriterTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use PHPUnit\Framework\Attributes\DataProvider;
77
use PHPUnit\Framework\TestCase;
88

9-
#[CoversClass(DSVWriter::class)]
10-
class DSVWriterTest extends TestCase
9+
#[CoversClass(Writer::class)]
10+
class WriterTest extends TestCase
1111
{
1212
/**
1313
* @return array[]
@@ -49,7 +49,7 @@ public static function dataProvider(): array
4949
public function testWrite(array $data, string $result): void
5050
{
5151
$file = tempnam(sys_get_temp_dir(), 'dsv-test-data');
52-
$writer = new DSVWriter($file);
52+
$writer = new Writer($file);
5353
$writer->write($data);
5454
$this->assertEquals($result, file_get_contents($file));
5555
unlink($file);

0 commit comments

Comments
 (0)