jeyroik/extas-base

View on GitHub
src/components/THasItemsData.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
namespace extas\components;

/**
 * Trait THasItemsData
 *
 * @package extas\components
 * @author jeyroik@gmail.com
 */
trait THasItemsData
{
    /**
     * @param array $data
     * @param string $itemClass
     * @return array
     */
    public function convertToItems(array $data, string $itemClass): array
    {
        $items = [];

        foreach ($data as $index => $datum) {
            $items[$index] = new $itemClass($datum);
        }

        return $items;
    }
}