original_string: public function findSameCategoryProduct($product, $direction)
      {
          $qb = $this->getQueryBuilder()
              ->select('p')
              ->andWhere('p.category = :category')
              ->setMaxResults(1)
              ->setParameter('category', $product->getCategory());
  
          if ('next' == $direction) {
              $qb->andWhere('p.id > :id')
                  ->orderBy('p.id', 'asc');
          } else {
              $qb->andWhere('p.id < :id')
                  ->orderBy('p.id', 'desc');
          }
  
          $qb->setParameter('id', $product->getId());
  
          if (0 == count($qb->getQuery()->getResult())) {
              return null;
          }
  
          return $qb->getQuery()
              ->getSingleResult();
      }
code: public function findSameCategoryProduct($product, $direction)
      {
          $qb = $this->getQueryBuilder()
              ->select('p')
              ->andWhere('p.category = :category')
              ->setMaxResults(1)
              ->setParameter('category', $product->getCategory());
  
          if ('next' == $direction) {
              $qb->andWhere('p.id > :id')
                  ->orderBy('p.id', 'asc');
          } else {
              $qb->andWhere('p.id < :id')
                  ->orderBy('p.id', 'desc');
          }
  
          $qb->setParameter('id', $product->getId());
  
          if (0 == count($qb->getQuery()->getResult())) {
              return null;
          }
  
          return $qb->getQuery()
              ->getSingleResult();
      }
code_tokens: public function findSameCategoryProduct ( $ product , $ direction ) { $ qb = $ this -> getQueryBuilder ( ) -> select ( 'p' ) -> andWhere ( 'p.category = :category' ) -> setMaxResults ( 1 ) -> setParameter ( 'category' , $ product -> getCategory ( ) ) ; if ( 'next' == $ direction ) { $ qb -> andWhere ( 'p.id > :id' ) -> orderBy ( 'p.id' , 'asc' ) ; } else { $ qb -> andWhere ( 'p.id < :id' ) -> orderBy ( 'p.id' , 'desc' ) ; } $ qb -> setParameter ( 'id' , $ product -> getId ( ) ) ; if ( 0 == count ( $ qb -> getQuery ( ) -> getResult ( ) ) ) { return null ; } return $ qb -> getQuery ( ) -> getSingleResult ( ) ; }
docstring: Find a product from the same category
  
  @param Product $product
  @param string  $direction
  
  @return Product|null
docstring_tokens: Find a product from the same category