Skip to content

Commit fe961c8

Browse files
committed
add and polish phpdocs
1 parent 04f9be6 commit fe961c8

File tree

4 files changed

+376
-6
lines changed

4 files changed

+376
-6
lines changed

src/Builder/DatabaseBuilder.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@
1111
*/
1212
class DatabaseBuilder
1313
{
14+
/**
15+
* @var array
16+
*/
1417
private array $payload;
1518

19+
/**
20+
* DatabaseBuilder constructor.
21+
* @param Databases $databasesEndpoint
22+
*/
1623
public function __construct(private Databases $databasesEndpoint)
1724
{
1825
$this->payload = [
@@ -29,6 +36,12 @@ public function __construct(private Databases $databasesEndpoint)
2936
];
3037
}
3138

39+
/**
40+
* Creates database within given page.
41+
*
42+
* @param string $pageId
43+
* @return Database
44+
*/
3245
public function createInPage($pageId): Database
3346
{
3447
$this->payload['parent'] = [
@@ -43,6 +56,12 @@ public function createInPage($pageId): Database
4356
return $this->databasesEndpoint->create($this->payload());
4457
}
4558

59+
/**
60+
* Sets the title for the database creation.
61+
*
62+
* @param string $title
63+
* @return DatabaseBuilder
64+
*/
4665
public function title(string $title): DatabaseBuilder
4766
{
4867
$this->payload['title'] = [
@@ -56,6 +75,12 @@ public function title(string $title): DatabaseBuilder
5675
return $this;
5776
}
5877

78+
/**
79+
* Sets the description for the database creation.
80+
*
81+
* @param string $description
82+
* @return DatabaseBuilder
83+
*/
5984
public function description(string $description): DatabaseBuilder
6085
{
6186
$this->payload['description'] = [
@@ -69,13 +94,25 @@ public function description(string $description): DatabaseBuilder
6994
return $this;
7095
}
7196

97+
/**
98+
* Sets the created database as inline (currently not supported).
99+
* @todo increase Notion API Version, to make this work
100+
*
101+
* @return DatabaseBuilder
102+
*/
72103
public function inline(): DatabaseBuilder
73104
{
74105
$this->payload['is_inline'] = true;
75106

76107
return $this;
77108
}
78109

110+
/**
111+
* Sets the icon for the database creation.
112+
*
113+
* @param string $icon
114+
* @return DatabaseBuilder
115+
*/
79116
public function iconEmoji(string $icon): DatabaseBuilder
80117
{
81118
$this->payload['icon'] = [
@@ -86,6 +123,12 @@ public function iconEmoji(string $icon): DatabaseBuilder
86123
return $this;
87124
}
88125

126+
/**
127+
* Sets the icon for the database creation.
128+
*
129+
* @param string $url
130+
* @return DatabaseBuilder
131+
*/
89132
public function iconExternal(string $url): DatabaseBuilder
90133
{
91134
$this->payload['icon'] = [
@@ -98,6 +141,12 @@ public function iconExternal(string $url): DatabaseBuilder
98141
return $this;
99142
}
100143

144+
/**
145+
* Sets the cover for the database creation.
146+
*
147+
* @param string $url
148+
* @return DatabaseBuilder
149+
*/
101150
public function coverExternal(string $url): DatabaseBuilder
102151
{
103152
$this->payload['cover'] = [
@@ -110,13 +159,25 @@ public function coverExternal(string $url): DatabaseBuilder
110159
return $this;
111160
}
112161

162+
/**
163+
* Adds the property `title` database creation.
164+
*
165+
* @param string $name
166+
* @return DatabaseBuilder
167+
*/
113168
public function addTitle(string $name = 'Name')
114169
{
115170
$this->add(PropertyBuilder::title($name));
116171

117172
return $this;
118173
}
119174

175+
/**
176+
* Adds one or multiple properties to the database creation.
177+
*
178+
* @param PropertyBuilder|Collection|DatabaseSchemeBuilder $properties
179+
* @return DatabaseBuilder
180+
*/
120181
public function add(PropertyBuilder|Collection|DatabaseSchemeBuilder $properties): DatabaseBuilder
121182
{
122183
if ($properties instanceof PropertyBuilder) {
@@ -134,6 +195,12 @@ public function add(PropertyBuilder|Collection|DatabaseSchemeBuilder $properties
134195
return $this;
135196
}
136197

198+
/**
199+
* Adds multiple properties to the database creation, similar to a Laravel migration.
200+
*
201+
* @param callable $callback
202+
* @return DatabaseBuilder
203+
*/
137204
public function scheme(callable $callback): DatabaseBuilder
138205
{
139206
$builder = new DatabaseSchemeBuilder();
@@ -142,6 +209,14 @@ public function scheme(callable $callback): DatabaseBuilder
142209
return $this->add($builder);
143210
}
144211

212+
/**
213+
* Adds a raw property to the database creation.
214+
*
215+
* @param string $title
216+
* @param string $propertyType
217+
* @param array|null $content
218+
* @return DatabaseBuilder
219+
*/
145220
public function addRaw(string $title, string $propertyType, array $content = null): DatabaseBuilder
146221
{
147222
$this->payload['properties'][$title] = [];
@@ -150,6 +225,11 @@ public function addRaw(string $title, string $propertyType, array $content = nul
150225
return $this;
151226
}
152227

228+
/**
229+
* Returns the payload for the database creation.
230+
*
231+
* @return array
232+
*/
153233
public function payload(): array
154234
{
155235
return $this->payload;

0 commit comments

Comments
 (0)