Visual Console Refactor: fixes

Former-commit-id: c9ae864cba26c6085e4e7390db26e32204ec7397
This commit is contained in:
Alejandro Gallardo Escobar 2019-04-03 11:25:35 +02:00
parent eb17b01adc
commit eb6757e91c
2 changed files with 36 additions and 50 deletions

View File

@ -5,6 +5,9 @@ declare(strict_types=1);
namespace Models\VisualConsole\Items; namespace Models\VisualConsole\Items;
use Models\Model; use Models\Model;
/**
* Model of a line item of the Visual Console.
*/
final class Line extends Model final class Line extends Model
{ {
@ -16,11 +19,10 @@ final class Line extends Model
* @param array $data Input data. * @param array $data Input data.
* *
* @return void * @return void
*
* @throws \InvalidArgumentException If any input value is considered * @throws \InvalidArgumentException If any input value is considered
* invalid. * invalid.
* *
* @overrides Model::validateData. * @overrides Model->validateData.
*/ */
protected function validateData(array $data): void protected function validateData(array $data): void
{ {
@ -49,7 +51,7 @@ final class Line extends Model
* *
* @return array Data structure representing the model. * @return array Data structure representing the model.
* *
* @overrides Model::decode. * @overrides Model->decode.
*/ */
protected function decode(array $data): array protected function decode(array $data): array
{ {
@ -60,7 +62,7 @@ final class Line extends Model
'startY' => $this->extractStartY($data), 'startY' => $this->extractStartY($data),
'endX' => $this->extractEndX($data), 'endX' => $this->extractEndX($data),
'endY' => $this->extractEndY($data), 'endY' => $this->extractEndY($data),
'isOnTop' => $this->extractIsOnTope($data), 'isOnTop' => $this->extractIsOnTop($data),
'borderWidth' => $this->extractBorderWidth($data), 'borderWidth' => $this->extractBorderWidth($data),
'borderColor' => $this->extractBorderColor($data), 'borderColor' => $this->extractBorderColor($data),
]; ];
@ -68,119 +70,104 @@ final class Line extends Model
/** /**
* Extract the value of startX and * Extract a x axis value.
* return a integer.
* *
* @param array $data Unknown input data structure. * @param array $data Unknown input data structure.
* *
* @return integer Valid x axis start position of the item. * @return integer Valid x axis of the start position of the line.
*/ */
private function extractStartX(array $data): int private function extractStartX(array $data): int
{ {
$startX = Model::parseIntOr( return static::parseIntOr(
Model::issetInArray($data, ['startX', 'pos_x']), static::issetInArray($data, ['startX', 'pos_x']),
0 0
); );
return $startX;
} }
/** /**
* Extract the value of startY and * Extract a y axis value.
* return a integer.
* *
* @param array $data Unknown input data structure. * @param array $data Unknown input data structure.
* *
* @return integer Valid y axis start position of the item. * @return integer Valid y axis of the start position of the line.
*/ */
private function extractStartY(array $data): int private function extractStartY(array $data): int
{ {
$startY = Model::parseIntOr( return static::parseIntOr(
Model::issetInArray($data, ['startY', 'pos_y']), static::issetInArray($data, ['startY', 'pos_y']),
0 0
); );
return $startY;
} }
/** /**
* Extract the value of endX and * Extract a x axis value.
* return a integer.
* *
* @param array $data Unknown input data structure. * @param array $data Unknown input data structure.
* *
* @return integer Valid x axis end position of the item. * @return integer Valid x axis of the end position of the line.
*/ */
private function extractEndX(array $data): int private function extractEndX(array $data): int
{ {
$endX = Model::parseIntOr( return static::parseIntOr(
Model::issetInArray($data, ['endX', 'width']), static::issetInArray($data, ['endX', 'width']),
0 0
); );
return $endX;
} }
/** /**
* Extract the value of endY and * Extract a y axis value.
* return a integer.
* *
* @param array $data Unknown input data structure. * @param array $data Unknown input data structure.
* *
* @return integer Valid y axis end position of the item. * @return integer Valid y axis of the end position of the line.
*/ */
private function extractEndY(array $data): int private function extractEndY(array $data): int
{ {
$endY = Model::parseIntOr( return static::parseIntOr(
Model::issetInArray($data, ['endY', 'height']), static::issetInArray($data, ['endY', 'height']),
0 0
); );
return $endY;
} }
/** /**
* Extract the value of isOnTop and * Extract a conditional value which tells if the item has visual priority.
* return a bool.
* *
* @param array $data Unknown input data structure. * @param array $data Unknown input data structure.
* *
* @return boolean If the item is on top or not. * @return boolean If the item is on top or not.
*/ */
private function extractIsOnTope(array $data): bool private function extractIsOnTop(array $data): bool
{ {
$isOnTop = Model::parseBool( return static::parseBool(
Model::issetInArray($data, ['isOnTop', 'show_on_top']) static::issetInArray($data, ['isOnTop', 'show_on_top'])
); );
return $isOnTop;
} }
/** /**
* Extract the value of borderWidth and * Extract a border width value.
* return a integer.
* *
* @param array $data Unknown input data structure. * @param array $data Unknown input data structure.
* *
* @return integer Valid border width. 0 by default. * @return integer Valid border width. 0 by default and minimum value.
*/ */
private function extractBorderWidth(array $data): int private function extractBorderWidth(array $data): int
{ {
$borderWidth = Model::parseIntOr( $borderWidth = static::parseIntOr(
Model::issetInArray($data, ['borderWidth', 'border_width']), static::issetInArray($data, ['borderWidth', 'border_width']),
0 0
); );
if ($borderWidth >= 0) {
return $borderWidth; return ($borderWidth >= 0) ? $borderWidth : 0;
} else {
return 0;
}
} }
/** /**
* Extract the value of borderColor and * Extract a border color value.
* return to not empty string or null.
* *
* @param array $data Unknown input data structure. * @param array $data Unknown input data structure.
* *
@ -188,11 +175,10 @@ final class Line extends Model
*/ */
private function extractBorderColor(array $data) private function extractBorderColor(array $data)
{ {
$borderColor = Model::notEmptyStringOr( return static::notEmptyStringOr(
Model::issetInArray($data, ['borderColor', 'border_color']), static::issetInArray($data, ['borderColor', 'border_color']),
null null
); );
return $borderColor;
} }

View File

@ -90,7 +90,7 @@ final class SimpleValue extends Item
case 'avg': case 'avg':
case 'max': case 'max':
case 'min': case 'min':
return $processValue; return $data['processValue'];
default: default:
return 'none'; return 'none';