W przyszłości warto się zastanowić czy nie zrobić tutaj zaokrąglania lepszego,
a nie na zasadzie odrąbywania

@param mixed $data
@return string
@throws Exception
168976
public static function toDb($data) {

        $d = static::toInt($data);

        $d .= '';

        $minus = false;
        if (strlen($d) && $d[0] === '-') {
            $minus = true;
        }

        $d = trim($d, '-');

        $d = str_pad($d, 2, '0', STR_PAD_LEFT);

        $one = substr($d, 0, -2);

        $one = str_pad($one, 1, '0');

        $two = substr($d, -2);

        $two = str_pad($two, 2, '0', STR_PAD_RIGHT);

        return ($minus ? '-' : '') . "$one.$two";
    }
1280278
private function getExceptionText(&$item, $exception) {
        $text = "";
        switch ($exception) {
            case 'dataTypeException':
                if (isset($item["texts"]["exception-$exception"]) && $item["texts"]["exception-$exception"]) return $this->getText($item["texts"]["exception-$exception"]);
                if (isset($item["texts"]["exceptions"]["$exception"])) return $this->getText($item["texts"]["exceptions"]["$exception"]);
                if (isset($this->data["$exception"])) return $this->getText($this->data["$exception"]);
                if (!$text) $text = $this->getText("MF_$exception");
                if (!$text || $text == "MF_$exception") $text = Language::get("Wrong data type has been supplied");
                break;
            case 'minLengthException':
                if (isset($item["texts"]["exception-$exception"]) && $item["texts"]["exception-$exception"]) return $this->getText($item["texts"]["exception-$exception"]);
                if (isset($item["texts"]["exceptions"]["$exception"])) return $this->getText($item["texts"]["exceptions"]["$exception"]);
                if (isset($this->data["$exception"])) return $this->getText($this->data["$exception"]);
                if (!$text) $text = $this->getText("MF_$exception");
                if (!$text || $text == "MF_$exception") $text = Language::get("Input is too short");
                break;
            case 'maxLengthException':
                if (isset($item["texts"]["exception-$exception"]) && $item["texts"]["exception-$exception"]) return $this->getText($item["texts"]["exception-$exception"]);
                if (isset($item["texts"]["exceptions"]["$exception"])) return $this->getText($item["texts"]["exceptions"]["$exception"]);
                if (isset($this->data["$exception"])) return $this->getText($this->data["$exception"]);
                if (!$text) $text = $this->getText("MF_$exception");
                if (!$text || $text == "MF_$exception") $text = Language::get("Input is too long");
                break;
            case 'uniqueException':
                if (isset($item["texts"]["exception-$exception"]) && $item["texts"]["exception-$exception"]) return $this->getText($item["texts"]["exception-$exception"]);
                if (isset($item["texts"]["exceptions"]["$exception"])) return $this->getText($item["texts"]["exceptions"]["$exception"]);
                if (isset($this->data["$exception"])) return $this->getText($this->data["$exception"]);
                if (!$text) $text = $this->getText("MF_$exception");
                if (!$text || $text == "MF_$exception") $text = Language::get("Value must be unique. This value is already in the DB.");
                break;
            case 'fileExistsException':
                if (isset($item["texts"]["exception-$exception"]) && $item["texts"]["exception-$exception"]) return $this->getText($item["texts"]["exception-$exception"]);
                if (isset($item["texts"]["exceptions"]["$exception"])) return $this->getText($item["texts"]["exceptions"]["$exception"]);
                if (isset($this->data["$exception"])) return $this->getText($this->data["$exception"]);
                if (!$text) $text = $this->getText("MF_$exception");
                if (!$text || $text == "MF_$exception") $text = Language::get("File with the same name already exists");
                break;
            case 'fileNotAllowed':
                if (isset($item["texts"]["exception-$exception"]) && $item["texts"]["exception-$exception"]) return $this->getText($item["texts"]["exception-$exception"]);
                if (isset($item["texts"]["exceptions"]["$exception"])) return $this->getText($item["texts"]["exceptions"]["$exception"]);
                if (isset($this->data["$exception"])) return $this->getText($this->data["$exception"]);
                if (!$text) $text = $this->getText("MF_$exception");
                if (!$text || $text == "MF_$exception") $text = Language::get("File cannot be processed because of security reasons");
                break;
            case 'errorWhileMovingFile':
                if (isset($item["texts"]["exception-$exception"]) && $item["texts"]["exception-$exception"]) return $this->getText($item["texts"]["exception-$exception"]);
                if (isset($item["texts"]["exceptions"]["$exception"])) return $this->getText($item["texts"]["exceptions"]["$exception"]);
                if (isset($this->data["$exception"])) return $this->getText($this->data["$exception"]);
                if (!$text) $text = $this->getText("MF_$exception");
                if (!$text || $text == "MF_$exception") $text = Language::get("Error occured while copying file");
                break;
            case 'minNumException':
                if (isset($item["texts"]["exception-$exception"]) && $item["texts"]["exception-$exception"]) return $this->getText($item["texts"]["exception-$exception"]);
                if (isset($item["texts"]["exceptions"]["$exception"])) return $this->getText($item["texts"]["exceptions"]["$exception"]);
                if (isset($this->data["$exception"])) return $this->getText($this->data["$exception"]);
                if (!$text) $text = $this->getText("MF_$exception");
                if (!$text || $text == "MF_$exception") $text = Language::get("Number is too low");
                break;
            case 'maxNumException':
                if (isset($item["texts"]["exception-$exception"]) && $item["texts"]["exception-$exception"]) return $this->getText($item["texts"]["exception-$exception"]);
                if (isset($item["texts"]["exceptions"]["$exception"])) return $this->getText($item["texts"]["exceptions"]["$exception"]);
                if (isset($this->data["$exception"])) return $this->getText($this->data["$exception"]);
                if (!$text) $text = $this->getText("MF_$exception");
                if (!$text || $text == "MF_$exception") $text = Language::get("Number is too high");
                break;
            case "enumTypeException":
                if (isset($item["texts"]["exception-$exception"]) && $item["texts"]["exception-$exception"]) return $this->getText($item["texts"]["exception-$exception"]);
                if (isset($item["texts"]["exceptions"]["$exception"])) return $this->getText($item["texts"]["exceptions"]["$exception"]);
                if (isset($this->data["$exception"])) return $this->getText($this->data["$exception"]);
                if (!$text) $text = $this->getText("MF_$exception");
                if (!$text || $text == "MF_$exception") $text = Language::get("Wrong value has been entered");;
                break;
            case "captchaTypeException":
                if (isset($item["texts"]["exception-$exception"]) && $item["texts"]["exception-$exception"]) return $this->getText($item["texts"]["exception-$exception"]);
                if (isset($item["texts"]["exceptions"]["$exception"])) return $this->getText($item["texts"]["exceptions"]["$exception"]);
                if (isset($this->data["$exception"])) return $this->getText($this->data["$exception"]);
                if (!$text) $text = $this->getText("MF_$exception");
                if (!$text || $text == "MF_$exception") $text = Language::get("Captcha is not correct");;
                break;
            }
            return $text;
        }
1144846
private function sign($data)
    {
        if (openssl_sign((string)$data, $signature, $this->privateKey->toString(), static::SIGNATURE_ALGORITHM) !== true) {
            throw new \Exception("Could not sign request: " . openssl_error_string());
        }

        return $signature;
    }
800361
public static function json_encode(array $data)
    {
        $json = @json_encode($data);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \Exception(
                sprintf('An error occurred while trying to encode data to JSON [code "%s"]!', json_last_error())
            );
        } else {
            $data = $json;
        }
        return $data;
    }
784811
public function thaw($data)
    {
        try {
            $value = Parser::fromString($data);
        } catch (Exception $e) {
            throw new Exception\TomlThawException($e);
        }

        return $value;
    }
145247
private function responseFromGate($data)
	{

		$response = array(
			'response' => array(
				'result_code' => $data['error'],
			),
		);
		//Если код ошибки 0 - добавляем к ответу данные счёта
		if ($data['error'] == Catalog::C_WITHOUT_ERRORS) {
			$response['response']['bill'] = $data;
		}
		$code_response = Catalog::serverCode($data['error']);

		return Response::json($response, $code_response);
	}
1114629
public function write($id, $data)
    {
        //dane nie uległy zmianie
        if ($data == $this->_data) {
            return true;
        }
        //niepoprawne ID
        if (!$this->_validate($id)) {
            return true;
        }
        //wyszukiwanie rekordu
        if (null === $record = (new Orm\SessionQuery)->findPk($id)) {
            //tworzenie nowego rekordu
            $record = new Orm\SessionRecord;
        }
        //puste dane sesyjne
        if (!$data) {
            //jeśli istniał rekord - usuwamy
            $record->id ? $record->delete() : null;
            return true;
        }
        //ustawianie danych i czasu
        $record->id = $id;
        $record->data = $data;
        $record->timestamp = time();
        //zapis rekordu
        return $record->save();
    }
179418
public function savePermission($data = [])
    {
        if (!empty($data)) {
            $this->data($data);
        }
        $validate = new \gmars\rbac\validate\Permission();
        if (!$validate->check($this)) {
            throw new Exception($validate->getError());
        }
        $data = $this->getData();
        if (isset($data['id']) && !empty($data['id'])) {
            $this->isUpdate(true);
        }
        $this->save();
        return $this;
    }
370401
private function decryptSymmetric($data)
    {
        $iv_length = openssl_cipher_iv_length($this->cryptParams['cipher']);
        $this->iv = substr($data, 0, $iv_length);
        $data = substr($data, $iv_length);
        $decrypted = openssl_decrypt($data, $this->cryptParams['cipher'], $this->key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $this->iv);
        if (false === $decrypted) {
            throw new Exception('Failure decrypting Data (openssl symmetric) - ' . openssl_error_string());
        }
        return $this->unpadISO10126($decrypted);
    }
517983
public function serialize(/*mixed*/ $data) 
    {
        if (null === $data) {
            return $this->serializeInt(null);
        }
        elseif (is_array($data)) {
            return $this->serializeUInt8($data);
        }
        elseif (is_integer($data)) {
            return $this->serializeLong($data);
        }
        elseif (is_string($data)) {
            return $this->serializeString($data);
        }
        elseif ($data instanceof Serializable) {
            return $data->serialize();
        }

        throw new RuntimeException("Invalid parameter provided to \\NEM\\Core\\Serialize::serialize().");
    }
103086
public static function encode($data)
    {
        $dataLen = strlen($data);
        if ($dataLen % 2 != 0 || $dataLen == 0) {
            throw new \Exception('Invalid Length');
        }

        $code_string = self::BASE58_CHARS;
        $x = Util::decodeHex($data);
        $output_string = '';

        while (Math::cmp($x, '0') > 0) {
            $q = Math::div($x, 58);
            $r = Math::mod($x, 58);
            $output_string .= substr($code_string, intval($r), 1);
            $x = $q;
        }

        for ($i = 0; $i < $dataLen && substr($data, $i, 2) == '00'; $i += 2) {
            $output_string .= substr($code_string, 0, 1);
        }

        $output_string = strrev($output_string);

        return $output_string;
    }
1334054
public function wsdlAction()
    {
        try {
            $apiModel = $this->_getModelName($this->obj);
            $serverParams = [
                'module' => 'cms',
                'controller' => 'api',
                'action' => 'soapServer',
                'obj' => $this->obj,
            ];
            //serwer z autoryzacją (WSDL jest publiczny)
            if ($this->type == 'private' || \Mmi\App\FrontController::getInstance()->getEnvironment()->authUser) {
                $apiModel .= 'Private';
            }
            //link do serwera SOAP
            $url = $this->view->url($serverParams, true, true, $this->_isSsl());
            //typ odpowiedzi application/xml
            $this->getResponse()->setTypeXml();
            //@TODO: przepisać do ZF2
            require_once BASE_PATH . '/vendors/Zend/Soap/AutoDiscover.php';
            //rozpoznanie usługi (klasy)
            $autodiscover = new \Zend_Soap_AutoDiscover;
            $autodiscover->setClass($apiModel);
            $autodiscover->setUri($url);
            //obsługa żądania
            $autodiscover->handle();
            return '';
        } catch (\Exception $e) {
            //internal server error
            $this->_internalError($e);
        }
    }
1342303
public function stream_write($data)
    {
        if ($this->getOnWriteDataMode()) {

            $length = strlen($data);
            $this->appendDataBuffer($data);
            $this->appendPosition($length);
            return $length;
        } else {
            throw new \Exception('dirty mode.');
        }
    }
505739
public function sendNotificationToDevices($data)
    {
        if(!isset($data['device_tokens']) || empty($data['device_tokens'])) {
            throw new Exception('need param: device_tokens');
        }
        $newData = array(
            'type' => 'listcast',
            'payload' => array(
                'body' => array(
                    'title' => $data['title'],
                    'text' => $data['text'],
                )
            ),
        );
        if(is_array($data['device_tokens'])) {
            $newData['device_tokens'] = implode(',', $data['device_tokens']);
        } else {
            $newData['device_tokens'] = $data['device_tokens'];
        }

        return $this->send($newData);
    }
1239098
protected function transform($data)
    {
        if (!$data instanceof GetSchema\Schema) {
            throw new Exception('Data is not a Schema.');
        }

        $definition = $data->getTableDefinition($this->table);
        $defSchema = $definition->getSchema();

        $returnData = [];
        $row = [
            self::KEY_TABLE => $definition->getName(),
            0 => $definition->getName(),
            self::KEY_CREATE_TABLE => $defSchema,
            1 => $defSchema,
        ];
        $returnData[] = $row;

        return $returnData;
    }
119202
protected function getLabelFromRecordData(array $data)
    {
        $label = Arrays::getValueByPath($data, $this->labelDataKey);
        if ($label === null) {
            throw new \Exception('Could not determine label from record data (key: ' . $this->labelDataKey . '). See ' . self::class . ' for more information.', 1462968958372);
        }
        return (string)$label;
    }
999704
public function xssProtection($data = '')
        {

            $data = str_replace($this->getReplaceTags(), '', $data);
            if (!is_string($data)) {

                throw new \Exception(sprintf('%s veri tipi %s fonksiyonunda kullanılamaz', gettype($data),
                    __FUNCTION__));
            }

            $data = strip_tags(
                htmlspecialchars(
                    htmlentities(
                        filter_var($data, FILTER_SANITIZE_SPECIAL_CHARS))
                )
            );

            return $data;
        }