private function replaceTraits($raml, array $traits, $path, $name)
    {
        if (!\is_array($raml)) {
            return $raml;
        }

        $newArray = [];

        foreach ($raml as $key => $value) {
            if ($key === 'is') {
                foreach ($value as $traitName) {
                    $trait = [];
                    if (\is_array($traitName)) {
                        $traitVariables = \current($traitName);
                        $traitName = \key($traitName);

                        $traitVariables['resourcePath'] = $path;
                        $traitVariables['resourcePathName'] = $name;

                        $trait = $this->applyVariables($traitVariables, $traits[$traitName]);
                    } elseif (isset($traits[$traitName])) {
                        $trait = $traits[$traitName];
                    }
                    // @todo Refactor as can be resource greedy
                    // @see https://github.com/kalessil/phpinspectionsea/blob/master/docs/performance.md#slow-array-function-used-in-loop
                    $newArray = \array_replace_recursive($newArray, $this->replaceTraits($trait, $traits, $path, $name));
                }
                $newArray['is'] = $value;
            } else {
                $newValue = $this->replaceTraits($value, $traits, $path, $name);

                if (isset($newArray[$key]) && \is_array($newArray[$key])) {
                    // @todo Refactor as can be resource greedy
                    // @see https://github.com/kalessil/phpinspectionsea/blob/master/docs/performance.md#slow-array-function-used-in-loop
                    $newArray[$key] = \array_replace_recursive($newArray[$key], $newValue);
                } else {
                    $newArray[$key] = $newValue;
                }
            }
        }

        return $newArray;
    }