<commit_before><?php

session_start();

if (isset($_POST['id']) && isset($_POST['amount'])) {
  $id = $_POST['id'];
  $amount = $_POST['amount'];

  if (!isset($_SESSION['cart'])) {
    $cart = [];
  } else {
    $cart = $_SESSION['cart'];
  }

  if (!empty($id) && $amount > 0) {
    $cart[$id] += $amount;

    $_SESSION['cart'] = $cart;

    $response = [
      'error' => false,
      'id' => $id,
      'totalAmount' => $cart[$id],
      'msg' => 'Amount was added to cart.'
    ];
  } else {
    $response = [
      'error' => true,
      'msg' => 'Zero and negative amounts forbidden.'
    ];
  }
} else {
  $response = [
    'error' => true,
    'msg' => 'Fatal error'
  ];
}

header('Content-Type: application/json');
echo json_encode($response);

?>
<commit_msg>fixed bad code<commit_after><?php

session_start();

if (isset($_POST['id']) && isset($_POST['amount'])) {
  $id = $_POST['id'];
  $amount = $_POST['amount'];

  if (!isset($_SESSION['cart'])) {
    $cart = [];
  } else {
    $cart = $_SESSION['cart'];
  }

  if (!empty($id) && $amount > 0) {

		if (isset($cart[$id])) {
			$cart[$id] += $amount;
		} else {
			$cart[$id] = $amount;
		}

    $_SESSION['cart'] = $cart;

    $response = [
      'error' => false,
      'id' => $id,
      'totalAmount' => $cart[$id],
      'msg' => 'Amount was added to cart.'
    ];
  } else {
    $response = [
      'error' => true,
      'msg' => 'Zero and negative amounts forbidden.'
    ];
  }
} else {
  $response = [
    'error' => true,
    'msg' => 'Fatal error'
  ];
}

header('Content-Type: application/json');
echo json_encode($response);

?>

{'fraction_non_alphanumeric': 0.22516166960611406, 'fraction_numerical': 0.0011757789535567313, 'mean_word_length': 2.2667946257197698, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2834360', 'n_tokens_mistral': 644, 'n_tokens_neox': 585, 'n_words': 121}