Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on getdkan/contracts #20

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
],
"require": {
"php": ">=7.4",
"ext-ctype": "*",
"ext-json": "*",
"fmizzell/maquina": "^1.1.1",
"getdkan/contracts": "^1.1.3"
"fmizzell/maquina": "^1.1.1"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
Expand Down
7 changes: 3 additions & 4 deletions src/Parser/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

namespace CsvParser\Parser;

use Contracts\ParserInterface;
use Maquina\StateMachine\MachineOfMachines;
use CsvParser\Parser\StateMachine as sm;
use Maquina\StateMachine\MachineOfMachines;

class Csv implements ParserInterface, \JsonSerializable
{
Expand Down Expand Up @@ -49,7 +48,7 @@ public function __construct($delimiter, $quote, $escape, array $record_end)
$this->machine->stopRecording();
}

public function feed(string $chunk)
public function feed(string $chunk): void
{
if (strlen($chunk) > 0) {
$chars = str_split($chunk);
Expand Down Expand Up @@ -104,7 +103,7 @@ public function reset(): void
$this->quoted = false;
}

public function finish()
public function finish(): void
{
// There will be csv strings that do not end in a "end of record" char.
// This will flush them.
Expand Down
40 changes: 40 additions & 0 deletions src/Parser/ParserInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace CsvParser\Parser;

/**
* Interface for parsing CSV files.
*/
interface ParserInterface
{

/**
* Feed a string into the parser.
*
* @param string $chunk
* A chunk of the CSV being fed into the parser.
*/
public function feed(string $chunk): void;

/**
* Get a record.
*
* @return array|null
* The record as an array, or null.
*/
public function getRecord();

/**
* Reset the parser to an initialized state.
*/
public function reset(): void;

/**
* At the end of a run of parsing, ensure there were no errors.
*
* @throws \Exception
* Throws an exception if the state machine was out of sync with our
* expectations.
*/
public function finish(): void;
}