Fix the failing unit tests
refactor the codestyle for the tests we wanted to keep
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser;
|
||||
|
||||
class Factory
|
||||
{
|
||||
protected $classMap = [
|
||||
'TuneCollection' => null,
|
||||
];
|
||||
|
||||
public function __construct(array $config = [])
|
||||
{
|
||||
}
|
||||
|
||||
public static function create($type)
|
||||
{
|
||||
return call_user_func([self, 'createInstance']);
|
||||
}
|
||||
|
||||
public function createInstance($type)
|
||||
{
|
||||
return isset($this->classMap[$type])? new $this->classMap[$type]() : null;
|
||||
}
|
||||
}
|
||||
17
src/Interfaces/Repository.php
Normal file
17
src/Interfaces/Repository.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: richard
|
||||
* Date: 10/16/17
|
||||
* Time: 6:14 AM
|
||||
*/
|
||||
|
||||
namespace XaiCorp\AbcParser\Interfaces;
|
||||
|
||||
|
||||
interface Repository
|
||||
{
|
||||
public function store($entity);
|
||||
|
||||
public function get($id);
|
||||
}
|
||||
@@ -23,9 +23,14 @@ class Abc implements Builder
|
||||
$this->collection->append($key, $data);
|
||||
}
|
||||
|
||||
public function setOnCollection($key, $data)
|
||||
{
|
||||
$this->collection->set($key, $data);
|
||||
}
|
||||
|
||||
public function getCollection()
|
||||
{
|
||||
return count($this->collection) ? $this->collection : FALSE;
|
||||
return count($this->collection) ? $this->collection : false;
|
||||
}
|
||||
|
||||
public function newTune()
|
||||
@@ -53,6 +58,11 @@ class Abc implements Builder
|
||||
$this->currentSetting->append($key, $data);
|
||||
}
|
||||
|
||||
public function setOnSetting($key, $data)
|
||||
{
|
||||
$this->currentSetting->set($key, $data);
|
||||
}
|
||||
|
||||
public function newPerson(array $data)
|
||||
{
|
||||
return new Person($data);
|
||||
@@ -63,5 +73,6 @@ class Abc implements Builder
|
||||
$this->currentSetting->set('music', trim($music));
|
||||
$this->currentTune->append('collection', $this->currentSetting);
|
||||
$this->collection->append('collection', $this->currentTune);
|
||||
//TODO: save to repositories
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,12 +62,12 @@ class Parser {
|
||||
}
|
||||
|
||||
$mode = self::MODE_NO_DATA;
|
||||
} else if ($mode === self::MODE_TUNE_BODY) {
|
||||
} elseif ($mode === self::MODE_TUNE_BODY) {
|
||||
$music .= $line . PHP_EOL;
|
||||
} else if (preg_match(self::LN_VERSION, $line)) {
|
||||
} elseif (preg_match(self::LN_VERSION, $line)) {
|
||||
//this line might contain the abc version.
|
||||
//What do we want to do with it?
|
||||
} else if (preg_match(self::LN_FIELD, $line) || $inHistory) {
|
||||
} elseif (preg_match(self::LN_FIELD, $line) || $inHistory) {
|
||||
if (preg_match(self::LN_FIELD, $line)) { $inHistory = FALSE; }
|
||||
//split the line "key:data"
|
||||
if($inHistory) {
|
||||
@@ -87,7 +87,7 @@ class Parser {
|
||||
|
||||
$this->builder->setOnTune('X', $data);
|
||||
|
||||
} else if (preg_match($keys_for_Tunes, $key)) {
|
||||
} elseif (preg_match($keys_for_Tunes, $key)) {
|
||||
if ($key === 'H') {
|
||||
$inHistory = TRUE;
|
||||
} else {
|
||||
@@ -102,7 +102,7 @@ class Parser {
|
||||
} else {
|
||||
$this->builder->appendToCollection($key, $data);
|
||||
}
|
||||
} else if($inTunes) {
|
||||
} elseif($inTunes) {
|
||||
if (in_array($key, self::SINGLE_VALUE_KEYS)) {
|
||||
$this->builder->setOnTune($key, $data);
|
||||
} else {
|
||||
@@ -110,7 +110,7 @@ class Parser {
|
||||
}
|
||||
}
|
||||
|
||||
} else if (preg_match($keys_for_Settings, $key)) {
|
||||
} elseif (preg_match($keys_for_Settings, $key)) {
|
||||
if ($key === 'K' && $mode === self::MODE_TUNE_HEADER) {
|
||||
$mode = self::MODE_TUNE_BODY;
|
||||
}
|
||||
@@ -126,7 +126,7 @@ class Parser {
|
||||
} else {
|
||||
$this->builder->appendToCollection($key, $data);
|
||||
}
|
||||
} else if($inTunes){
|
||||
} elseif($inTunes){
|
||||
if (in_array($key, self::SINGLE_VALUE_KEYS)) {
|
||||
$this->builder->setOnSetting($key, $data);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user