<commit_before><?php

$app->get('/departments', function() use ($app) {
  $page = $app->request->getQuery('page', 'int', 1);
  $startRecord = ($page - 1) * PER_PAGE;

  // Query
  $queryString = array();
  $queryData = array();
  $name = $app->request->getQuery('name');

  if($name) {
    array_push($queryString, 'name LIKE :name:');
    $queryData['name'] = '%' . $name . '%';
  }

  if(count($queryString) > 0) {
    $queryCache = implode(" AND ", $queryString);
    $queryString = " WHERE {$queryCache}";
    unset($queryCache);
  } else {
    $queryString = "";
  }

  $phql = "SELECT * FROM Departments{$queryString} LIMIT {$startRecord}, " . PER_PAGE;
  $departments = $app->modelsManager->executeQuery($phql, $queryData);

  return $app->response->setJsonContent($departments->toArray());
});

$app->get('/department/{code:[0-9]+}', function($code) use ($app) {
  $phql = "SELECT * FROM Departments WHERE code = :code:";
  $department = $app->modelsManager->executeQuery($phql, array('code' => $code));

  return $app->response->setJsonContent($department->toArray());
<commit_msg>Refactor# refactor department query via QueryHelper<commit_after><?php

$app->get('/departments', function() use ($app) {

  $queryHelper = $app->queryHelper;
  $queryHelper->setModel(Departments::query());
  $queryHelper->addFilter('name');
  $queryHelper->usePage(PER_PAGE);

  return $app->response->setJsonContent($queryHelper->result());
});

$app->get('/department/{code:[0-9]+}', function($code) use ($app) {

  $queryHelper = $app->queryHelper;
  $queryHelper->setModel(Departments::query());
  $queryHelper->addFilter('code', QueryHelper::FILTER_SIMPLE, $code);

  return $app->response->setJsonContent($queryHelper->result());

{'fraction_non_alphanumeric': 0.21482339316734222, 'fraction_numerical': 0.004053271569195136, 'mean_word_length': 5.23826714801444, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, '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': '3915068', 'n_tokens_mistral': 588, 'n_tokens_neox': 564, 'n_words': 97}