Giter VIP home page Giter VIP logo

types's People

Contributors

aleswita avatar bleksak avatar cezam avatar emir avatar korgocz avatar kotmic avatar mstrouhal avatar novotnyj avatar slackdave avatar slischka avatar vibko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

types's Issues

Int from float

I think that float values that can be converted to int without any rounding should not throw exceptions

IntType::from(1.0000000000);//currently throws exception, expected return value of (int) 1
IntType::from('5.00');//currently throws exception, expected return value of (int) 5

DateTimes

  • DateTimesImmutable missing fromOrNull factory method

Types 2.0 - Allow extract from ArrayAcces interface

Extract values should be also possile from objects implementing ArrayAccess.

BC break: No
New feature: Yes

If you implement own collection or you want to extract values maybe from \Nette\Database\IRow. First you have to serialize object to array then you can extract values from array.

Example:

/** @var Nette\Database\Table\ActiveRow $databaseRow */
$databaseRow = $this->repository->fetch();

$array = iterator_to_array($databaseRow); // or $databaseRow->toArray()

$id = PrimitiveTypes::extractInt($array, 'id');

should be simplified to:

/** @var Nette\Database\Table\ActiveRow $databaseRow */
$databaseRow = $this->repository->fetch();

$id = PrimitiveTypes::extractInt($databaseRow, 'id');

So exract method should look like:

final public static function extractInt(array|ArrayAccess $data, string $key): int; // PHP 8.0 syntax

Types 2.0 - Arrays extractor context errors

BC break: posibly yes
New feature: Yes

Problem:

$data = [
	'ids' => [
		'a' => 1,
		'b' => 2,
		'c' => 'failed',
                // ...
	]
];

Arrays::extractIntArray($data, 'ids');

Produces error like:
Problem at key ids: Expected int, got string (failed)
so we know there is problem at key ids but we dont know where exactly in ids array.

It whould be nice if the massege will be formatted like: Problem at key ids[c]: Expected int, got string (failed).

Simular problem is with array extractable object:

$data = [
	'address' => [
		'street_and_number' => 'My streer 21',
		'town' => 'Prague',
		'zip_code' => '12552',
		'country' => 'XX'
	]
];

Address::extract($data, 'address');

Produces error like: Problem at key address: Problem at key country: XX [string] is not a valid value for SmartEmailing\Types\CountryCode, accepted values: ...

It would be more readable like: Problem at key address[country]: XX [string] is not a valid value for SmartEmailing\Types\CountryCode, accepted values: ...

Bug PrimitiveTypes::getInt()

PrimitiveTypes nevytáhne z '0' nulu.
PrimitiveTypes::getInt("0") Vyhodí chybu
Bug ?

$value = '0'
if (\is_int($value)) { // false '0' není int
	return $value;
}
if (\is_string($value)) { // true
	$value = \ltrim($value, '0'); // $value = ''
}
if ((string) (int) $value === $value) { // false '0' !== ''
	return (int) $value;
}
throw InvalidTypeException::typeError('int', $value); //vyhodí vyjímku

EmailAddress

  • email dopravasladek{@seznam.cz should not be valid.

Missing JsonSerializable interface

What i did:

$data = [
    'quantity' => Quantity::from(5)
];
debug(json_encode($data));

Expected result:

{
   "quantity": 5
}

Actual result:

{
   "quantity": {}
}

Iban

@slischka what you think about adding jschaedl/iban-validation dependency using in Iban type from required section in composer to suggestion?

Constructor in Iban type will be like below:

public function __construct(
	string $value
)
{

	if (!\class_exists(\Iban\Validation\Iban::class) || !\class_exists(\Iban\Validation\Iban::class)) {
		throw new \Exception('For using ' . self::class . ' type, please require "jschaedl/iban-validation" in your project composer.')
	}

	$this->iban = new \Iban\Validation\Iban($value);
	$validator = new Validator();

	...

Types 2.0 - Allow int key in extract methods

It should to possible to extract value from array with int keys.
BC break: No
New feture: Yes

PrimitiveTypes::extractIntOrNull($data, 1); 

implementation:

final public static function extractIntOrNull(array $data, string|int $key): ?int; // PHP 8.0 syntax

Duration and TimeUnit

TimeUnit

  • add getSecondsCount()
  • add weeks ?

Duration

  • add getDateTimeModify()
  • add getLengthInSeconds()
  • allow negative values

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.