<commit_before><?php

namespace AppBundle\API\Details;

use AppBundle\API\Webservice;
use \PDO as PDO;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

/**
 * Web Service.
 * Returns Organisms that posess a given trait
 */
class OrganismsWithTrait extends Webservice
{
    const DEFAULT_LIMIT = 100;

    /**
     * @param $query ParameterBag $query[type_cvterm_id] array of trait type_cvterm_id
     * @param $session SessionInterface|null
     * @returns array of organisms accoring to a specific trait type
     */
    public function execute(ParameterBag $query, SessionInterface $session = null)
    {
        $db = $this->getDbFromQuery($query);
        $trait_type_id = $query->get('trait_type_id');
        $limit = OrganismsWithTrait::DEFAULT_LIMIT;
        if ($query->has('limit')) {
            $limit = $query->get('limit');
        }
        
        $query_get_organism_by_trait = <<<EOF
SELECT *
    FROM organism, (SELECT DISTINCT organism_id FROM trait_categorical_entry WHERE trait_type_id = :trait_type_id) AS ids
    WHERE organism.organism_id = ids.organism_id LIMIT :limit
EOF;
        $stm_get_organism_by_trait = $db->prepare($query_get_organism_by_trait);
        $stm_get_organism_by_trait->bindValue('trait_type_id', $trait_type_id);
        $stm_get_organism_by_trait->bindValue('limit', $limit);
        $stm_get_organism_by_trait->execute();
        
        $data = array();
        
        while ($row = $stm_get_organism_by_trait->fetch(PDO::FETCH_ASSOC)) {
            $result = array();
            $result['organism_id'] = $row['organism_id'];
            $result['scientific_name'] = $row['species'];
            $result['rank'] = $row['genus'];
            $result['common_name'] = $row['common_name'];
            if ($row["abbreviation"]!=null) {
                $result['rank']='species';
            }
            $data[] = $result;
        }
        return $data;
        <commit_msg>Make OrganismsWithTrait test pass<commit_after><?php

namespace AppBundle\API\Details;

use AppBundle\API\Webservice;
use \PDO as PDO;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

/**
 * Web Service.
 * Returns Organisms that posess a given trait
 */
class OrganismsWithTrait extends Webservice
{
    const DEFAULT_LIMIT = 100;

    /**
     * @param $query ParameterBag $query[type_cvterm_id] array of trait type_cvterm_id
     * @param $session SessionInterface|null
     * @returns array of organisms accoring to a specific trait type
     */
    public function execute(ParameterBag $query, SessionInterface $session = null)
    {
        $db = $this->getDbFromQuery($query);
        $trait_type_id = $query->get('trait_type_id');
        $limit = OrganismsWithTrait::DEFAULT_LIMIT;
        if ($query->has('limit')) {
            $limit = $query->get('limit');
        }
        
        $query_get_organism_by_trait = <<<EOF
SELECT *
    FROM organism, (SELECT DISTINCT fennec_id FROM trait_categorical_entry WHERE trait_type_id = :trait_type_id) AS ids
    WHERE organism.fennec_id = ids.fennec_id LIMIT :limit
EOF;
        $stm_get_organism_by_trait = $db->prepare($query_get_organism_by_trait);
        $stm_get_organism_by_trait->bindValue('trait_type_id', $trait_type_id);
        $stm_get_organism_by_trait->bindValue('limit', $limit);
        $stm_get_organism_by_trait->execute();
        
        $data = array();
        
        while ($row = $stm_get_organism_by_trait->fetch(PDO::FETCH_ASSOC)) {
            $result = array();
            $result['fennec_id'] = $row['fennec_id'];
            $result['scientific_name'] = $row['scientific_name'];
            $data[] = $result;
        }
        return $data;
        
{'fraction_non_alphanumeric': 0.12098895318253551, 'fraction_numerical': 0.0015781167806417674, 'mean_word_length': 3.067379679144385, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, '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': '127899', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1209, 'n_words': 230}