<commit_before><?php
/**
 * @package        Precincts
 * @category       modules
 * @author         <NAME> <<EMAIL>>
 * @copyright      Copyright (c) 2014, <NAME>
 * @license        MIT License, see license.txt
 */
namespace cs\modules\Precincts;

use
	cs\Index,
	cs\Page,
	cs\User;

$Index = Index::instance();
$User  = User::instance();
if (!$User->user()) {
	error_code(403);
	return;
}
if (
	!isset($Index->route_ids[0], $_POST['text'], $_POST['images'], $_POST['video']) ||
	(
		empty($_POST['text']) &&
		empty($_POST['images']) &&
		empty($_POST['video'])
	)
) {
	error_code(400);
	return;
}
$Violations = Violations::instance();
$id         = $Violations->add(
	$Index->route_ids[0],
	$User->id,
	$_POST['text'],
	(array)$_POST['images'],
	$_POST['video']
);
if (!$id) {
	error_code(500);
}
Page::instance()->json($id);
<commit_msg>Optional parameters can be omitted in POST api/Precincts/{id}/violations<commit_after><?php
/**
 * @package        Precincts
 * @category       modules
 * @author         <NAME> <<EMAIL>>
 * @copyright      Copyright (c) 2014, <NAME>
 * @license        MIT License, see license.txt
 */
namespace cs\modules\Precincts;

use
	cs\Index,
	cs\Page,
	cs\User;

$Index = Index::instance();
$User  = User::instance();
if (!$User->user()) {
	error_code(403);
	return;
}
if (
	!isset($Index->route_ids[0]) ||
	(
		(
			!isset($_POST['text']) || empty($_POST['text'])
		) &&
		(
			!isset($_POST['images']) || empty($_POST['images'])
		) &&
		(
			!isset($_POST['video']) || empty($_POST['video'])
		)
	)
) {
	error_code(400);
	return;
}
$Violations = Violations::instance();
$id         = $Violations->add(
	$Index->route_ids[0],
	$User->id,
	isset($_POST['text']) ? $_POST['text'] : '',
	isset($_POST['images']) ? (array)$_POST['images'] : [],
	isset($_POST['video']) ? $_POST['video'] : ''
);
if (!$id) {
	error_code(500);
}
Page::instance()->json($id);

{'fraction_non_alphanumeric': 0.23753976670201485, 'fraction_numerical': 0.015906680805938492, 'mean_word_length': 3.978891820580475, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, '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': '1365789', 'n_tokens_mistral': 734, 'n_tokens_neox': 696, 'n_words': 120}