Skip to content

Commit

Permalink
Alpha improvement (webmozarts#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrontEndCoffee authored and BackEndTea committed Oct 15, 2019
1 parent 836e707 commit a3a574a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -1132,13 +1132,17 @@ public static function unicodeLetters($value, $message = '')
}

/**
* @psalm-assert string $value
*
* @param mixed $value
* @param string $message
*
* @throws InvalidArgumentException
*/
public static function alpha($value, $message = '')
{
static::string($value);

$locale = \setlocale(LC_CTYPE, 0);
\setlocale(LC_CTYPE, 'C');
$valid = !\ctype_alpha($value);
Expand Down
2 changes: 2 additions & 0 deletions tests/AssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ public function getTests()
array('alpha', array('abcd'), true),
array('alpha', array('ab1cd'), false),
array('alpha', array(''), false),
array('alpha', array(66), false),
array('alpha', array(array()), false),
array('digits', array('1234'), true),
array('digits', array('12a34'), false),
array('digits', array(''), false),
Expand Down
14 changes: 14 additions & 0 deletions tests/static-analysis/assert-alpha.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Webmozart\Assert\Tests\StaticAnalysis;

use Webmozart\Assert\Assert;

/**
* @param mixed $value
*/
function consume($value) : string
{
Assert::alpha($value);
return $value;
}

0 comments on commit a3a574a

Please sign in to comment.