Skip to content

Commit

Permalink
Remove dependency on getdkan/contracts (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-m authored Dec 12, 2024
1 parent 9da722e commit 4a411d2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
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;
}

0 comments on commit 4a411d2

Please sign in to comment.