@param array $data

@return Rate
550841
public static function createFromData(array $data)
    {
        if (!isset($data['name'])) {
            throw new DomainException(self::MSG_REQUIRED_NAME);
        }

        if (!isset($data['price'])) {
            throw new DomainException(self::MSG_REQUIRED_NAME);
        }

        if (!isset($data['currency'])) {
            throw new DomainException(self::MSG_REQUIRED_CURRENCY);
        }

        $rate = new self($data);

        return $rate;
    }
904633
public static function createFromData(array $data): self
    {
        if (!isset($data['method'])) {
            throw new DomainException(self::REQUIRED_METHOD);
        }

        switch ($data['method']) {
            case self::NONE:
                $paymentInstruction = new NoneType($data);

                break;
            case self::PARTIAL:
                $paymentInstruction = new PartialType($data);

                break;
            case self::DISCOUNT:
                $paymentInstruction = new DiscountType($data);

                break;
            default:
                throw new DomainException(
                    sprintf(self::UNSUPPORTED_METHOD, implode(',', self::$availableMethods))
                );
        }

        return $paymentInstruction;
    }
469763
public function create(array $data)
    {
        $url = $this->getUrl('create');
        $request = urldecode(json_encode($data, JSON_UNESCAPED_UNICODE));
        $json = $this->curl->post($url, $request);

        return $json;
    }
848286
protected function getClassFromArray($data)
    {
        if (!is_array($data)) {
            return;
        }

        if (isset($data['@type']) and $type = $data['@type'] and isset($this->types[$type])) {
            $class = $this->types[$type];
        }

        if (isset($data['@class'])) {
            $class = $data['@class'];
        }

        if (isset($class) and class_exists($class)) {
            return $class;
        }
    }
1365859
public function getProbabilityFor($data)
    {
        $found = null;
        array_map(function ($element) use ($data, &$found) {
                if ($element->getData() === $data) {
                    $found = $element;
                }
            },
            $this->elements);

        if ($found !== null) {
            return $found->getWeight() / $this->getTotalWeight();
        }

        return 0.0;
    }
964713
private function calculateChecksum($data) {
    if (strlen($data) % 2) {
      $data .= "\x00";
    }

    $bit = unpack('n*', $data);
    $sum = array_sum($bit);

    while ($sum >> 16) {
      $sum = ($sum >> 16) + ($sum & 0xffff);
    }

    return pack('n*', ~$sum);
  }
953767
public static function toBytes(String $data) : Float
    {
        $number = substr($data, 0, -2);

        switch( strtoupper(substr($data, -2)) )
        {
            case 'KB': return $number * 1024;
            case 'MB': return $number * pow(1024, 2);
            case 'GB': return $number * pow(1024, 3);
            case 'TB': return $number * pow(1024, 4);
            case 'PB': return $number * pow(1024, 5);

            default  : return $data;
        }
    }
209783
public function add($data = [])
    {
        $insertId = $this->db->insert($this->table, $data);
        if ($insertId) {
            return (int) $insertId;
        }

        return 0;
    }
932134
public function format(array $data)
    {
        $value = parent::format($data);
        foreach ($this->list as $uri => $values) {
            if (in_array($value, $values)) {
                return $uri;
            }
        }
        return '';
    }
939318
protected function formatMpMessage(array $data = [])
    {
        $params = $this->baseFormat($data, $this->mpMessage);

        if (empty($params['miniprogram']['appid'])) {
            $params['miniprogram']['appid'] = $this->app['config']['app_id'];
        }

        $params['data'] = $this->formatData($params['data'] ?? []);

        return $params;
    }
312093
public function run(array $data)
    {
        foreach ($this->filters as $path) {
            foreach ($data as &$item) {
                $item = $this->filterItem($item, $path);
            }
        }

        return $data;
    }
871042
protected function sort($data)
    {
        if (is_string($this->sort)) {
            $p = $this->sort;
            usort($data, function ($a, $b) use ($p) {
                if ($a[$p] == $b[$p]) {
                    return 0;
                }
                return $a[$p] < $b[$p] ? -1 : 1;
            });
        } elseif ($this->sort === true) {
            sort($data);
        }
        return $data;
    }
401055
public function send(array $data)
    {
        $url = self::SEND_URL.$this->access_token;
        $request = json_encode($data);
        $res = $this->curl->post($url, $request);

        return $res;
    }
1086447
public static function fromArray(array $data) {
		$ret = new FormOptions();
		foreach($data as $value => $text) {
			$ret->add($value, $text);
		}
		return $ret;
	}
375203
public static function createFromData(array $data)
    {
        if (!isset($data['type'])) {
            throw new DomainException(self::MSG_REQUIRED_TYPE);
        }

        switch ($data['type']) {
            case self::TYPE_FIXED:
                $discount = new Discounts\Fixed($data);

                break;
            case self::TYPE_PERCENT:
                $discount = new Discounts\Percent($data);

                break;
            default:
                throw new DomainException(
                    sprintf(self::MSG_UNSUPPORTED_TYPE, implode(',', self::$supportedTypes))
                );
        }

        return $discount;
    }
535982
public static function fromArray(array $data)
    {
        $result = '';
        foreach ($data as $name => $value) {
            $value = StringHelper::toString($value, "'", Serialize::SERIALIZE_JSON);
            $result .= "$name=$value; ";
        }

        return $result === '' ? null : rtrim($result);
    }
319952
public function write($data) {
    $this->byte_buffer .= $data;
    $current_buffer_len = strlen($this->byte_buffer);
    $data_len = strlen($data);
    // If this data doesn't fill the buffer then write it and return.
    if ($current_buffer_len < self::WRITE_CHUNK_SIZE) {
      return $data_len;
    }

    // Write out this data
    if (!$this->writeBufferToGS()) {
      // Remove the bytes we added to the buffer
      $this->byte_buffer = substr($this->byte_buffer, 0, -strlen($data));
      return 0;
    }

    // We wrote the buffered content - but only return the amount of $data
    // we wrote as per the contract of write()
    return $data_len;
  }