Refactor
This commit is contained in:
parent
51299096c5
commit
202552cdfe
1 changed files with 9 additions and 23 deletions
|
@ -4,12 +4,10 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Drupal\opd_podcast;
|
namespace Drupal\opd_podcast;
|
||||||
|
|
||||||
use Drupal\taxonomy\TermInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @implements \IteratorAggregate<Guest>
|
* @implements \IteratorAggregate<Guest>
|
||||||
*/
|
*/
|
||||||
final class Guests implements \ArrayAccess, \Countable, \IteratorAggregate, \Stringable {
|
final class Guests implements \Countable, \IteratorAggregate, \Stringable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Guest[] $guests
|
* @param Guest[] $guests
|
||||||
|
@ -25,31 +23,15 @@ final class Guests implements \ArrayAccess, \Countable, \IteratorAggregate, \Str
|
||||||
return new \ArrayIterator($this->guests);
|
return new \ArrayIterator($this->guests);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function offsetExists(mixed $offset): bool {
|
|
||||||
return isset($this->guests[$offset]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function offsetGet(mixed $offset): mixed {
|
|
||||||
return $this->guests[$offset];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function offsetSet(mixed $offset, mixed $value): void {
|
|
||||||
$this->guests[$offset] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function offsetUnset(mixed $offset): void {
|
|
||||||
unset($this->guests[$offset]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __toString(): string {
|
public function __toString(): string {
|
||||||
// TODO: allow for more than two guests.
|
// TODO: allow for more than two guests.
|
||||||
if (count($this->guests) === 2) {
|
if ($this->count() === 2) {
|
||||||
assert($this->guests[1] instanceof Guest);
|
assert($this->get(0) instanceof Guest);
|
||||||
|
|
||||||
return sprintf('%s %s %s', $this->guests[0]->getName(), t('and'), $this->guests[1]->getName());
|
return sprintf('%s %s %s', $this->get(0)->getName(), t('and'), $this->get(1)->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return strval($this->guests[0]->getName());
|
return strval($this->get(0)->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,4 +41,8 @@ final class Guests implements \ArrayAccess, \Countable, \IteratorAggregate, \Str
|
||||||
return new self($guests);
|
return new self($guests);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function get(int $offset): ?Guest {
|
||||||
|
return $this->guests[$offset];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue