Webmozart\Assert\Assert::methodExists PHP Method

methodExists() public static method

public static methodExists ( $classOrObject, $method, $message = '' )
    public static function methodExists($classOrObject, $method, $message = '')
    {
        if (!method_exists($classOrObject, $method)) {
            static::reportInvalidArgument(sprintf($message ?: 'Expected the method %s to exist.', static::valueToString($method)));
        }
    }

Usage Example

 /**
  * AbstractContentElement constructor.
  *
  * @param Model|Collection|Result $model           Object model or result.
  * @param TemplateFactory         $templateFactory Template factory.
  * @param string                  $column          Column.
  *
  * @throws InvalidArgumentException When model does not have a row method.
  */
 public function __construct($model, TemplateFactory $templateFactory, $column = 'main')
 {
     if ($model instanceof Collection) {
         $model = $model->current();
     }
     if ($model instanceof Model) {
         $this->model = $model;
     }
     Assert::methodExists($model, 'row');
     $this->templateFactory = $templateFactory;
     $this->column = $column;
     $this->data = $this->deserializeData($model->row());
     if ($this->get('customTpl') != '' && TL_MODE == 'FE') {
         $this->setTemplateName($this->get('customTpl'));
     }
 }