damianopetrungaro/clean-architecture

View on GitHub
src/Common/CommonTrait/CloneArrayTrait.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

declare(strict_types=1);

namespace Damianopetrungaro\CleanArchitecture\Common\CommonTrait;

trait CloneArrayTrait
{
    /**
     * Return a cloned array from an array reference.
     *
     * @param array $array
     *
     * @return array
     */
    protected function cloneArray(array &$array): array
    {
        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $array[$key] = $this->cloneArray($value);
            }

            if (is_object($value)) {
                $array[$key] = clone $value;
            }
        }

        return $array;
    }
}