database = $database; $this->target = null; $this->error = null; $this->prevalidate($database, $tables); } protected abstract function prevalidate( \wpdb $database, table_names $tables ) : void; public function check() : self { $result = $this->validate(); $this->error = null; if ($result !== null) { $this->make_error($result); } return $this; } protected abstract function validate() : ?string; protected function is_loaded() : bool { return $this->target !== null; } protected function get_target() : mixed { if (!$this->is_loaded()) { throw new \exception('Must load target before get it.'); } return $this->target; } public function load(mixed $target) : self { $this->target = $target; return $this; } protected function make_error(string $content) : void { if (!$this->is_valid()) { throw new \exception('This validator has already error.'); } $this->error = $content; } public function is_valid() : bool { return $this->error === null; } public function error_on() : string { if ($this->is_valid()) { throw new \exception('Trying to load error on valid object.'); } return $this->error; } private mixed $target; private ?string $error; }