Skip to content

Commit f1ace57

Browse files
committed
refactor: cleans up mime type and json schema
1 parent 5821bb2 commit f1ace57

File tree

16 files changed

+70
-77
lines changed

16 files changed

+70
-77
lines changed

src/Common/Contracts/WithJsonSchema.php renamed to src/Common/Contracts/WithJsonSchemaInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* @since n.e.x.t
1414
*/
15-
interface WithJsonSchema
15+
interface WithJsonSchemaInterface
1616
{
1717
/**
1818
* Gets the JSON schema representation of the object.

src/Files/DTO/InlineFile.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
namespace WordPress\AiClient\Files\DTO;
66

7-
use WordPress\AiClient\Common\Contracts\WithJsonSchema;
7+
use WordPress\AiClient\Common\Contracts\WithJsonSchemaInterface;
88
use WordPress\AiClient\Files\Contracts\FileInterface;
9+
use WordPress\AiClient\Files\Traits\HasMimeType;
910

1011
/**
1112
* Represents a file with inline base64-encoded data.
@@ -15,12 +16,9 @@
1516
*
1617
* @since n.e.x.t
1718
*/
18-
class InlineFile implements FileInterface, WithJsonSchema
19+
class InlineFile implements FileInterface, WithJsonSchemaInterface
1920
{
20-
/**
21-
* @var string The MIME type of the file.
22-
*/
23-
private string $mimeType;
21+
use HasMimeType;
2422

2523
/**
2624
* @var string The base64-encoded file data.
@@ -41,18 +39,6 @@ public function __construct(string $mimeType, string $base64Data)
4139
$this->base64Data = $base64Data;
4240
}
4341

44-
/**
45-
* Gets the MIME type of the file.
46-
*
47-
* @since n.e.x.t
48-
*
49-
* @return string The MIME type.
50-
*/
51-
public function getMimeType(): string
52-
{
53-
return $this->mimeType;
54-
}
55-
5642
/**
5743
* Gets the base64-encoded data.
5844
*

src/Files/DTO/LocalFile.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
namespace WordPress\AiClient\Files\DTO;
66

7-
use WordPress\AiClient\Common\Contracts\WithJsonSchema;
7+
use WordPress\AiClient\Common\Contracts\WithJsonSchemaInterface;
88
use WordPress\AiClient\Files\Contracts\FileInterface;
9+
use WordPress\AiClient\Files\Traits\HasMimeType;
910

1011
/**
1112
* Represents a file stored locally on the filesystem.
@@ -15,12 +16,9 @@
1516
*
1617
* @since n.e.x.t
1718
*/
18-
class LocalFile implements FileInterface, WithJsonSchema
19+
class LocalFile implements FileInterface, WithJsonSchemaInterface
1920
{
20-
/**
21-
* @var string The MIME type of the file.
22-
*/
23-
private string $mimeType;
21+
use HasMimeType;
2422

2523
/**
2624
* @var string The local filesystem path to the file.
@@ -41,18 +39,6 @@ public function __construct(string $mimeType, string $path)
4139
$this->path = $path;
4240
}
4341

44-
/**
45-
* Gets the MIME type of the file.
46-
*
47-
* @since n.e.x.t
48-
*
49-
* @return string The MIME type.
50-
*/
51-
public function getMimeType(): string
52-
{
53-
return $this->mimeType;
54-
}
55-
5642
/**
5743
* Gets the local filesystem path.
5844
*

src/Files/DTO/RemoteFile.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
namespace WordPress\AiClient\Files\DTO;
66

7-
use WordPress\AiClient\Common\Contracts\WithJsonSchema;
7+
use WordPress\AiClient\Common\Contracts\WithJsonSchemaInterface;
88
use WordPress\AiClient\Files\Contracts\FileInterface;
9+
use WordPress\AiClient\Files\Traits\HasMimeType;
910

1011
/**
1112
* Represents a file accessible via a remote URL.
@@ -15,12 +16,9 @@
1516
*
1617
* @since n.e.x.t
1718
*/
18-
class RemoteFile implements FileInterface, WithJsonSchema
19+
class RemoteFile implements FileInterface, WithJsonSchemaInterface
1920
{
20-
/**
21-
* @var string The MIME type of the file.
22-
*/
23-
private string $mimeType;
21+
use HasMimeType;
2422

2523
/**
2624
* @var string The URL to the remote file.
@@ -41,18 +39,6 @@ public function __construct(string $mimeType, string $url)
4139
$this->url = $url;
4240
}
4341

44-
/**
45-
* Gets the MIME type of the file.
46-
*
47-
* @since n.e.x.t
48-
*
49-
* @return string The MIME type.
50-
*/
51-
public function getMimeType(): string
52-
{
53-
return $this->mimeType;
54-
}
55-
5642
/**
5743
* Gets the URL to the remote file.
5844
*

src/Files/Traits/HasMimeType.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Files\Traits;
6+
7+
/**
8+
* Provides MIME type functionality for file objects.
9+
*
10+
* This trait can be used by any class that needs to store and retrieve
11+
* a MIME type property.
12+
*
13+
* @since 1.0.0
14+
*/
15+
trait HasMimeType
16+
{
17+
/**
18+
* The MIME type of the file.
19+
*
20+
* @var string
21+
*/
22+
protected string $mimeType;
23+
24+
/**
25+
* Gets the MIME type of the file.
26+
*
27+
* @return string The MIME type.
28+
*
29+
* @since 1.0.0
30+
*/
31+
public function getMimeType(): string
32+
{
33+
return $this->mimeType;
34+
}
35+
}

src/Messages/DTO/Message.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace WordPress\AiClient\Messages\DTO;
66

7-
use WordPress\AiClient\Common\Contracts\WithJsonSchema;
7+
use WordPress\AiClient\Common\Contracts\WithJsonSchemaInterface;
88
use WordPress\AiClient\Messages\Enums\MessageRoleEnum;
99

1010
/**
@@ -15,7 +15,7 @@
1515
*
1616
* @since n.e.x.t
1717
*/
18-
class Message implements WithJsonSchema
18+
class Message implements WithJsonSchemaInterface
1919
{
2020
/**
2121
* @var MessageRoleEnum The role of the message sender.

src/Messages/DTO/MessagePart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace WordPress\AiClient\Messages\DTO;
66

7-
use WordPress\AiClient\Common\Contracts\WithJsonSchema;
7+
use WordPress\AiClient\Common\Contracts\WithJsonSchemaInterface;
88
use WordPress\AiClient\Files\DTO\InlineFile;
99
use WordPress\AiClient\Files\DTO\RemoteFile;
1010
use WordPress\AiClient\Messages\Enums\MessagePartTypeEnum;
@@ -19,7 +19,7 @@
1919
*
2020
* @since n.e.x.t
2121
*/
22-
class MessagePart implements WithJsonSchema
22+
class MessagePart implements WithJsonSchemaInterface
2323
{
2424
/**
2525
* @var MessagePartTypeEnum The type of this message part.

src/Operations/Contracts/OperationInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace WordPress\AiClient\Operations\Contracts;
66

7-
use WordPress\AiClient\Common\Contracts\WithJsonSchema;
7+
use WordPress\AiClient\Common\Contracts\WithJsonSchemaInterface;
88
use WordPress\AiClient\Operations\Enums\OperationStateEnum;
99

1010
/**
@@ -15,7 +15,7 @@
1515
*
1616
* @since n.e.x.t
1717
*/
18-
interface OperationInterface extends WithJsonSchema
18+
interface OperationInterface extends WithJsonSchemaInterface
1919
{
2020
/**
2121
* Gets the operation ID.

src/Results/Contracts/ResultInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace WordPress\AiClient\Results\Contracts;
66

7-
use WordPress\AiClient\Common\Contracts\WithJsonSchema;
7+
use WordPress\AiClient\Common\Contracts\WithJsonSchemaInterface;
88
use WordPress\AiClient\Results\DTO\TokenUsage;
99

1010
/**
@@ -15,7 +15,7 @@
1515
*
1616
* @since n.e.x.t
1717
*/
18-
interface ResultInterface extends WithJsonSchema
18+
interface ResultInterface extends WithJsonSchemaInterface
1919
{
2020
/**
2121
* Gets the result ID.

src/Results/DTO/Candidate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace WordPress\AiClient\Results\DTO;
66

7-
use WordPress\AiClient\Common\Contracts\WithJsonSchema;
7+
use WordPress\AiClient\Common\Contracts\WithJsonSchemaInterface;
88
use WordPress\AiClient\Messages\DTO\Message;
99
use WordPress\AiClient\Results\Enums\FinishReasonEnum;
1010

@@ -16,7 +16,7 @@
1616
*
1717
* @since n.e.x.t
1818
*/
19-
class Candidate implements WithJsonSchema
19+
class Candidate implements WithJsonSchemaInterface
2020
{
2121
/**
2222
* @var Message The generated message.

0 commit comments

Comments
 (0)