Refactor, add extensive README.md, add future planning
This commit is contained in:
39
src/Tool/Parser/ToolParser.php
Normal file
39
src/Tool/Parser/ToolParser.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user