diff --git a/src/Enums/FeesPercentCategory.php b/src/Enums/FeesPercentCategory.php index 4c91fca..e9a5afc 100644 --- a/src/Enums/FeesPercentCategory.php +++ b/src/Enums/FeesPercentCategory.php @@ -73,7 +73,7 @@ enum FeesPercentCategory: int /** - * ΤΕισφορά δακοκτονίας [ποσό] + * Εισφορά δακοκτονίας [ποσό] */ case TYPE_12 = 12; diff --git a/src/Services/CategoryClassificationCollection.php b/src/Services/CategoryClassificationCollection.php index dec0b36..91c3bca 100644 --- a/src/Services/CategoryClassificationCollection.php +++ b/src/Services/CategoryClassificationCollection.php @@ -108,7 +108,7 @@ public function getIterator(): Traversable public function isEmpty(): bool { - return empty($this->toArray()); + return empty($this->classifications); } private function toEnum(mixed $value): IncomeClassificationCategory|ExpenseClassificationCategory|null diff --git a/src/Services/TypeClassificationCollection.php b/src/Services/TypeClassificationCollection.php index c477e37..608ff8a 100644 --- a/src/Services/TypeClassificationCollection.php +++ b/src/Services/TypeClassificationCollection.php @@ -12,15 +12,27 @@ class TypeClassificationCollection implements ArrayAccess, IteratorAggregate { + /** + * @var array $classifications + */ private array $classifications; private bool $isIncome; + /** + * @param array $classifications + * @param bool $isIncome + */ public function __construct(array $classifications, bool $isIncome) { $this->classifications = $classifications; $this->isIncome = $isIncome; } + /** + * Converts classifications to an associative array with keys and labels. + * + * @return array + */ public function toKeyLabel(): array { $results = []; @@ -34,64 +46,127 @@ public function toKeyLabel(): array return $results; } + /** + * Returns the keys of the classifications array. + * + * @return array + */ public function keys(): array { - return $this->toArray(); + return $this->classifications; } + /** + * Returns the classifications as an array. + * + * @return array + */ public function toArray(): array { return $this->classifications; } + /** + * Checks if an offset exists in the classifications array. + * + * @param mixed $offset + * @return bool + */ public function offsetExists(mixed $offset): bool { return isset($this->classifications[$offset]); } - public function offsetGet(mixed $offset): mixed + /** + * Gets the value at the given offset. + * + * @param mixed $offset + * @return string|IncomeClassificationType|ExpenseClassificationType|null + */ + public function offsetGet(mixed $offset): string|null|IncomeClassificationType|ExpenseClassificationType { - return $this->classifications[$offset]; + return $this->classifications[$offset] ?? null; } + /** + * Checks if the classifications array contains a specific value. + * + * @param mixed $value + * @return bool + */ public function contains(mixed $value): bool { if ($value === null) { - return empty($this->toArray()) || in_array($value, $this->toArray(), true); + return empty($this->classifications) || in_array($value, $this->classifications, true); } - + if ($value instanceof BackedEnum) { $value = $value->value; } - - return in_array($value, $this->toArray(), true); + + return in_array($value, $this->classifications, true); } + /** + * Gets the classification as an enum if possible. + * + * @param mixed $offset + * @return IncomeClassificationType|ExpenseClassificationType|null + */ public function get(mixed $offset): IncomeClassificationType|ExpenseClassificationType|null { return $this->toEnum($offset); } + /** + * Sets the value at the given offset. + * + * @param mixed $offset + * @param IncomeClassificationType|ExpenseClassificationType|string $value + * @return void + */ public function offsetSet(mixed $offset, mixed $value): void { $this->classifications[$offset] = $value; } + /** + * Unsets the value at the given offset. + * + * @param mixed $offset + * @return void + */ public function offsetUnset(mixed $offset): void { unset($this->classifications[$offset]); } + /** + * Returns an iterator for the classifications array. + * + * @return Traversable + */ public function getIterator(): Traversable { return new ArrayIterator($this->classifications); } + /** + * Checks if the classifications array is empty. + * + * @return bool + */ public function isEmpty(): bool { - return empty($this->toArray()); + return empty($this->classifications); } - + + /** + * Converts a value to the appropriate enum type if possible. + * + * @param mixed $value + * @return IncomeClassificationType|ExpenseClassificationType|null + */ private function toEnum(mixed $value): IncomeClassificationType|ExpenseClassificationType|null { if ($value === null) { @@ -106,4 +181,4 @@ private function toEnum(mixed $value): IncomeClassificationType|ExpenseClassific ? IncomeClassificationType::tryFrom($value) : ExpenseClassificationType::tryFrom($value); } -} \ No newline at end of file +} diff --git a/src/Traits/HasIterator.php b/src/Traits/HasIterator.php index a906a05..27b8aab 100644 --- a/src/Traits/HasIterator.php +++ b/src/Traits/HasIterator.php @@ -2,42 +2,80 @@ namespace Firebed\AadeMyData\Traits; +use ArrayAccess; use ArrayIterator; +use IteratorAggregate; use Traversable; /** + * Trait HasIterator + * * @template Model + * @implements ArrayAccess + * @implements IteratorAggregate */ trait HasIterator { + /** + * Returns an iterator for the attributes. + * + * @return Traversable + */ public function getIterator(): Traversable { return new ArrayIterator($this->attributes); } + /** + * Returns the count of attributes. + * + * @return int + */ public function count(): int { return count($this->attributes); } + /** + * Checks if the given offset exists in the attributes. + * + * @param int|string $offset + * @return bool + */ public function offsetExists(mixed $offset): bool { return array_key_exists($offset, $this->attributes); } /** - * @return Model + * Gets the value at the given offset. + * + * @param int|string $offset + * @return Model|null */ public function offsetGet(mixed $offset): mixed { return $this->get($offset); } + /** + * Sets the value at the given offset. + * + * @param int|string $offset + * @param Model $value + * @return void + */ public function offsetSet(mixed $offset, mixed $value): void { $this->set($offset, $value); } + /** + * Unsets the value at the given offset. + * + * @param int|string $offset + * @return void + */ public function offsetUnset(mixed $offset): void { unset($this->attributes[$offset]);