for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Install GitHub App
<?php
/*
* This file is part of Respect/Validation.
*
* (c) Alexandre Gomes Gaigalas <[email protected]>
* For the full copyright and license information, please view the "LICENSE.md"
* file that was distributed with this source code.
*/
namespace Respect\Validation\Rules;
class Sorted extends AbstractRule
{
public function __construct(callable $fn = null, bool $ascending = true)
$this->fn = $fn ?? function($x){ return $x;};
fn
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
$this->ascending = $ascending;
ascending
}
public function validate($input)
$count = count($input);
if($count < 2){
return true;
};
for($i = 1; $i < $count; $i++){
$cmp = $this->ascending === true
? ($this->fn)($input[$i]) > ($this->fn)($input[$i - 1])
: ($this->fn)($input[$i]) < ($this->fn)($input[$i - 1]);
if($cmp === false) return false;
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: