jaroslavtyc/drd-plus-therugist-spells

View on GitHub
DrdPlus/Theurgist/Spells/ProfilesTable.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
declare(strict_types=1);
 
namespace DrdPlus\Theurgist\Spells;
 
use DrdPlus\Tables\Partials\AbstractFileTable;
use DrdPlus\Tables\Partials\Exceptions\RequiredRowNotFound;
use DrdPlus\Codes\Theurgist\FormulaCode;
use DrdPlus\Codes\Theurgist\ModifierCode;
use DrdPlus\Codes\Theurgist\ProfileCode;
 
class ProfilesTable extends AbstractFileTable
{
protected function getDataFileName(): string
{
return __DIR__ . '/data/profiles.csv';
}
 
public const MODIFIERS = 'modifiers';
public const FORMULAS = 'formulas';
 
protected function getExpectedDataHeaderNamesToTypes(): array
{
return [
self::MODIFIERS => self::ARRAY,
self::FORMULAS => self::ARRAY,
];
}
 
public const PROFILE = 'profile';
 
protected function getRowsHeader(): array
{
return [
self::PROFILE,
];
}
 
/**
* @param ProfileCode $profileCode
* @return array|ModifierCode[]
* @throws \DrdPlus\Theurgist\Spells\Exceptions\UnknownProfileToGetModifiersFor
*/
public function getModifiersForProfile(ProfileCode $profileCode): array
{
try {
return \array_map(
function (string $modifierValue) {
Avoid using static access to class '\DrdPlus\Codes\Theurgist\ModifierCode' in method 'getModifiersForProfile'.
return ModifierCode::getIt($modifierValue);
},
$this->getValue($profileCode, self::MODIFIERS)
);
} catch (RequiredRowNotFound $requiredRowNotFound) {
throw new Exceptions\UnknownProfileToGetModifiersFor("Given profile code '{$profileCode}' is unknown");
}
}
 
/**
* @param ProfileCode $profileCode
* @return array|FormulaCode[]
* @throws \DrdPlus\Theurgist\Spells\Exceptions\UnknownProfileToGetFormulasFor
*/
public function getFormulasForProfile(ProfileCode $profileCode): array
{
try {
return \array_map(
function (string $formulaValue) {
Avoid using static access to class '\DrdPlus\Codes\Theurgist\FormulaCode' in method 'getFormulasForProfile'.
return FormulaCode::getIt($formulaValue);
},
$this->getValue($profileCode, self::FORMULAS)
);
} catch (RequiredRowNotFound $requiredRowNotFound) {
throw new Exceptions\UnknownProfileToGetFormulasFor("Given profile code '{$profileCode}' is unknown");
}
}
 
}