BookRepository   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 23
c 4
b 0
f 0
dl 0
loc 91
rs 10
ccs 0
cts 30
cp 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A remove() 0 6 2
A create() 0 19 1
A drop() 0 10 1
A insert() 0 16 1
A __construct() 0 3 1
A save() 0 6 2
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\Main\Book;
6
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
7
use Doctrine\Persistence\ManagerRegistry;
8
9
/**
10
 * @extends ServiceEntityRepository<Book>
11
 *
12
 * @method Book|null find($id, $lockMode = null, $lockVersion = null)
13
 * @method Book|null findOneBy(array $criteria, array $orderBy = null)
14
 * @method Book[]    findAll()
15
 * @method Book[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
16
 */
17
class BookRepository extends ServiceEntityRepository
18
{
19
    public function __construct(ManagerRegistry $registry)
20
    {
21
        parent::__construct($registry, Book::class);
22
    }
23
24
    /** @SuppressWarnings(PHPMD.BooleanArgumentFlag) */
25
    public function save(Book $entity, bool $flush = false): void
26
    {
27
        $this->getEntityManager()->persist($entity);
28
29
        if ($flush) {
30
            $this->getEntityManager()->flush();
31
        }
32
    }
33
34
    /** @SuppressWarnings(PHPMD.BooleanArgumentFlag) */
35
    public function remove(Book $entity, bool $flush = false): void
36
    {
37
        $this->getEntityManager()->remove($entity);
38
39
        if ($flush) {
40
            $this->getEntityManager()->flush();
41
        }
42
    }
43
44
    /**
45
     * Drop book table.
46
     *
47
     * @return mixed[] as the result of query.
48
     */
49
    public function drop(): array
50
    {
51
        $conn = $this->getEntityManager()->getConnection();
52
53
        $sql = "DROP TABLE IF EXISTS book;";
54
55
        $stmt = $conn->prepare($sql);
56
        $resultSet = $stmt->executeQuery();
57
58
        return $resultSet->fetchAllAssociative();
59
    }
60
61
    /**
62
     * Create book table.
63
     *
64
     * @return mixed[] as the result of query.
65
     */
66
    public function create(): array
67
    {
68
        $conn = $this->getEntityManager()->getConnection();
69
70
        $sql = "
71
            CREATE TABLE book (
72
                id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
73
                title VARCHAR(255) NOT NULL,
74
                description CLOB NOT NULL,
75
                isbn CHAR(13) NOT NULL,
76
                author VARCHAR(255) NOT NULL,
77
                image_url VARCHAR(255) NOT NULL
78
            );
79
        ";
80
81
        $stmt = $conn->prepare($sql);
82
        $resultSet = $stmt->executeQuery();
83
84
        return $resultSet->fetchAllAssociative();
85
    }
86
87
    /**
88
     * Insert default values into book table.
89
     *
90
     * @return mixed[] as the result of query.
91
     */
92
    public function insert(): array
93
    {
94
        $conn = $this->getEntityManager()->getConnection();
95
96
        $sql = "
97
            INSERT INTO book VALUES
98
            (4,'The Joy of Debugging','\"The Joy of Debugging\" is a fun and motivational guide to the often-frustrating process of debugging code. The book is filled with humorous anecdotes, practical tips, and inspiring stories from experienced developers who have overcome even the most stubborn bugs. With a focus on positive thinking and a can-do attitude, \"The Joy of Debugging\" encourages readers to embrace the challenge of debugging and approach it with enthusiasm and creativity. Whether you are a seasoned developer or just starting out, \"The Joy of Debugging\" will help you unlock the joy and satisfaction that comes from successfully fixing a stubborn bug.','3333333333333','Haskell Backslash','https://ucarecdn.com/df36fae6-bdd3-4d1c-b36d-f6d521efd2e9/the_joy_of_debugging.png'),
99
            (5,'The Phantom Programmer: A D.B. Webber Adventure','A Shadowy Software Thriller and the first book of the D.B. Webber series. A software developer named Ada Lovejoy, is tasked with creating a new, cutting-edge program for a major tech company. But as she delves deeper into the project, strange things begin to happen. Code appears in the program that she does not remember writing, and her coworkers start to disappear one by one. Ada soon realizes that she''s being targeted by a mysterious hacker, known only as the Phantom Programmer, who seems to be able to manipulate the code itself. D.B. Webber is called in to solve the case. As he races to uncover the identity of the Phantom Programmer and stop them before they can cause any more harm, he realizes that he may be in over his head in a world of high-tech intrigue and danger.','2222222222222','Pythonia Jones','https://ucarecdn.com/e8bcdb1f-f42e-4876-aeb4-f0b7246876ed/d_b_webber.png'),
100
            (6,'When Code Breaks','\"When Code Breaks\" is a lighthearted, humorous look at the life of a programmer. The book follows the misadventures of Jake, a quirky and somewhat clumsy programmer, as he navigates the highs and lows of the tech industry. From debugging seemingly impossible code errors to dealing with difficult clients, his life is never dull. But despite the challenges he faces, Jake is always able to find humor in even the most frustrating situations. With plenty of jokes and relatable anecdotes, \"When Code Breaks\" is the perfect read for anyone who has ever spent hours staring at a screen trying to fix their broken code.','1111111111111','Bob Rossbach ','https://ucarecdn.com/c0894e3e-3694-4771-aabf-83a7f5a59770/when_code_breaks.png'),
101
            (7,'The History of Naming Variables','\"The History of Naming Variables\" is a hilarious take on the often-overlooked skill of naming variables. The book starts with a tongue-in-cheek examination of the ancient art of naming variables, including examples from Babylonian cuneiform tablets and Egyptian hieroglyphics. From there, it moves on to the more recent history of variable naming, including the evolution of programming languages and their associated naming conventions. Along the way, the book pokes fun at some of the more ridiculous variable names that have been used over the years. \"The History of Naming Variables\" is a must-read for anyone who has ever struggled to come up with the perfect variable name.','4444444444444','Dr. Hax','https://ucarecdn.com/1cfb66cd-77d2-4808-8aa3-89780239c885/history_of_naming_variables.png');
102
        ";
103
104
        $stmt = $conn->prepare($sql);
105
        $resultSet = $stmt->executeQuery();
106
107
        return $resultSet->fetchAllAssociative();
108
    }
109
110
//    /**
111
//     * @return Book[] Returns an array of Book objects
112
//     */
113
//    public function findByExampleField($value): array
114
//    {
115
//        return $this->createQueryBuilder('b')
116
//            ->andWhere('b.exampleField = :val')
117
//            ->setParameter('val', $value)
118
//            ->orderBy('b.id', 'ASC')
119
//            ->setMaxResults(10)
120
//            ->getQuery()
121
//            ->getResult()
122
//        ;
123
//    }
124
125
//    public function findOneBySomeField($value): ?Book
126
//    {
127
//        return $this->createQueryBuilder('b')
128
//            ->andWhere('b.exampleField = :val')
129
//            ->setParameter('val', $value)
130
//            ->getQuery()
131
//            ->getOneOrNullResult()
132
//        ;
133
//    }
134
}
135