ProductRepository::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
ccs 0
cts 2
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
    /**
20
     * Find all producs having a value above the specified one.
21
     * 
22
     * @return Product[] Returns an array of Product objects
23
     */
24
    public function findByMinimumValue($value): array
25
    {
26
        return $this->createQueryBuilder('p')
27
            ->andWhere('p.value >= :value')
28
            ->setParameter('value', $value)
29
            ->orderBy('p.value', 'ASC')
30
            ->getQuery()
31
            ->getResult()
32
        ;
33
    }
34
35
    /**
36
     * Find all producs having a value above the specified one with SQL.
37
     * 
38
     * @return [][] Returns an array of arrays (i.e. a raw data set)
0 ignored issues
show
Documentation Bug introduced by
The doc comment [][] at position 0 could not be parsed: Unknown type name '[' at position 0 in [][].
Loading history...
39
     */
40
    public function findByMinimumValue2($value): array
41
    {
42
        $conn = $this->getEntityManager()->getConnection();
43
44
        $sql = '
45
            SELECT * FROM product AS p
46
            WHERE p.value >= :value
47
            ORDER BY p.value ASC
48
        ';
49
50
        $resultSet = $conn->executeQuery($sql, ['value' => $value]);
51
52
        return $resultSet->fetchAllAssociative();
53
    }
54
55
    //    /**
56
    //     * @return Product[] Returns an array of Product objects
57
    //     */
58
    //    public function findByExampleField($value): array
59
    //    {
60
    //        return $this->createQueryBuilder('p')
61
    //            ->andWhere('p.exampleField = :val')
62
    //            ->setParameter('val', $value)
63
    //            ->orderBy('p.id', 'ASC')
64
    //            ->setMaxResults(10)
65
    //            ->getQuery()
66
    //            ->getResult()
67
    //        ;
68
    //    }
69
70
    //    public function findOneBySomeField($value): ?Product
71
    //    {
72
    //        return $this->createQueryBuilder('p')
73
    //            ->andWhere('p.exampleField = :val')
74
    //            ->setParameter('val', $value)
75
    //            ->getQuery()
76
    //            ->getOneOrNullResult()
77
    //        ;
78
    //    }
79
}
80