BookRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A findByIsbn() 0 8 1
A reset() 0 14 1
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\Book;
6
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
7
use Doctrine\Persistence\ManagerRegistry;
8
9
/**
10
 * @extends ServiceEntityRepository<Book>
11
 */
12
class BookRepository extends ServiceEntityRepository
13
{
14
    public function __construct(ManagerRegistry $registry)
15
    {
16
        parent::__construct($registry, Book::class);
17
    }
18
    public function findByIsbn(string $isbn): ?Book
19
    {
20
        /** @phpstan-ignore-next-line */
21
        return $this->createQueryBuilder('b')
22
            ->andWhere('b.isbn = :val')
23
            ->setParameter('val', $isbn)
24
            ->getQuery()
25
            ->getOneOrNullResult()
26
        ;
27
    }
28
    public function reset(): void
29
    {
30
        $conn = $this->getEntityManager()->getConnection();
31
        $sql = "
32
            DELETE FROM book;
33
            INSERT INTO book (title, isbn, author, image) 
34
            VALUES
35
                ('Around the World in Eighty Days','978-1949460858','Jules Verne','80days.jpg'),
36
                ('Krig och fred. Vol 1, 1805','978-9174619249','Leo Tolstoy','kf1.jpg'),
37
                ('Krig och fred. Vol 2, 1806-1812','978-9174619256','Leo Tolstoy','kf2.jpg'),
38
                ('Krig och fred. Vol 3, 1812','978-9174619263','Leo Tolstoy','kf3.jpg'),
39
                ('Krig och fred. Vol 4, 1812-1813 / Epilog','978-9174619270','Leo Tolstoy','kf4.jpg');
40
            ";
41
        $conn->executeQuery($sql);
42
43
    }
44
45
    //    /**
46
    //     * @return Book[] Returns an array of Book objects
47
    //     */
48
    //    public function findByExampleField($value): array
49
    //    {
50
    //        return $this->createQueryBuilder('b')
51
    //            ->andWhere('b.exampleField = :val')
52
    //            ->setParameter('val', $value)
53
    //            ->orderBy('b.id', 'ASC')
54
    //            ->setMaxResults(10)
55
    //            ->getQuery()
56
    //            ->getResult()
57
    //        ;
58
    //    }
59
60
    //    public function findOneBySomeField($value): ?Book
61
    //    {
62
    //        return $this->createQueryBuilder('b')
63
    //            ->andWhere('b.exampleField = :val')
64
    //            ->setParameter('val', $value)
65
    //            ->getQuery()
66
    //            ->getOneOrNullResult()
67
    //        ;
68
    //    }
69
}
70