ProductRepository::findByMinimumValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
ccs 0
cts 7
cp 0
crap 2
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\Product;
6
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
7
use Doctrine\Persistence\ManagerRegistry;
8
9
/**
10
 * @extends ServiceEntityRepository<Product>
11
 */
12
class ProductRepository extends ServiceEntityRepository
13
{
14
    public function __construct(ManagerRegistry $registry)
15
    {
16
        parent::__construct($registry, Product::class);
17
    }
18
    /**
19
     * Find all products having a value above the specified one.
20
     *
21
     * @return Product[] Returns an array of Product objects
22
     */
23
    public function findByMinimumValue($value): array
24
    {
25
        return $this->createQueryBuilder('p')
26
            ->andWhere('p.value >= :value')
27
            ->setParameter('value', $value)
28
            ->orderBy('p.value', 'ASC')
29
            ->getQuery()
30
            ->getResult()
31
        ;
32
    }
33
    /**
34
     * Find all producs having a value above the specified one with SQL.
35
     *
36
     * @return array Returns an array of arrays (i.e. a raw data set)
37
     */
38
    public function findByMinimumValue2($value): array
39
    {
40
        $conn = $this->getEntityManager()->getConnection();
41
42
        $sql = '
43
            SELECT * FROM product AS p
44
            WHERE p.value >= :value
45
            ORDER BY p.value ASC
46
        ';
47
48
        $resultSet = $conn->executeQuery($sql, ['value' => $value]);
49
50
        return $resultSet->fetchAllAssociative();
51
    }
52
    //    /**
53
    //     * @return Product[] Returns an array of Product objects
54
    //     */
55
    //    public function findByExampleField($value): array
56
    //    {
57
    //        return $this->createQueryBuilder('p')
58
    //            ->andWhere('p.exampleField = :val')
59
    //            ->setParameter('val', $value)
60
    //            ->orderBy('p.id', 'ASC')
61
    //            ->setMaxResults(10)
62
    //            ->getQuery()
63
    //            ->getResult()
64
    //        ;
65
    //    }
66
67
    //    public function findOneBySomeField($value): ?Product
68
    //    {
69
    //        return $this->createQueryBuilder('p')
70
    //            ->andWhere('p.exampleField = :val')
71
    //            ->setParameter('val', $value)
72
    //            ->getQuery()
73
    //            ->getOneOrNullResult()
74
    //        ;
75
    //    }
76
}
77