/**
  * @param \Elastica\Document|\Elastica\Script $data
  * @param string $opType
  * @return \Elastica\Bulk\Action\AbstractDocument
  */
 public static function create($data, $opType = null)
 {
     //Check type
     if (!$data instanceof Document && !$data instanceof Script) {
         throw new \InvalidArgumentException("The data needs to be a Document or a Script.");
     }
     if (null === $opType && $data->hasOpType()) {
         $opType = $data->getOpType();
     }
     //Check that scripts can only be used for updates
     if ($data instanceof Script && isset($opType) && $opType != self::OP_TYPE_UPDATE) {
         throw new \InvalidArgumentException("When performing an update action, the data needs to be a Document or a Script.");
     }
     switch ($opType) {
         case self::OP_TYPE_DELETE:
             $action = new DeleteDocument($data);
             break;
         case self::OP_TYPE_CREATE:
             $action = new CreateDocument($data);
             break;
         case self::OP_TYPE_UPDATE:
             $action = new UpdateDocument($data);
             break;
         case self::OP_TYPE_INDEX:
         default:
             $action = new IndexDocument($data);
             break;
     }
     return $action;
 }