Skip to content

Commit 97bc172

Browse files
author
liquetsoft
committed
add description for field
1 parent 6a69ce1 commit 97bc172

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/EntityField/BaseEntityField.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ class BaseEntityField implements EntityField
1616
*/
1717
protected $name;
1818

19+
/**
20+
* @var string
21+
*/
22+
protected $description;
23+
1924
/**
2025
* @var string
2126
*/
@@ -59,6 +64,7 @@ class BaseEntityField implements EntityField
5964
public function __construct(array $p)
6065
{
6166
$this->name = $this->extractStringFromOptions($p, 'name', true);
67+
$this->description = $this->extractStringFromOptions($p, 'description');
6268
$this->type = $this->extractStringFromOptions($p, 'type', true);
6369
$this->subType = $this->extractStringFromOptions($p, 'subType');
6470
$this->length = isset($p['length']) ? (int) $p['length'] : null;
@@ -82,6 +88,14 @@ public function getName(): string
8288
return $this->name;
8389
}
8490

91+
/**
92+
* @inheritdoc
93+
*/
94+
public function getDescription(): string
95+
{
96+
return $this->description;
97+
}
98+
8599
/**
86100
* @inheritdoc
87101
*/

src/EntityField/EntityField.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ interface EntityField
1616
*/
1717
public function getName(): string;
1818

19+
/**
20+
* Возвращает описание поля.
21+
*
22+
* @return string
23+
*/
24+
public function getDescription(): string;
25+
1926
/**
2027
* Возвращает тип поля.
2128
*

tests/src/EntityField/BaseEntityFieldTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,27 @@ public function testGetName()
2727
$this->assertSame($name, $field->getName());
2828
}
2929

30+
/**
31+
* Проверяет, что объект правильно вернет описание поля.
32+
*/
33+
public function testGetDescription()
34+
{
35+
$description = $this->createFakeData()->word;
36+
37+
$field = $this->createField([
38+
'description' => $description,
39+
]);
40+
41+
$this->assertSame($description, $field->getDescription());
42+
}
43+
3044
/**
3145
* Проверяет, что объект правильно выбросит исключение, если имя не задано.
3246
*/
3347
public function testEmptyNameException()
3448
{
3549
$this->expectException(InvalidArgumentException::class);
36-
$field = $this->createField([
50+
$this->createField([
3751
'name' => null,
3852
]);
3953
}

0 commit comments

Comments
 (0)