/** * @param float|int|string $value * @return int * @throws \Granam\Integer\Tools\Exceptions\WrongParameterType * @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast * @throws \Granam\Integer\Tools\Exceptions\PositiveIntegerCanNotBeNegative */ protected function sanitizeValue($value) { return ToInteger::toPositiveInteger($value); }
/** * @param int $skillRank * @return array * @throws \DrdPlus\Tables\Partials\Exceptions\RequiredRowNotFound * @throws \Granam\Scalar\Tools\Exceptions\WrongParameterType */ public function getMalusesForWeaponSkill($skillRank) { /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ return $this->getRow([ToInteger::toPositiveInteger($skillRank)]); }
/** * You can pay by a level (by its property adjustment respectively) or by two another skill points * (for example combined and psychical for a new physical). * * @param int $skillPointValue zero or one * @param ProfessionLevel $professionLevel * @param Tables|null $tables = null * @param BackgroundSkillPoints|null $backgroundSkillPoints = null * @param SkillPoint $firstPaidOtherSkillPoint = null * @param SkillPoint $secondPaidOtherSkillPoint = null * @throws \DrdPlus\Skills\Exceptions\UnexpectedSkillPointValue * @throws \DrdPlus\Skills\Exceptions\UnknownPaymentForSkillPoint * @throws \Granam\Integer\Tools\Exceptions\WrongParameterType * @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast */ protected function __construct($skillPointValue, ProfessionLevel $professionLevel, Tables $tables = null, BackgroundSkillPoints $backgroundSkillPoints = null, SkillPoint $firstPaidOtherSkillPoint = null, SkillPoint $secondPaidOtherSkillPoint = null) { try { $skillPointValue = ToInteger::toPositiveInteger($skillPointValue); } catch (PositiveIntegerCanNotBeNegative $positiveIntegerCanNotBeNegative) { throw new Exceptions\UnexpectedSkillPointValue('Expected zero or one, got ' . ValueDescriber::describe($skillPointValue)); } if ($professionLevel instanceof ProfessionFirstLevel) { $this->professionFirstLevel = $professionLevel; } if ($professionLevel instanceof ProfessionNextLevel) { $this->professionNextLevel = $professionLevel; } $this->checkSkillPointPayment($skillPointValue, $tables, $this->professionFirstLevel, $this->professionNextLevel, $backgroundSkillPoints, $firstPaidOtherSkillPoint, $secondPaidOtherSkillPoint); $this->value = $skillPointValue; $this->backgroundSkillPoints = $backgroundSkillPoints; $this->firstPaidOtherSkillPoint = $firstPaidOtherSkillPoint; $this->secondPaidOtherSkillPoint = $secondPaidOtherSkillPoint; }
private function normalizeValueForType($value, $type) { $value = trim($value); switch ($type) { case self::BOOLEAN: return ToBoolean::toBoolean($value, false); case self::INTEGER: return $value === '' ? false : ToInteger::toInteger($this->normalizeMinus($value)); case self::POSITIVE_INTEGER: return $value === '' ? false : ToInteger::toPositiveInteger($this->normalizeMinus($value)); case self::NEGATIVE_INTEGER: return $value === '' ? false : ToInteger::toNegativeInteger($this->normalizeMinus($value)); case self::FLOAT: return $value === '' ? false : ToFloat::toFloat($this->normalizeMinus($value)); default: // string return $value; } }