ascetik/primalvalues

Simple classe to handle primitive types

v0.1.0 2024-01-20 10:29 UTC

This package is auto-updated.

Last update: 2024-05-20 15:13:05 UTC


README

Some Classes to handle primitive types

Release Notes

v.O.1.0 : draft

  • PrimalValue interface - still incomplete
  • PrimalString implementation - now a string can have its methods...
  • Numerik implementation - a numeric value with methods.

PrimalString

An object oriented way to handle strings.

PrimalString's constructor is private. To instanciate a PrimalString, use either of() or empty() static methods.

Methods and descriptions :

  • charAt(int $index): self Returns a new self instance with the letter of the current value at given index. On negative $index, search starts from the end of current value. Empty instance if $index is higher than value's length.

  • concat(string|self $sequence): self Returns a new self with the specified string appended to current string

  • contains(string/self $sequence): bool Checks if current value contains given sequence.

  • endsWith(string/self $sequence): bool Checks if current value ends with given sequence.

  • equals(mixed $string): bool Checks value equality for a given PrimalString, strict equality otherwise.

  • indexOf(string/self $sequence): int Returns the index of a sequence of this value, -1 if the sequence is not found

  • isEmpty(): bool Checks if current value is empty

  • lastIndexOf(string/self $sequence): int Returns the index of the last found sequence, -1 if not found

  • length(): int Returns current value's length

  • matches(string $regex): bool Checks current value format using a regular expression

  • replace(string|self|array $oldVal, string|self|array $newVal): self Returns a new self instance with replaced sequence.

  • replaceAll(string|array $regex, string|self|array $replacement): self Replaces from current value all sequences matching given expressions with replacements.

  • split(string $regex): array Returns an array of string sequences from splitting current value using given regex pattern.

  • startsWith(string/self $sequence): bool Checks if current value starts with given sequence.

  • subString(int $offset, ?int $length): self Returns a new self instance from current value starting from $offset with $length characters if given, until the end if not, or an empty self instance if an error occured.

  • toArray(): array Returns an array of self instances for each character of current value.

  • toLowerCase(): self Returns a new self instance with lower-cased current value.

  • toUpperCase(): self Returns a new self instance with upper-cased current value.

  • trim(string|self|null $chars): self Returns a new self instance from current value after removing trailing spaces and $chars at start and end.

  • static of(string $sequence): self Returns a new self instance with given sequence

  • static empty(): self Returns a new self empty instance

Numerik

Object orientd way to handle numeric values. No difference is made between an integer and a float value in this version.

Private constructor. Use of or zero static methods to build a Numerik instance.

Methods and descriptions :

  • add(int|float|self $number): self Return a new self instance with the sum of current value and the given one

  • cube(): self Returns anw self instance with current value at power of 3.

  • decrement(int|float|self $decrease = 1): self Returns a new self instance with current value decreased with given value.

  • divides(int|float|self $dividend): self Returns a new self instance with the result of given number divided by self value. A zero self instance if returned if current value == 0

  • dividedBy(int|float|self $divider): self Returns a new self instance with the result of self value divided by given number. A zero self instance if returned if $number == 0

  • equals(): bool Checks strict equality between current instance and given value.

  • exposing(int|float|self $number): self Returns self instance of given number raised to the power of current value.

  • increment(int|float|self $increase = 1): self Returns a new self instance with current value increased with given value.

  • multiply(int|float|self $number): self Returns a new self instance with the product of current value and given number.

  • power(int|float|self $exponent): self Returns a self instance with current value raised at power $exponent.

  • square(): self Returns anw self instance with current value at power of 2.

  • squareRoot(): self Returns a self instance with current value square root.

  • subtract(int|float|self $number): self Returns a self instance with current value minus $number.

  • subtractTo(int|float|self $number): self Returns a self instance with $number minus current value.

  • toFloat(): float Returns self instance with current value as integer.

  • toInteger(): int Returns self instance with current value as integer.

  • value(): int|float Returns current value

  • static of(int|float $number): self Returns self instance with given number.

  • static zero(): self Returns self instance with 0.

## Next release

Maybe some more calculation methods for Numerik class, including trigonometric ones (cos, sin, tan...) Some other methods in PrimalString if i need to...

Are booleans concerned about this kind of consideration ? A boolean is either true or false, valid or not... What should i implement? A valid() method and that's all ? The hypothetik package already handles boolean case with the appropriate management.