<commit_before># Converter and object wrapper for an integer

[![Build Status](https://travis-ci.org/jaroslavtyc/granam-integer.svg?branch=master)](https://travis-ci.org/jaroslavtyc/granam-integer)

Note: requires PHP 5.4+
```php
<?php
use Granam\IntegerObject\IntegerObject;
use Granam\IntegerObject\Exceptions\WrongParameterType;

$integer = new IntegerObject(12345);

// int(12345)
var_dump($integer->getValue());

$integerFromString = new IntegerObject("124578");
// int(124578)
var_dump($integerFromString->getValue());

$integerFromFloatString = new IntegerObject("987.0");
// int(987)
var_dump($integerFromFloatString->getValue());

try {
new IntegerObject(987.123);
} catch (WrongParameterType $integerException) {
   // Something get wrong: Some value has been lost on cast. Got '987.456', cast into integer 987
   echo('Something get wrong: ' . $integerException->getMessage() . "\n");
 }

$integerFromTrue = new IntegerObject(true);
// int(1)
var_dump($integerFromTrue->getValue());

$integerFromNull = new IntegerObject(null);
// int(0)
var_dump($integerFromNull->getValue());
// ...

$stringWithAlmostInteger = '0.9999999999999999';
$integerFromStringWithAlmostInteger = new IntegerObject($stringWithAlmostInteger);
// int(1)
var_dump($integerFromStringWithAlmostInteger->getValue());
// int(0) -- because of intval(floatval($value))
var_dump(intval($stringWithAlmostInteger));

```
<commit_msg>Hint about built-in validation in readme<commit_after># Converter and object wrapper for an integer

[![Build Status](https://travis-ci.org/jaroslavtyc/granam-integer.svg?branch=master)](https://travis-ci.org/jaroslavtyc/granam-integer)

## Hint
First of all, make sure you don't need just a [simple  built-in int validation](http://php.net/manual/en/function.filter-var.php).

Note: requires PHP 5.4+
```php
<?php
use Granam\IntegerObject\IntegerObject;
use Granam\IntegerObject\Exceptions\WrongParameterType;

$integer = new IntegerObject(12345);

// int(12345)
var_dump($integer->getValue());

$integerFromString = new IntegerObject("124578");
// int(124578)
var_dump($integerFromString->getValue());

$integerFromFloatString = new IntegerObject("987.0");
// int(987)
var_dump($integerFromFloatString->getValue());

try {
new IntegerObject(987.123);
} catch (WrongParameterType $integerException) {
   // Something get wrong: Some value has been lost on cast. Got '987.456', cast into integer 987
   echo('Something get wrong: ' . $integerException->getMessage() . "\n");
 }

$integerFromTrue = new IntegerObject(true);
// int(1)
var_dump($integerFromTrue->getValue());

$integerFromNull = new IntegerObject(null);
// int(0)
var_dump($integerFromNull->getValue());
// ...

$stringWithAlmostInteger = '0.9999999999999999';
$integerFromStringWithAlmostInteger = new IntegerObject($stringWithAlmostInteger);
// int(1)
var_dump($integerFromStringWithAlmostInteger->getValue());
// int(0) -- because of intval(floatval($value))
var_dump(intval($stringWithAlmostInteger));

```

{'fraction_non_alphanumeric': 0.15521287294669794, 'fraction_numerical': 0.04492122024807241, 'mean_word_length': 6.278048780487805, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '433206', 'n_tokens_mistral': 1020, 'n_tokens_neox': 909, 'n_words': 188}