generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added documenting of optional params (by adding a comment about it is…
… being optional) (#448) * handling optional params in opinionated way * added optional param test * handling the case when param name is in different case * added extension property marking optional properties as optional * update test * Fix styling --------- Co-authored-by: romalytvynenko <[email protected]>
- Loading branch information
1 parent
71199f3
commit 6821dd2
Showing
4 changed files
with
100 additions
and
5 deletions.
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,47 @@ | ||
<?php | ||
|
||
namespace Dedoc\Scramble\Support\Generator; | ||
|
||
trait WithExtensions | ||
{ | ||
/** @var array<string, mixed> */ | ||
private $extensions = []; | ||
|
||
public function setExtensionProperty(string $key, mixed $value): void | ||
{ | ||
$this->extensions[$key] = $value; | ||
} | ||
|
||
public function hasExtensionProperty(string $key): bool | ||
{ | ||
return array_key_exists($key, $this->extensions); | ||
} | ||
|
||
public function getExtensionProperty(string $key): mixed | ||
{ | ||
if ($this->hasExtensionProperty($key)) { | ||
return $this->extensions[$key]; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function extensionProperties() | ||
{ | ||
return $this->extensions; | ||
} | ||
|
||
public function mergeExtensionProperties($extensionsProperties) | ||
{ | ||
$this->extensions = array_merge($this->extensions, $extensionsProperties); | ||
|
||
return $this; | ||
} | ||
|
||
public function extensionPropertiesToArray(): array | ||
{ | ||
return collect($this->extensions) | ||
->mapWithKeys(fn ($v, $k) => ["x-$k" => $v]) | ||
->all(); | ||
} | ||
} |
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