From 5947995ad8b819e92874240c03b834bfa2cf1a39 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 10 Jun 2026 18:05:15 +0000 Subject: [PATCH 1/7] Initial plan From 8ed0f341466dbe7e714444a1603ab4ce56cd3935 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 10 Jun 2026 18:55:23 +0000 Subject: [PATCH 2/7] Fix: Allow Avatar::create() to be called statically Use __call and __callStatic magic methods to support both static and instance usage of the create() method. When called statically (Avatar::create('Name')), a new instance is created. When called on an existing instance ($avatar->create('Name')), it uses the existing instance preserving its configuration. Also adds @method PHPDoc annotations to the Facade class for better IDE support. --- src/Avatar.php | 33 ++++++++++++++++++++++++++++++++- src/Facade.php | 21 +++++++++++++++++++++ tests/AvatarPhpTest.php | 21 +++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/Avatar.php b/src/Avatar.php index a8c20f2..9cc3f71 100644 --- a/src/Avatar.php +++ b/src/Avatar.php @@ -122,12 +122,43 @@ public function __toString() return (string) $this->toBase64(); } + /** + * Handle dynamic method calls on the instance. + * + * @return mixed + */ + public function __call(string $method, array $args): mixed + { + if ($method === 'create') { + return $this->createAvatar($args[0]); + } + + throw new \BadMethodCallException("Method {$method} does not exist."); + } + + /** + * Handle static method calls to allow static usage of the Avatar class. + * This enables calling Avatar::create('Name') without a facade. + * + * @return mixed + */ + public static function __callStatic(string $method, array $args): mixed + { + if ($method === 'create') { + $instance = new static; + + return $instance->createAvatar($args[0]); + } + + throw new \BadMethodCallException("Method {$method} does not exist."); + } + public function setGenerator(GeneratorInterface $generator): void { $this->initialGenerator = $generator; } - public function create(string $name): static + public function createAvatar(string $name): static { $this->name = $name; diff --git a/src/Facade.php b/src/Facade.php index 8e5e40c..752780b 100644 --- a/src/Facade.php +++ b/src/Facade.php @@ -2,6 +2,27 @@ namespace Laravolt\Avatar; +/** + * @method static \Laravolt\Avatar\Avatar create(string $name) + * @method static \Laravolt\Avatar\Avatar setBackground(string $color) + * @method static \Laravolt\Avatar\Avatar setForeground(string $color) + * @method static \Laravolt\Avatar\Avatar setDimension(int $width, int $height = null) + * @method static \Laravolt\Avatar\Avatar setFontSize(float $size) + * @method static \Laravolt\Avatar\Avatar setFont(string $font) + * @method static \Laravolt\Avatar\Avatar setShape(string $shape) + * @method static \Laravolt\Avatar\Avatar setChars(int $chars) + * @method static \Laravolt\Avatar\Avatar setBorder(int $size, string $color) + * @method static \Laravolt\Avatar\Avatar setBorderRadius(int $radius) + * @method static \Laravolt\Avatar\Avatar setTheme(array|string $theme) + * @method static \Laravolt\Avatar\Avatar setResponsive(bool $responsive) + * @method static \Laravolt\Avatar\Avatar buildAvatar() + * @method static string toBase64() + * @method static string toSvg() + * @method static string toGravatar() + * @method static string getInitial() + * + * @see \Laravolt\Avatar\Avatar + */ class Facade extends \Illuminate\Support\Facades\Facade { /** diff --git a/tests/AvatarPhpTest.php b/tests/AvatarPhpTest.php index 213adfb..3db163c 100644 --- a/tests/AvatarPhpTest.php +++ b/tests/AvatarPhpTest.php @@ -583,6 +583,27 @@ public function it_can_set_custom_generator() $this->assertEquals('foo', $avatar->buildAvatar()->getInitial()); } + #[Test] + public function it_can_be_called_statically() + { + $avatar = \Laravolt\Avatar\Avatar::create('John Doe'); + + $this->assertInstanceOf(\Laravolt\Avatar\Avatar::class, $avatar); + $this->assertEquals('John Doe', $avatar->getAttribute('name')); + } + + #[Test] + public function it_can_chain_methods_after_static_create() + { + $svg = \Laravolt\Avatar\Avatar::create('Jane Smith') + ->setDimension(100, 100) + ->setShape('circle') + ->toSvg(); + + $this->assertStringContainsString('assertStringContainsString('JS', $svg); + } + protected function sampleBase64String() { if (version_compare(phpversion(), '7.2', '>=')) { From d8c87c90bb43bff2871f186f7305083d869eec37 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 10 Jun 2026 18:56:11 +0000 Subject: [PATCH 3/7] Add argument validation to __call and __callStatic methods --- src/Avatar.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Avatar.php b/src/Avatar.php index 9cc3f71..50ccc42 100644 --- a/src/Avatar.php +++ b/src/Avatar.php @@ -130,6 +130,10 @@ public function __toString() public function __call(string $method, array $args): mixed { if ($method === 'create') { + if (empty($args) || ! is_string($args[0])) { + throw new \InvalidArgumentException('The create() method requires a string name argument.'); + } + return $this->createAvatar($args[0]); } @@ -145,6 +149,10 @@ public function __call(string $method, array $args): mixed public static function __callStatic(string $method, array $args): mixed { if ($method === 'create') { + if (empty($args) || ! is_string($args[0])) { + throw new \InvalidArgumentException('The create() method requires a string name argument.'); + } + $instance = new static; return $instance->createAvatar($args[0]); From 20a2a39ecee2968f6227aabcf9b636c6008dbdcb Mon Sep 17 00:00:00 2001 From: Bayu Hendra Winata Date: Thu, 11 Jun 2026 09:09:09 +0700 Subject: [PATCH 4/7] Apply fixes from StyleCI (#188) Co-authored-by: StyleCI Bot --- tests/ImageExportTest.php | 3 +-- tests/StorageOptimizationTest.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/ImageExportTest.php b/tests/ImageExportTest.php index eb83d15..1c4c5f5 100644 --- a/tests/ImageExportTest.php +++ b/tests/ImageExportTest.php @@ -15,8 +15,7 @@ protected function setUp(): void parent::setUp(); // Create a test avatar class with ImageExport trait - $this->avatar = new class extends Avatar - { + $this->avatar = new class extends Avatar { use ImageExport; public function __construct() diff --git a/tests/StorageOptimizationTest.php b/tests/StorageOptimizationTest.php index 7d88fbb..5f06525 100644 --- a/tests/StorageOptimizationTest.php +++ b/tests/StorageOptimizationTest.php @@ -22,8 +22,7 @@ protected function setUp(): void $this->mockCache(); // Create a test avatar class with StorageOptimization trait - $this->avatar = new class extends Avatar - { + $this->avatar = new class extends Avatar { use StorageOptimization; public function __construct() From e7cef14878ba5ced54aefd3fb454e80f0e7f8c81 Mon Sep 17 00:00:00 2001 From: Qisthi Ramadhani Date: Thu, 11 Jun 2026 10:42:44 +0700 Subject: [PATCH 5/7] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/Avatar.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Avatar.php b/src/Avatar.php index 50ccc42..5ffe0f4 100644 --- a/src/Avatar.php +++ b/src/Avatar.php @@ -127,16 +127,21 @@ public function __toString() * * @return mixed */ - public function __call(string $method, array $args): mixed - { - if ($method === 'create') { - if (empty($args) || ! is_string($args[0])) { - throw new \InvalidArgumentException('The create() method requires a string name argument.'); - } +public function __call(string $method, array $args): mixed +{ + if ($method === 'create') { + $name = $args['name'] ?? ($args[0] ?? null); - return $this->createAvatar($args[0]); + if (! is_string($name)) { + throw new \InvalidArgumentException('The create() method requires a string name argument.'); } + return $this->createAvatar($name); + } + + throw new \BadMethodCallException("Method {$method} does not exist."); +} + throw new \BadMethodCallException("Method {$method} does not exist."); } From f802b99f783d1063aca31683352a3c7443f6f8d3 Mon Sep 17 00:00:00 2001 From: Qisthi Ramadhani Date: Thu, 11 Jun 2026 10:42:57 +0700 Subject: [PATCH 6/7] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/Avatar.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Avatar.php b/src/Avatar.php index 5ffe0f4..a1a90eb 100644 --- a/src/Avatar.php +++ b/src/Avatar.php @@ -151,18 +151,23 @@ public function __call(string $method, array $args): mixed * * @return mixed */ - public static function __callStatic(string $method, array $args): mixed - { - if ($method === 'create') { - if (empty($args) || ! is_string($args[0])) { - throw new \InvalidArgumentException('The create() method requires a string name argument.'); - } - - $instance = new static; +public static function __callStatic(string $method, array $args): mixed +{ + if ($method === 'create') { + $name = $args['name'] ?? ($args[0] ?? null); - return $instance->createAvatar($args[0]); + if (! is_string($name)) { + throw new \InvalidArgumentException('The create() method requires a string name argument.'); } + $instance = new static; + + return $instance->createAvatar($name); + } + + throw new \BadMethodCallException("Method {$method} does not exist."); +} + throw new \BadMethodCallException("Method {$method} does not exist."); } From 8d58bc7823d030b72f7e483e8f1cf3e44e23e349 Mon Sep 17 00:00:00 2001 From: Qisthi Ramadhani Date: Thu, 11 Jun 2026 10:43:08 +0700 Subject: [PATCH 7/7] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/Facade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Facade.php b/src/Facade.php index 752780b..84e754d 100644 --- a/src/Facade.php +++ b/src/Facade.php @@ -6,12 +6,12 @@ * @method static \Laravolt\Avatar\Avatar create(string $name) * @method static \Laravolt\Avatar\Avatar setBackground(string $color) * @method static \Laravolt\Avatar\Avatar setForeground(string $color) - * @method static \Laravolt\Avatar\Avatar setDimension(int $width, int $height = null) + * @method static \Laravolt\Avatar\Avatar setDimension(int $width, ?int $height = null) * @method static \Laravolt\Avatar\Avatar setFontSize(float $size) * @method static \Laravolt\Avatar\Avatar setFont(string $font) * @method static \Laravolt\Avatar\Avatar setShape(string $shape) * @method static \Laravolt\Avatar\Avatar setChars(int $chars) - * @method static \Laravolt\Avatar\Avatar setBorder(int $size, string $color) + * @method static \Laravolt\Avatar\Avatar setBorder(int $size, string $color, int $radius = 0) * @method static \Laravolt\Avatar\Avatar setBorderRadius(int $radius) * @method static \Laravolt\Avatar\Avatar setTheme(array|string $theme) * @method static \Laravolt\Avatar\Avatar setResponsive(bool $responsive)