ItemCollectionRepository::__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
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\Collection;
6
use App\Entity\Item;
7
use App\Entity\ItemCollection;
8
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
9
use Doctrine\Common\Persistence\ManagerRegistry;
0 ignored issues
show
Bug introduced by
The type Doctrine\Common\Persistence\ManagerRegistry was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Doctrine\ORM\ORMException;
11
use Doctrine\ORM\OptimisticLockException;
12
use App\Repository\Exception\ItemCollectionNotFoundException;
13
14
/**
15
 * @method ItemCollection|null find($id, $lockMode = null, $lockVersion = null)
16
 * @method ItemCollection|null findOneBy(array $criteria, array $orderBy = null)
17
 * @method ItemCollection[]    findAll()
18
 * @method ItemCollection[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
19
 */
20
class ItemCollectionRepository extends ServiceEntityRepository
21
{
22
    /**
23
     * @param ManagerRegistry $registry
24
     */
25
    public function __construct(ManagerRegistry $registry)
26
    {
27
        parent::__construct($registry, ItemCollection::class);
28
    }
29
30
    /**
31
     * @param Item $item
32
     * @param Collection $collection
33
     * @throws ItemCollectionNotFoundException
34
     * @return itemCollection
35
     */
36
    public function getItemCollection(Item $item, Collection $collection): ItemCollection
37
    {
38
        if ($itemCollection = $this->findOneBy(['item'=> $item, 'collection'=>$collection])) {
39
            return $itemCollection;
40
        }
41
42
        throw new ItemCollectionNotFoundException('itemCollection not found');
43
    }
44
    
45
    /**
46
     * @param ItemCollection $itemCollection
47
     * @throws \Doctrine\ORM\ORMException
48
     * @throws \Doctrine\ORM\OptimisticLockException
49
     */
50
    public function save(ItemCollection $itemCollection): void
51
    {
52
        $em = $this->getEntityManager();
53
        $em->persist($itemCollection);
54
        $em->flush();
55
    }
56
    
57
    /**
58
     * @param ItemCollection $itemCollection
59
     * @throws ORMException
60
     * @throws OptimisticLockException
61
     */
62
    public function delete(ItemCollection $itemCollection): void
63
    {
64
        $em = $this->getEntityManager();
65
        $em->remove($itemCollection);
66
        $em->flush();
67
    }
68
    
69
    /**
70
     * @param Item $item
71
     * @param Collection $collection
72
     * @return \App\Entity\ItemCollection|NULL
73
     */
74
    public function findItemCollection(Item $item, Collection $collection): ?ItemCollection
75
    {
76
        return $this->findOneBy(['item' => $item, 'collection' => $collection]);
77
    }
78
}
79