Skip to content

Commit

Permalink
Refactoring naming
Browse files Browse the repository at this point in the history
  • Loading branch information
terremoth committed Nov 22, 2024
1 parent 3526092 commit 77723e6
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ composer require terremoth/php-dsv
```php
require_once 'vendor/autoload.php';

use DSV\DSVWriter;
use DSV\DSVReader;
use DSV\Writer;
use DSV\Reader;

$data = [
['Name', 'Comment'],
Expand All @@ -38,9 +38,9 @@ $data = [
['Edward', 'アップル'],
];

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

$reader = new DSVReader('demos/data.dsv');
$reader = new Reader('demos/data.dsv');
print_r($reader->read()); // will read the demos/data.dsv file and put it in array format
```
8 changes: 4 additions & 4 deletions demos/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

require_once 'vendor/autoload.php';

use DSV\DSVWriter;
use DSV\DSVReader;
use DSV\Writer;
use DSV\Reader;

$data = [
['Name', 'Comment'],
Expand All @@ -14,9 +14,9 @@
['Edward', 'アップル'],
];

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

$reader = new DSVReader('demos/data.dsv');
$reader = new Reader('demos/data.dsv');

print_r($reader->read());
2 changes: 1 addition & 1 deletion src/DSV/DSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace DSV;

abstract class DSV
trait DSV
{
/**
* @var non-empty-string
Expand Down
4 changes: 3 additions & 1 deletion src/DSV/DSVReader.php → src/DSV/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

use Exception;

class DSVReader extends DSV
class Reader
{
use DSV;

/**
* @throws Exception
*/
Expand Down
4 changes: 3 additions & 1 deletion src/DSV/DSVWriter.php → src/DSV/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace DSV;

class DSVWriter extends DSV
class Writer
{
use DSV;

public function __construct(protected string $outputFile)
{
}
Expand Down
8 changes: 4 additions & 4 deletions tests/DSV/DSVReaderTest.php → tests/DSV/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[CoversClass(DSVReader::class)]
class DSVReaderTest extends TestCase
#[CoversClass(Reader::class)]
class ReaderTest extends TestCase
{
/**
* @throws Exception
Expand All @@ -25,7 +25,7 @@ public function testRead(): void

$totalFileLines = 6;

$reader = new DSVReader($tempFile);
$reader = new Reader($tempFile);
$result = $reader->read();
$this->assertEquals(count($result), $totalFileLines);
unlink($tempFile);
Expand All @@ -37,7 +37,7 @@ public function testRead(): void
public function testException(): void
{
$this->expectException(Exception::class);
$reader = new DSVReader(random_int(0, 999999) . '.dsv');
$reader = new Reader(random_int(0, 999999) . '.dsv');
$reader->read();
}
}
6 changes: 3 additions & 3 deletions tests/DSV/DSVWriterTest.php → tests/DSV/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

#[CoversClass(DSVWriter::class)]
class DSVWriterTest extends TestCase
#[CoversClass(Writer::class)]
class WriterTest extends TestCase
{
/**
* @return array[]
Expand Down Expand Up @@ -49,7 +49,7 @@ public static function dataProvider(): array
public function testWrite(array $data, string $result): void
{
$file = tempnam(sys_get_temp_dir(), 'dsv-test-data');
$writer = new DSVWriter($file);
$writer = new Writer($file);
$writer->write($data);
$this->assertEquals($result, file_get_contents($file));
unlink($file);
Expand Down

0 comments on commit 77723e6

Please sign in to comment.