@param Species    $species
@param array|null $existingCodes if null, existing codes will be fetched from database

@return string

@throws InvalidEntityCodeException
357687
public static function generate($species, $existingCodes = null)
    {
        if (!$species->getName()) {
            throw new InvalidEntityCodeException('librinfo.error.missing_species_name');
        }
        // Unaccent, remove marks and punctuation, uppercase
        $translit = transliterator_transliterate(
            'Any-Latin; Latin-ASCII; [:Nonspacing Mark:] Remove; [:Punctuation:] Remove; Upper();',
            $species->getName()
        );
        // Remove everything that is not a letter or a digit
        $cleaned = preg_replace('/[^A-Z0-9]/', '', $translit);

        // 3 first chars (right padded with "X" if necessary)
        $code = str_pad(substr($cleaned, 0, 3), 3, 'X');
        if (self::isCodeUnique($code, $species->getId(), $existingCodes)) {
            return $code;
        }

        // XX1 ... XX9
        for ($i = 1; $i < 10; ++$i) {
            $code = sprintf('%s%d', substr($code, 0, 2), $i);
            if (self::isCodeUnique($code, $species->getId(), $existingCodes)) {
                return $code;
            }
        }

        // X01 ... X99
        for ($i = 1; $i < 100; ++$i) {
            $code = sprintf('%s%02d', substr($code, 0, 1), $i);
            if (self::isCodeUnique($code, $species->getId(), $existingCodes)) {
                return $code;
            }
        }

        // 001 ... 999
        // TODO: find a better solution !!
        for ($i = 1; $i < 1000; ++$i) {
            $code = sprintf('%03d', $i);
            if (self::isCodeUnique($code, $species->getId(), $existingCodes)) {
                return $code;
            }
        }

        return '';
    }
143078
private function _checkRef(&$reference, &$refCode)
    {
        if (!is_string($reference)) {
            $reference = strval($reference);
            if (!is_string($reference)) {
                throw new Klarna_InvalidTypeException("Reference", "string");
            }
        }

        if (!is_string($refCode)) {
            $refCode = strval($refCode);
            if (!is_string($refCode)) {
                throw new Klarna_InvalidTypeException("Reference code", "string");
            }
        }
    }
1131785
function nullify($authorizationCode, $authorizedAmount, $buyOrder, $nullifyAmount, $commercecode) {

        try {
            $nullificationInput = new nullificationInput();

            /** Código de autorización de la transacción que se requiere anular. Para el caso que se esté anulando una transacción de captura en línea,
             *  este código corresponde al código de autorización de la captura */
            $nullificationInput->authorizationCode = $authorizationCode; // string

            /** Monto autorizado de la transacción que se requiere anular.
             * Para el caso que se esté anulando una transacción de captura en línea,
             * este monto corresponde al monto de la captura */
            $nullificationInput->authorizedAmount = $authorizedAmount; // decimal

            $nullificationInput->buyOrder = $buyOrder; // string

            if ($commercecode == null){
                $nullificationInput->commerceId = floatval($this->config->getCommerceCode());
            } else {
                $nullificationInput->commerceId = floatval($commercecode);
            }

            $nullificationInput->nullifyAmount = $nullifyAmount;

            $nullifyResponse = $this->_nullify(
                    array("nullificationInput" => $nullificationInput));

            /** Validación de firma del requerimiento de respuesta enviado por Webpay */
            $xmlResponse = $this->soapClient->__getLastResponse();
            $soapValidation = new SoapValidation($xmlResponse, $this->config->getWebpayCert());
            $validationResult = $soapValidation->getValidationResult();

            /** Valida conexion a Webpay */
            if ($validationResult === TRUE) {

                $nullificationOutput = $nullifyResponse->return;
                return $nullificationOutput;
            } else {
                $error["error"] = "Error validando conexión a Webpay";
                $error["error"] = "No se pudo completar la conexión con Webpay";
            }

        } catch (\Exception $e) {

            $error["error"] = "Error conectando a Webpay (Verificar que la informaci&oacute;n del certificado sea correcta)";

            $replaceArray = array('<!--' => '', '-->' => '');
            $error["detail"] = str_replace(array_keys($replaceArray), array_values($replaceArray), $e->getMessage());
        }

        return $error;
    }
903229
public function addSpecies(\Librinfo\VarietiesBundle\Entity\Species $species)
    {
        $this->species[] = $species;

        return $this;
    }
145575
public function setReceptionCode($newCode)
    {
        return $this->model->setReceptionCode(
                $this->getPatientNumber(),
                $this->getOrganizationId(),
                $newCode,
                $this->getId(),
                $this->getReceptionCode()
                );
    }
453448
public function getIdByIso($isoCode) {
		$match = ['DE' => 1, 'AT' => 2, 'CH' => 3];

		$isoCode = strtoupper($isoCode);
		if (array_key_exists($isoCode, $match)) {
			return $match[$isoCode];
		}

		throw new InvalidArgumentException('ISO code not valid: ' . $isoCode);
	}
1026481
public static function factory($globalCode, $data = null)
    {
        if (self::R_SUCCESS === $globalCode) {
            return new self($globalCode, $data);
        }

        $code = $globalCode % 1000;
        $resultClassIndex = (int) ($globalCode / 1000);
        $resultClass = array_search($resultClassIndex,
            self::getClassIndexMap());

        if ($resultClass != null) {
            return new $resultClass($code, $data);
        }

        throw new InvalidArgumentException("Unknown result code [$globalCode]");
    }
1330957
public function validateSpeciesCode(ErrorElement $errorElement, $object)
    {
        $generator = $this->getConfigurationPool()->getContainer()->get('librinfo_varieties.code_generator.species');
        if (!$generator->validate($object->getCode())) {
            $errorElement
                ->with('code')
                    ->addViolation('Wrong species code format')
                ->end();
        }
    }
670264
public static function validateLanguageCode(string $languageCode = null): string
    {
        // We allow empty languageCode in order to quit asking for more
        if (empty($languageCode)) {
            return '';
        }

        if (!preg_match('/^[a-z][a-z][a-z]-[A-Z][A-Z]$/', $languageCode)) {
            throw new InvalidArgumentException('Language code name is not valid.');
        }

        return $languageCode;
    }
439720
private function normalizeMetadata(array &$metadata, array &$normalized, $namespace = '') {
        foreach ($metadata as $key => $value) {
            if (strstr($key, $this->metadataNamespaceSeparator) !== false) {
                throw new DatabaseException('Invalid metadata', 400);
            }

            $ns = $namespace . ($namespace ? $this->metadataNamespaceSeparator : '') . $key;

            if (is_array($value)) {
                $this->normalizeMetadata($value, $normalized, $ns);
            } else {
                $normalized[$ns] = $value;
            }
        }
    }
1299647
protected function getCodeResponse($statusCode)
    {
        $this->checkParameters();

        /** @var ResponsesInterface $responses */
        $responses = $this->getIntegration()->getFromContainer(ResponsesInterface::class);
        $outputMediaType = $this->codecMatcher->getEncoderRegisteredMatchedType();

        return $responses->getResponse($statusCode, $outputMediaType, null, $this->supportedExtensions);
    }
907904
def extract_ast_species(ast):
    """"""

    species_id = "None"
    species_label = "None"
    species = [
        (species_id, species_label) for (species_id, species_label) in ast.species if species_id
    ]

    if len(species) == 1:
        (species_id, species_label) = species[0]

    if not species_id:
        species_id = "None"
        species_label = "None"

    log.debug(f"AST Species: {ast.species}  Species: {species}  SpeciesID: {species_id}")

    return (species_id, species_label)
136304
public static function getStatusIdList($statusCode)
    {
        if (! isset(self::$statusIdListsCache[$statusCode])) {
            $statusIdList = [];

            $statusList = OrderStatusQuery::create()->find();

            /** @var OrderStatus $status */
            foreach ($statusList as $status) {
                switch ($statusCode) {
                    case OrderStatus::CODE_NOT_PAID:
                        $match = $status->isNotPaid(false);
                        break;
                    case OrderStatus::CODE_PAID:
                        $match = $status->isPaid(false);
                        break;

                    case OrderStatus::CODE_PROCESSING:
                        $match = $status->isProcessing(false);
                        break;

                    case OrderStatus::CODE_SENT:
                        $match = $status->isSent(false);
                        break;
                    case OrderStatus::CODE_CANCELED:
                        $match = $status->isCancelled(false);
                        break;
                    case OrderStatus::CODE_REFUNDED:
                        $match = $status->isRefunded(false);
                        break;

                    default:
                        throw new InvalidArgumentException("Status code '$statusCode' is not a valid value.");
                }

                if ($match) {
                    $statusIdList[] = $status->getId();
                }
            }

            self::$statusIdListsCache[$statusCode] = $statusIdList;
        }

        return self::$statusIdListsCache[$statusCode];
    }
490068
public static function getName($code)
    {
        if (!isset(self::$codesDescriptions[$code])) {
            throw new InvalidArgumentException("Invalid code $code specified");
        }

        return self::$codesDescriptions[$code];
    }
47977
private static function isCodeUnique($code, Organism $organism)
    {
        $repo = self::$em->getRepository(Organism::class);
        $query = $repo->createQueryBuilder('o')
            ->where('o.seedProducerCode = :code')
            ->setParameters(['code' => $code]);
        if ($organism->getId()) {
            $query->andWhere('o.id != :id')->setParameter('id', $organism->getId());
        }
        $result = $query->getQuery()->setMaxResults(1)->getOneOrNullResult();

        return $result == null;
    }
891022
public function getConfigurationEntityFromCode($code)
    {
        $dbConfiguration = IndexEngineIndexQuery::create()->findOneByCode($code);

        if (null === $dbConfiguration) {
            throw new InvalidArgumentException(sprintf("The index configuration code '%s' doesn't exist", $code));
        }

        return $this->getConfigurationEntityFromPropelEntity($dbConfiguration);
    }
98466
public List<Namespace> getSpeciesNamespaces(final int speciesTaxId) {
        List<Namespace> rlocs = sizedArrayList(headers.size());
        for (final Map.Entry<String, NamespaceHeader> e : headers.entrySet()) {
            NamespaceHeader hdr = e.getValue();
            if (matchesSpecies(hdr, speciesTaxId)) {
                rlocs.add(new Namespace(hdr.getNamespaceBlock().getKeyword(), e.getKey()));
            }
        }
        return Collections.unmodifiableList(rlocs);
    }