|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Core\Entity; |
|
6
|
|
|
|
|
7
|
|
|
use Core\Entity\Collection\ArrayCollection; |
|
8
|
|
|
use Doctrine\Common\Collections\Collection; |
|
9
|
|
|
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; |
|
10
|
|
|
use MongoDB\BSON\ObjectId; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class ImageSet |
|
14
|
|
|
* |
|
15
|
|
|
* @ODM\EmbeddedDocument |
|
16
|
|
|
* |
|
17
|
|
|
* @package Core\Entity |
|
18
|
|
|
*/ |
|
19
|
|
|
class ImageSet implements ImageSetInterface |
|
20
|
|
|
{ |
|
21
|
|
|
use EntityTrait, IdentifiableEntityTrait; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Images in this set. |
|
25
|
|
|
* |
|
26
|
|
|
* @ODM\ReferenceMany(discriminatorField="_entity", cascade={"all"}, orphanRemoval=true) |
|
27
|
|
|
*/ |
|
28
|
|
|
protected Collection $images; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->images = new ArrayCollection(); |
|
33
|
|
|
$this->id = (string) new ObjectId(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function getId(): ?string |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->id; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return ArrayCollection|Collection |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getImages(): Collection |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->images; |
|
47
|
|
|
} |
|
48
|
14 |
|
|
|
49
|
|
|
public function setImages($images): self |
|
50
|
14 |
|
{ |
|
51
|
|
|
$this->images = $images; |
|
52
|
|
|
return $this; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function clear(): self |
|
56
|
|
|
{ |
|
57
|
|
|
$this->images->clear(); |
|
58
|
|
|
|
|
59
|
|
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function add(ImageInterface $image): self |
|
63
|
|
|
{ |
|
64
|
|
|
$images = $this->images; |
|
65
|
4 |
|
$metadata = $image->getMetadata(); |
|
66
|
|
|
if(!is_null($current = $this->get($metadata->getKey(), false))){ |
|
|
|
|
|
|
67
|
4 |
|
$index = $images->indexOf($current); |
|
68
|
1 |
|
$images->remove($index); |
|
69
|
1 |
|
} |
|
70
|
|
|
$images->add($image); |
|
71
|
1 |
|
return $this; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
3 |
|
public function get(string $key, bool $fallback = true): ?ImageInterface |
|
75
|
2 |
|
{ |
|
76
|
1 |
|
foreach($this->images as $image){ |
|
77
|
1 |
|
try{ |
|
78
|
|
|
if(!is_null($metadata = $image->getMetadata())){ |
|
79
|
|
|
if($metadata->getKey() === $key){ |
|
80
|
1 |
|
return $image; |
|
81
|
1 |
|
} |
|
82
|
|
|
} |
|
83
|
|
|
}catch (\Exception $e){ |
|
84
|
1 |
|
return null; |
|
85
|
1 |
|
} |
|
86
|
|
|
} |
|
87
|
|
|
return !$fallback || self::ORIGINAL == $key ? null : $this->get(self::ORIGINAL); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function getOriginal(): ?ImageInterface |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->get(self::ORIGINAL, false); |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
6 |
|
|
|
95
|
|
|
public function getThumbnail() |
|
96
|
6 |
|
{ |
|
97
|
3 |
|
return $this->get(self::THUMBNAIL); |
|
98
|
|
|
} |
|
99
|
|
|
} |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.