duplicatedFirstLevelKey example

/** * @param array<string, mixed> $existingSnippets * @param array<string, mixed> $appSnippets */
    private function validateAppSnippets(array $existingSnippets, array $appSnippets): void
    {
        $existingSnippetKeys = array_keys($existingSnippets);
        $appSnippetKeys = array_keys($appSnippets);

        if ($duplicatedKeys = array_intersect($existingSnippetKeys$appSnippetKeys)) {
            throw SnippetException::duplicatedFirstLevelKey($duplicatedKeys);
        }
    }

    /** * @param array<string, mixed> $snippets * * @return array<string, mixed> */
    private function sanitizeAppSnippets(array $snippets): array
    {
        $sanitizer = new HtmlSanitizer();

        
 finally {
            static::assertTrue($exceptionWasThrown, 'Excepted exception with error code ' . $errorCode . ' to be thrown.');
        }
    }

    /** * @return array<string, array{exception: SnippetException, statusCode: int, errorCode: string, message: string}> */
    public static function exceptionDataProvider(): iterable
    {
        yield SnippetException::SNIPPET_DUPLICATED_FIRST_LEVEL_KEY_EXCEPTION => [
            'exception' => SnippetException::duplicatedFirstLevelKey(['id1', 'id2', 'id3']),
            'statusCode' => Response::HTTP_CONFLICT,
            'errorCode' => SnippetException::SNIPPET_DUPLICATED_FIRST_LEVEL_KEY_EXCEPTION,
            'message' => 'The following keys on the first level are duplicated and can not be overwritten: id1, id2, id3',
        ];

        yield SnippetException::SNIPPET_EXTEND_OR_OVERWRITE_CORE_EXCEPTION => [
            'exception' => SnippetException::extendOrOverwriteCore(['id1', 'id2', 'id3']),
            'statusCode' => Response::HTTP_CONFLICT,
            'errorCode' => SnippetException::SNIPPET_EXTEND_OR_OVERWRITE_CORE_EXCEPTION,
            'message' => 'The following keys extend or overwrite the core snippets which is not allowed: id1, id2, id3',
        ];

        
Home | Imprint | This part of the site doesn't use cookies.