<commit_before><?php

namespace Api\Controller;

use Api\App;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class Author
{
	public function authors()
	{
		return 'list of authors';
	}

	public function author($id, Request $request, App $app)
	{
		if (strpos($request->headers->get('Content-Type'), ';') !== false) {
			return $app->json(
				['errors' => ''],
				Response::HTTP_UNSUPPORTED_MEDIA_TYPE,
				['Content-Type' => 'application/vnd.api+json']
			);
		}

		$accept = $request->headers->get('Accept');
		if (strpos($accept, 'application/vnd.api+json') !== false) {
			$mediaTypes = explode(',', $accept);
			foreach ($mediaTypes as $mediaType) {
				if (strpos($mediaType, 'application/vnd.api+json') === 0
					&& strpos($mediaType, ';') !== false
				) {
					return $app->json(
						['errors' => ''],
						Response::HTTP_NOT_ACCEPTABLE,
						['Content-Type' => 'application/vnd.api+json']
					);
				}
			}
		}

		$response = [
			'data' => [
				'type'       => 'author',
				'id'         => $id,
				'attributes' => [
					'name' => '<NAME>'
				],
			],
			'links' => [
				'self' => $app->url('author', ['id' => $id]),
			],
			'relationships' => [
				'books' => [
					'data' => [
						[
							'type'  => 'book',
							'id'    => '1',
							'links' => [
								'self' => $app->url('book', ['id' => '1']),
							],
						],
						[
							'type'  => 'book',
							'id'    => '2',
							'links' => [
								'self' => $app->url('book', ['id' => '2']),
							],
						],
					],
					'links' => [
						'self' => $app->url('authorBooks', ['id' => $id]),
					],
				],
			],
			'jsonapi' => [
				'version' => '1.0'
			],
		];

		$include = $request->query->get('include');
		if ($include) {
			if ($include === 'books') {
				$response['included'] = [
					[
						'type' => 'book',
						'id'   => '1',
						'attributes' => [
							'title'            => 'Foundation',
							'publication_date' => '1951-01-01',
							'description'      => 'desc1'
						],
						'links' => [
							'self' => $app->url('book', ['id' => '1']),
						],
					],
					[
						'type' => 'book',
						'id'   => '2',
						'attributes' => [
							'title'            => 'I, Robot',
							'publication_date' => '1950-12-02',
							'description'      => 'desc2'
						],
						'links' => [
							'self' => $app->url('book', ['id' => '2']),
						],
					],
				];
			} else {
				return $app->json(
					['errors' => ''],
					Response::HTTP_BAD_REQUEST,<commit_msg>add error handling<commit_after><?php

namespace Api\Controller;

use Api\App;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class Author
{
	public function authors()
	{
		return 'list of authors';
	}

	public function author($id, Request $request, App $app)
	{
		if (strpos($request->headers->get('Content-Type'), ';') !== false) {
			return $app->json(
				['errors' => ''],
				Response::HTTP_UNSUPPORTED_MEDIA_TYPE,
				['Content-Type' => 'application/vnd.api+json']
			);
		}

		$accept = $request->headers->get('Accept');
		if (strpos($accept, 'application/vnd.api+json') !== false) {
			$mediaTypes = explode(',', $accept);
			foreach ($mediaTypes as $mediaType) {
				if (strpos($mediaType, 'application/vnd.api+json') === 0
					&& strpos($mediaType, ';') !== false
				) {
					return $app->json(
						['errors' => ''],
						Response::HTTP_NOT_ACCEPTABLE,
						['Content-Type' => 'application/vnd.api+json']
					);
				}
			}
		}

		$response = [
			'data' => [
				'type'       => 'author',
				'id'         => $id,
				'attributes' => [
					'name' => '<NAME>'
				],
			],
			'links' => [
				'self' => $app->url('author', ['id' => $id]),
			],
			'relationships' => [
				'books' => [
					'data' => [
						[
							'type'  => 'book',
							'id'    => '1',
							'links' => [
								'self' => $app->url('book', ['id' => '1']),
							],
						],
						[
							'type'  => 'book',
							'id'    => '2',
							'links' => [
								'self' => $app->url('book', ['id' => '2']),
							],
						],
					],
					'links' => [
						'self' => $app->url('authorBooks', ['id' => $id]),
					],
				],
			],
			'jsonapi' => [
				'version' => '1.0'
			],
		];

		$include = $request->query->get('include');
		if ($include) {
			if ($include === 'books') {
				$response['included'] = [
					[
						'type' => 'book',
						'id'   => '1',
						'attributes' => [
							'title'            => 'Foundation',
							'publication_date' => '1951-01-01',
							'description'      => 'desc1'
						],
						'links' => [
							'self' => $app->url('book', ['id' => '1']),
						],
					],
					[
						'type' => 'book',
						'id'   => '2',
						'attributes' => [
							'title'            => 'I, Robot',
							'publication_date' => '1950-12-02',
							'description'      => 'desc2'
						],
						'links' => [
							'self' => $app->url('book', ['id' => '2']),
						],
					],
				];
			} else {
				return $app->json(
					[
						'errors' => [
							'code'   => '?',
							'status' => Response::HTTP_BAD_REQUEST,
							'title'  => '?',
							'detail' => '?',
						],
					],
					Response::HTTP_BAD_REQUEST,
{'fraction_non_alphanumeric': 0.2401385414662305, 'fraction_numerical': 0.011160284779680585, 'mean_word_length': 2.0081018518518516, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 137, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1650559', 'n_tokens_mistral': 2642, 'n_tokens_neox': 1861, 'n_words': 302}