Completed
Pull Request — master (#1)
by
unknown
07:53
created

Wishlist::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusWishlistPlugin\Entity;
14
15
use Doctrine\Common\Collections\ArrayCollection;
16
use Doctrine\Common\Collections\Collection;
17
use Sylius\Component\Core\Model\ProductInterface;
18
use Sylius\Component\Core\Model\ShopUserInterface;
19
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
20
21
class Wishlist implements WishlistInterface
22
{
23
    /** @var int */
24
    protected $id;
25
26
    /** @var Collection|WishlistProductInterface[] */
27
    protected $wishlistProducts;
28
29
    /** @var ShopUserInterface|null */
30
    protected $shopUser;
31
32
    /** @var TokenInterface|null */
33
    protected $token;
34
35
    public function __construct()
36
    {
37
        $this->wishlistProducts = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type object<Doctrine\Common\C...hlistProductInterface>> of property $wishlistProducts.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
38
        $this->token = new WishlistToken();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \BitBag\SyliusWishli...\Entity\WishlistToken() of type object<BitBag\SyliusWish...n\Entity\WishlistToken> is incompatible with the declared type object<Symfony\Component...en\TokenInterface>|null of property $token.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
39
    }
40
41
    public function getId(): ?int
42
    {
43
        return $this->id;
44
    }
45
46
    public function getProducts(): Collection
47
    {
48
        $products = [];
49
50
        foreach ($this->wishlistProducts as $wishlistProduct) {
51
            $products[] = $wishlistProduct->getProduct();
52
        }
53
54
        return new ArrayCollection($products);
55
    }
56
57
    public function getWishlistProducts(): Collection
58
    {
59
        return $this->wishlistProducts;
60
    }
61
62
    public function hasProduct(ProductInterface $product): bool
63
    {
64
        foreach ($this->wishlistProducts as $wishlistProduct) {
65
            if ($product === $wishlistProduct->getProduct()) {
66
                return true;
67
            }
68
        }
69
70
        return false;
71
    }
72
73
    public function hasWishlistProduct(WishlistProductInterface $wishlistProduct): bool
74
    {
75
        return $this->wishlistProducts->contains($wishlistProduct);
76
    }
77
78
    public function addWishlistProduct(WishlistProductInterface $wishlistProduct): void
79
    {
80
        if (!$this->hasProduct($wishlistProduct->getProduct())) {
81
            $wishlistProduct->setWishlist($this);
82
            $this->wishlistProducts->add($wishlistProduct);
83
        }
84
    }
85
86
    public function getShopUser(): ?ShopUserInterface
87
    {
88
        return $this->shopUser;
89
    }
90
91
    public function setShopUser(ShopUserInterface $shopUser): void
92
    {
93
        $this->shopUser = $shopUser;
94
    }
95
96
    public function getToken(): string
97
    {
98
        return (string) $this->token;
99
    }
100
101
    public function setToken(string $token): void
102
    {
103
        $this->token = new WishlistToken($token);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \BitBag\SyliusWishli...y\WishlistToken($token) of type object<BitBag\SyliusWish...n\Entity\WishlistToken> is incompatible with the declared type object<Symfony\Component...en\TokenInterface>|null of property $token.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
104
    }
105
}
106