Refactor, add extensive README.md, add future planning

This commit is contained in:
2020-05-13 00:32:28 +02:00
parent 63fd73f98c
commit 9002db40aa
26 changed files with 666 additions and 226 deletions

View File

@@ -0,0 +1,39 @@
<?php
namespace Tool\Parser;
use InvalidArgumentException;
use Symfony\Component\Yaml\Yaml;
use Tool\Tool;
class ToolParser
{
/**
* @param string $yamlFile
* @return Tool[]
*/
public function parseFile(string $yamlFile): array
{
$data = @Yaml::parseFile($yamlFile);
if (is_null($data)) {
throw new InvalidArgumentException('Yaml file not found: ' . $yamlFile);
}
return $this->parse($data);
}
/**
* @param array $data
* @return Tool[]
*/
public function parse(array $data): array
{
$tools = [];
foreach ($data as $T => $tool) {
$T = (int)filter_var($T, FILTER_SANITIZE_NUMBER_INT);
$tools[] = new Tool($T, $tool['X'], $tool['Z']);
}
return $tools;
}
}