ProductRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
c 1
b 0
f 0
dl 0
loc 46
ccs 16
cts 16
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A findByMinimumValue2() 0 13 1
A findByMinimumValue() 0 9 1
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 10
    public function __construct(ManagerRegistry $registry)
15
    {
16 10
        parent::__construct($registry, Product::class);
17
    }
18
19
    /**
20
     * Find all products having a value above the specified one.
21
     *
22
     * @param int $value
23
     *
24
     * @return Product[] Returns an array of Product objects
25
     */
26 2
    public function findByMinimumValue($value): array
27
    {
28
        // @phpstan-ignore-next-line
29 2
        return $this->createQueryBuilder('p')
30 2
            ->andWhere('p.value >= :value')
31 2
            ->setParameter('value', $value)
32 2
            ->orderBy('p.value', 'ASC')
33 2
            ->getQuery()
34 2
            ->getResult()
35 2
        ;
36
    }
37
38
    /**
39
     * Find all products having a value above the specified one with SQL.
40
     *
41
     * @param int $value
42
     *
43
     * @return array<array<mixed>> Returns an array of arrays (i.e. a raw data set)
44
     */
45 2
    public function findByMinimumValue2($value): array
46
    {
47 2
        $conn = $this->getEntityManager()->getConnection();
48
49 2
        $sql = '
50
            SELECT * FROM product AS p
51
            WHERE p.value >= :value
52
            ORDER BY p.value ASC
53 2
        ';
54
55 2
        $resultSet = $conn->executeQuery($sql, ['value' => $value]);
56
57 2
        return $resultSet->fetchAllAssociative();
58
    }
59
60
    //    /**
61
    //     * @return Product[] Returns an array of Product objects
62
    //     */
63
    //    public function findByExampleField($value): array
64
    //    {
65
    //        return $this->createQueryBuilder('p')
66
    //            ->andWhere('p.exampleField = :val')
67
    //            ->setParameter('val', $value)
68
    //            ->orderBy('p.id', 'ASC')
69
    //            ->setMaxResults(10)
70
    //            ->getQuery()
71
    //            ->getResult()
72
    //        ;
73
    //    }
74
75
    //    public function findOneBySomeField($value): ?Product
76
    //    {
77
    //        return $this->createQueryBuilder('p')
78
    //            ->andWhere('p.exampleField = :val')
79
    //            ->setParameter('val', $value)
80
    //            ->getQuery()
81
    //            ->getOneOrNullResult()
82
    //        ;
83
    //    }
84
}
85