generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7011d25
commit 19e2332
Showing
3 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Spatie\LaravelData\Tests\Factories; | ||
|
||
use Nette\PhpGenerator\Method; | ||
use Nette\PhpGenerator\Parameter; | ||
use Nette\PhpGenerator\PromotedParameter; | ||
use Nette\PhpGenerator\Property; | ||
use Spatie\LaravelData\DataCollection; | ||
use Spatie\LaravelData\Lazy; | ||
|
||
class DataMagicMethodFactory | ||
{ | ||
private string $body; | ||
|
||
private string $inputType; | ||
|
||
private string $inputName; | ||
|
||
public function __construct(private string $name) | ||
{ | ||
} | ||
|
||
public static function new(string $name): static | ||
{ | ||
return new self($name); | ||
} | ||
|
||
public function withInputType(string $inputType, string $inputName = 'payload'): self | ||
{ | ||
$clone = clone $this; | ||
|
||
$clone->inputType = $inputType; | ||
$clone->inputName = $inputName; | ||
|
||
return $clone; | ||
} | ||
|
||
public function withBody(string $body): self | ||
{ | ||
$clone = clone $this; | ||
|
||
$clone->body = $body; | ||
|
||
return $clone; | ||
} | ||
|
||
public function create(): Method | ||
{ | ||
$method = new Method($this->name); | ||
|
||
$method->addBody($this->body); | ||
$method->setStatic(true); | ||
$method->setReturnType('static'); | ||
$method->setParameters([(new Parameter($this->inputName))->setType($this->inputType)]); | ||
|
||
return $method; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters