Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ composer require sysvale/helpers
* removeAccents
* compareVersion
* monthPt
* monthPtAbbr
* removeCrassLetters
* validateCpf
* validateCNPJ
Expand All @@ -54,7 +55,7 @@ composer require sysvale/helpers

#### maskBank
```php
use Sysvale/Helpers;
use Sysvale\Helpers;

$bankNumber = 12345;

Expand All @@ -65,7 +66,7 @@ $maskedBank = Helpers::maskBank($bankNumber);

#### trimpp
```php
use Sysvale/Helpers;
use Sysvale\Helpers;

$text = " Text \t \n "; //String with spaces and special caracter;

Expand All @@ -76,7 +77,7 @@ $text = Helpers::trimpp($text);

#### urlNoCache
```php
use Sysvale/Helpers;
use Sysvale\Helpers;

$url = 'http://url.com.br';

Expand All @@ -85,6 +86,17 @@ $url = Helpers::urlNoCache($url);
// $url will be http://url.com.br?1570588480
```

#### monthPtAbbr
```php
use Sysvale\Helpers;

$month = 1;

$abbr = Helpers::monthPtAbbr($month);

// $abbr will be Jan
```

## Validate class

The validation methods can be accessed directly in the `Validate` class.
Expand All @@ -107,7 +119,7 @@ To use the class import as in the example:
#### isValidCpf

```php
use Sysvale/Helpers/Validate;
use Sysvale\Helpers\Validate;

$value = '334.734.750-17';

Expand All @@ -119,7 +131,7 @@ $isValid = Validate::isValidCpf($value);
#### isValidCnpj

```php
use Sysvale/Helpers/Validate;
use Sysvale\Helpers\Validate;

$value = '56.396.710/0001-37';

Expand All @@ -131,7 +143,7 @@ $isValid = Validate::isValidCnpj($value);
#### isValidPhone

```php
use Sysvale/Helpers/Validate;
use Sysvale\Helpers\Validate;

$value = '79988001010';

Expand All @@ -143,7 +155,7 @@ $isValid = Validate::isValidPhone($value);
#### isValidResidentialPhone

```php
use Sysvale/Helpers/Validate;
use Sysvale\Helpers\Validate;

$value = '7033662200';

Expand All @@ -155,7 +167,7 @@ $isValid = Validate::isValidResidentialPhone($value);
#### isValidMobilePhone

```php
use Sysvale/Helpers/Validate;
use Sysvale\Helpers\Validate;

$value = '70993662200';

Expand Down
9 changes: 9 additions & 0 deletions src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,15 @@ public static function monthPt($value)
return Dates::getMonthNamePtBr($value);
}

/**
* @param int $value
* @return string|null
*/
public static function monthPtAbbr($value)
{
return Dates::getMonthAbbrPtBr($value);
}

/**
* @param string $str
* @return string
Expand Down
26 changes: 26 additions & 0 deletions src/Helpers/Dates.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,32 @@ public static function getMonthNamePtBr($value)
return 1 <= $value && $value <= 12 ? $months[$value] : '';
}

/**
* @param int $value
* @return string|null
*/
public static function getMonthAbbrPtBr($value)
{
$months = [
1 => 'Jan',
2 => 'Fev',
3 => 'Mar',
4 => 'Abr',
5 => 'Mai',
6 => 'Jun',
7 => 'Jul',
8 => 'Ago',
9 => 'Set',
10 => 'Out',
11 => 'Nov',
12 => 'Dez',
];

$value = (int) $value;

return 1 <= $value && $value <= 12 ? $months[$value] : null;
}

/**
* @param string $date
* @return array|string
Expand Down
23 changes: 23 additions & 0 deletions tests/Helpers/DatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@ public function testGetgetMonthNamePtBrBrIsCorrect()
$this->assertEquals("Dezembro", Dates::getMonthNamePtBr(12));
}

public function testGetMonthAbbrPtBrIsCorrect()
{
$this->assertEquals("Jan", Dates::getMonthAbbrPtBr(1));
$this->assertEquals("Fev", Dates::getMonthAbbrPtBr(2));
$this->assertEquals("Mar", Dates::getMonthAbbrPtBr(3));
$this->assertEquals("Abr", Dates::getMonthAbbrPtBr(4));
$this->assertEquals("Mai", Dates::getMonthAbbrPtBr(5));
$this->assertEquals("Jun", Dates::getMonthAbbrPtBr(6));
$this->assertEquals("Jul", Dates::getMonthAbbrPtBr(7));
$this->assertEquals("Ago", Dates::getMonthAbbrPtBr(8));
$this->assertEquals("Set", Dates::getMonthAbbrPtBr(9));
$this->assertEquals("Out", Dates::getMonthAbbrPtBr(10));
$this->assertEquals("Nov", Dates::getMonthAbbrPtBr(11));
$this->assertEquals("Dez", Dates::getMonthAbbrPtBr(12));
}

public function testGetMonthAbbrPtBrReturnsNullForInvalidInput()
{
$this->assertNull(Dates::getMonthAbbrPtBr(0));
$this->assertNull(Dates::getMonthAbbrPtBr(13));
$this->assertNull(Dates::getMonthAbbrPtBr(-1));
}

public function testPtDate2IsoDate()
{
$date = '01/02/2003';
Expand Down
22 changes: 22 additions & 0 deletions tests/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,28 @@ public function testMonthPt()
$this->assertEquals("Dezembro", Helpers::monthPt(12));
}

public function testMonthPtAbbr()
{
$this->assertEquals("Jan", Helpers::monthPtAbbr(1));
$this->assertEquals("Fev", Helpers::monthPtAbbr(2));
$this->assertEquals("Mar", Helpers::monthPtAbbr(3));
$this->assertEquals("Abr", Helpers::monthPtAbbr(4));
$this->assertEquals("Mai", Helpers::monthPtAbbr(5));
$this->assertEquals("Jun", Helpers::monthPtAbbr(6));
$this->assertEquals("Jul", Helpers::monthPtAbbr(7));
$this->assertEquals("Ago", Helpers::monthPtAbbr(8));
$this->assertEquals("Set", Helpers::monthPtAbbr(9));
$this->assertEquals("Out", Helpers::monthPtAbbr(10));
$this->assertEquals("Nov", Helpers::monthPtAbbr(11));
$this->assertEquals("Dez", Helpers::monthPtAbbr(12));
}

public function testMonthPtAbbrReturnsNullForInvalidInput()
{
$this->assertNull(Helpers::monthPtAbbr(0));
$this->assertNull(Helpers::monthPtAbbr(13));
}

public function testUnMaskCpf()
{
$actual = "77298408631";
Expand Down
Loading