mirror of
https://github.com/Respect/Validation.git
synced 2024-06-29 02:30:06 +02:00
Fix coding standards
This commit is contained in:
parent
d8e5f305a7
commit
5b7ea399c0
|
@ -18,22 +18,25 @@ class Sorted extends AbstractRule
|
|||
|
||||
public function __construct(callable $fn = null, bool $ascending = true)
|
||||
{
|
||||
$this->fn = $fn ?? function($x){ return $x;};
|
||||
$this->fn = $fn ?? function ($x) { return $x;};
|
||||
$this->ascending = $ascending;
|
||||
}
|
||||
|
||||
public function validate($input)
|
||||
{
|
||||
$count = count($input);
|
||||
if ($count < 2)
|
||||
if ($count < 2) {
|
||||
return true;
|
||||
for ($i = 1; $i < $count; $i++) {
|
||||
}
|
||||
for ($i = 1; $i < $count; ++$i) {
|
||||
if (
|
||||
($this->ascending && ($this->fn)($input[$i]) < ($this->fn)($input[$i - 1]))
|
||||
|| (!$this->ascending && ($this->fn)($input[$i]) > ($this->fn)($input[$i - 1]))
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class SortedTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
public function testPasses()
|
||||
{
|
||||
$arr = [1,2,3];
|
||||
$arr = [1, 2, 3];
|
||||
$rule = new Sorted();
|
||||
|
||||
$this->assertTrue($rule->validate($arr));
|
||||
|
@ -30,7 +30,7 @@ class SortedTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testPassesWithEqualValues()
|
||||
{
|
||||
$arr = [1,2,2,3];
|
||||
$arr = [1, 2, 2, 3];
|
||||
$rule = new Sorted();
|
||||
|
||||
$this->assertTrue($rule->validate($arr));
|
||||
|
@ -43,7 +43,7 @@ class SortedTest extends \PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testNotPasses()
|
||||
{
|
||||
$arr = [1,2,4,3];
|
||||
$arr = [1, 2, 4, 3];
|
||||
$rule = new Sorted();
|
||||
|
||||
$this->assertFalse($rule->validate($arr));
|
||||
|
@ -52,7 +52,7 @@ class SortedTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testPassesDescending()
|
||||
{
|
||||
$arr = [10,9,8];
|
||||
$arr = [10, 9, 8];
|
||||
$rule = new Sorted(null, false);
|
||||
|
||||
$this->assertTrue($rule->validate($arr));
|
||||
|
@ -62,7 +62,7 @@ class SortedTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testPassesDescendingWithEqualValues()
|
||||
{
|
||||
$arr = [10,9,9,8];
|
||||
$arr = [10, 9, 9, 8];
|
||||
$rule = new Sorted(null, false);
|
||||
|
||||
$this->assertTrue($rule->validate($arr));
|
||||
|
@ -83,7 +83,7 @@ class SortedTest extends \PHPUnit_Framework_TestCase
|
|||
'key' => 5,
|
||||
],
|
||||
];
|
||||
$rule = new Sorted(function($x){
|
||||
$rule = new Sorted(function ($x) {
|
||||
return $x['key'];
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue