Fix coding standards

This commit is contained in:
Henrique Moody 2017-11-12 14:21:46 +01:00
parent d8e5f305a7
commit 5b7ea399c0
No known key found for this signature in database
GPG key ID: 221E9281655813A6
2 changed files with 13 additions and 10 deletions

View file

@ -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;
}
}

View file

@ -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'];
});