Skip to content

Commit 81cbb5b

Browse files
committed
fix: some models are extension of other models
1 parent f76957a commit 81cbb5b

File tree

6 files changed

+19
-8
lines changed

6 files changed

+19
-8
lines changed

src/Models/Admin/TagModel.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
namespace Vazaha\Mastodon\Models\Admin;
1010

11-
use Vazaha\Mastodon\Models\Model;
11+
use Vazaha\Mastodon\Models\TagModel as ModelsTagModel;
1212

1313
/**
1414
* Represents a hashtag used within the content of a status.
1515
*/
16-
class TagModel extends Model
16+
class TagModel extends ModelsTagModel
1717
{
1818
/**
1919
* The ID of the Tag in the database.

src/Models/CredentialAccountModel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* Represents a user of Mastodon and their associated profile.
1313
*/
14-
class CredentialAccountModel extends Model
14+
class CredentialAccountModel extends AccountModel
1515
{
1616
/**
1717
* An extra attribute that contains source values to be used with API methods

src/Models/MutedAccountModel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* Represents a user of Mastodon and their associated profile.
1515
*/
16-
class MutedAccountModel extends Model
16+
class MutedAccountModel extends AccountModel
1717
{
1818
/**
1919
* When a timed mute will expire, if applicable.

src/Models/Trends/LinkModel.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
namespace Vazaha\Mastodon\Models\Trends;
1010

11-
use Vazaha\Mastodon\Models\Model;
11+
use Vazaha\Mastodon\Models\PreviewCardModel;
1212

1313
/**
1414
* Represents a rich preview card that is generated using OpenGraph tags from a URL.
1515
*/
16-
class LinkModel extends Model
16+
class LinkModel extends PreviewCardModel
1717
{
1818
/**
1919
* Usage statistics for given days (typically the past week).

tools/src/ModelClassTemplate.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,26 @@ class ModelClassTemplate extends ClassTemplate
1616

1717
protected function getTemplateVars(): array
1818
{
19-
$specs = $this->loadEntitySpecs();
19+
$this->loadEntitySpecs();
2020
$this->imports->add(new ClassName(Model::class));
2121

22+
$specs = $this->entitySpecs[$this->entity->name];
23+
24+
if (!empty($specs['parent']) && $specs['parent'] !== $this->entity->name) {
25+
$parentClass = ClassName::fromEntity(
26+
new Entity($this->entitySpecs[$this->entity->name]['parent']),
27+
ClassType::MODEL,
28+
);
29+
$this->imports->add($parentClass);
30+
}
31+
2232
return [
2333
'namespace' => $this->entity->getNamespace($this->getClassType()),
2434
'classname' => $this->entity->getBaseClassName($this->getClassType()),
2535
'classImports' => $this->imports,
2636
'properties' => $this->getProperties(),
2737
'description' => $this->entitySpecs[$this->entity->name]['description'] ?? '',
38+
'parentClass' => $parentClass ?? null,
2839
];
2940
}
3041

tools/templates/Model.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace {{ namespace }};
1515
/**
1616
* {{ description }}
1717
*/
18-
class {{ classname }} extends Model
18+
class {{ classname }} extends {% if parentClass %}{{ parentClass }}{% else %}Model{% endif %}
1919
{
2020
{% for property in properties %}
2121
{% if property.descriptionLines %}

0 commit comments

Comments
 (0)