Skip to content

Commit

Permalink
Merge pull request #21 from rawilk/chore/update-pint-config
Browse files Browse the repository at this point in the history
Chore: update pint config
  • Loading branch information
rawilk authored Mar 10, 2024
2 parents 54f6df3 + 76e5301 commit e7e93a8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 34 deletions.
32 changes: 31 additions & 1 deletion pint.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,36 @@
"types_spaces": {
"space": "none"
},
"single_trait_insert_per_statement": true
"combine_consecutive_issets": true,
"combine_consecutive_unsets": true,
"declare_parentheses": true,
"declare_strict_types": true,
"explicit_string_variable": true,
"single_trait_insert_per_statement": true,
"ordered_class_elements": {
"order": [
"use_trait",
"case",
"constant",
"constant_public",
"constant_protected",
"constant_private",
"property_public",
"property_protected",
"property_private",
"construct",
"destruct",
"magic",
"phpunit",
"method_abstract",
"method_public_static",
"method_public",
"method_protected_static",
"method_protected",
"method_private_static",
"method_private"
],
"sort_algorithm": "none"
}
}
}
66 changes: 33 additions & 33 deletions src/Support/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@
*/
class Name implements Castable, Jsonable, JsonSerializable
{
public function __construct(protected ?string $firstName, protected ?string $lastName = null)
{
}

public function __get(string $key): ?string
{
if ($this->wantsPossessive($key)) {
$key = Str::replaceLast('possessive', '', $key);

return $this->possessive($this->{$key});
}

if (method_exists($this, $method = Str::studly($key))) {
return $this->{$method}();
}

return null;
}

public function __toString(): string
{
return (string) $this->full();
}

public static function from(?string $name): self
{
$parts = explode(' ', trim($name), 2);
Expand All @@ -39,8 +63,9 @@ public static function from(?string $name): self
return new static(Arr::get($parts, 0), $lastName);
}

public function __construct(protected ?string $firstName, protected ?string $lastName = null)
public static function castUsing(array $arguments): CastsAttributes
{
return new NameCast(...$arguments);
}

public function first(): ?string
Expand Down Expand Up @@ -95,48 +120,23 @@ public function initials(): ?string
->join('');
}

protected function possessive(string $name): string
{
return sprintf("%s'%s", $name, (Str::endsWith($name, 's') ? null : 's'));
}

protected function wantsPossessive(string $key): bool
{
return Str::endsWith($key, 'possessive');
}

public function __get(string $key): ?string
public function toJson($options = 0): string
{
if ($this->wantsPossessive($key)) {
$key = Str::replaceLast('possessive', '', $key);

return $this->possessive($this->{$key});
}

if (method_exists($this, $method = Str::studly($key))) {
return $this->{$method}();
}

return null;
return json_encode($this->jsonSerialize(), $options);
}

public function __toString(): string
public function jsonSerialize(): string
{
return (string) $this->full();
}

public static function castUsing(array $arguments): CastsAttributes
{
return new NameCast(...$arguments);
}

public function toJson($options = 0): string
protected function possessive(string $name): string
{
return json_encode($this->jsonSerialize(), $options);
return sprintf("%s'%s", $name, (Str::endsWith($name, 's') ? null : 's'));
}

public function jsonSerialize(): string
protected function wantsPossessive(string $key): bool
{
return (string) $this->full();
return Str::endsWith($key, 'possessive');
}
}

0 comments on commit e7e93a8

Please sign in to comment.