Skip to content

Commit 168225b

Browse files
committed
Simplify persistable example models
1 parent 334bfee commit 168225b

File tree

1 file changed

+6
-47
lines changed

1 file changed

+6
-47
lines changed

examples/persistable.php

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use MongoDB\Model\BSONArray;
1010
use UnexpectedValueException;
1111

12-
use function array_search;
1312
use function getenv;
1413
use function var_dump;
1514

@@ -21,10 +20,10 @@ class PersistableEntry implements Persistable
2120
private $id;
2221

2322
/** @var string */
24-
private $name;
23+
public $name;
2524

2625
/** @var array<PersistableEmail> */
27-
private $emails = [];
26+
public $emails = [];
2827

2928
public function __construct(string $name)
3029
{
@@ -37,36 +36,6 @@ public function getId(): ObjectId
3736
return $this->id;
3837
}
3938

40-
public function getName(): string
41-
{
42-
return $this->name;
43-
}
44-
45-
public function setName(string $name): void
46-
{
47-
$this->name = $name;
48-
}
49-
50-
public function getEmails(): array
51-
{
52-
return $this->emails;
53-
}
54-
55-
public function addEmail(PersistableEmail $email): void
56-
{
57-
$this->emails[] = $email;
58-
}
59-
60-
public function deleteEmail(PersistableEmail $email): void
61-
{
62-
$index = array_search($email, $this->emails, true);
63-
if ($index === false) {
64-
return;
65-
}
66-
67-
unset($this->emails[$index]);
68-
}
69-
7039
public function bsonSerialize(): object
7140
{
7241
return (object) [
@@ -97,27 +66,17 @@ public function bsonUnserialize(array $data): void
9766
class PersistableEmail implements Persistable
9867
{
9968
/** @var string */
100-
private $type;
69+
public $type;
10170

10271
/** @var string */
103-
private $address;
72+
public $address;
10473

10574
public function __construct(string $type, string $address)
10675
{
10776
$this->type = $type;
10877
$this->address = $address;
10978
}
11079

111-
public function getType(): string
112-
{
113-
return $this->type;
114-
}
115-
116-
public function getAddress(): string
117-
{
118-
return $this->address;
119-
}
120-
12180
public function bsonSerialize(): object
12281
{
12382
return (object) [
@@ -134,8 +93,8 @@ public function bsonUnserialize(array $data): void
13493
}
13594

13695
$entry = new PersistableEntry('alcaeus');
137-
$entry->addEmail(new PersistableEmail('work', '[email protected]'));
138-
$entry->addEmail(new PersistableEmail('private', '[email protected]'));
96+
$entry->emails[] = new PersistableEmail('work', '[email protected]');
97+
$entry->emails[] = new PersistableEmail('private', '[email protected]');
13998

14099
$client = new Client(getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1/');
141100

0 commit comments

Comments
 (0)