for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace AlecRabbit\Spinner\Core\A;
use AlecRabbit\Spinner\Contract\IObserver;
use AlecRabbit\Spinner\Contract\ISubject;
use AlecRabbit\Spinner\Exception\InvalidArgumentException;
abstract class ASubject implements ISubject
{
public function __construct(
protected ?IObserver $observer = null,
) {
}
public function notify(): void
$this->observer?->update($this);
public function attach(IObserver $observer): void
if ($this->observer !== null) {
throw new InvalidArgumentException('Observer is already attached.');
$this->assertNotSelf($observer);
$this->observer = $observer;
protected function assertNotSelf(object $obj): void
if ($obj === $this) {
throw new InvalidArgumentException('Object can not be self.');
public function detach(IObserver $observer): void
if ($this->observer === $observer) {
$this->observer = null;