Flitch\File\File::getViolations PHP Method

getViolations() public method

Violations will be sorted by line/column before being returned.
public getViolations ( ) : array
return array
    public function getViolations()
    {
        usort($this->violations, function (Violation $a, Violation $b) {
            if ($a->getLine() === $b->getLine()) {
                if ($a->getColumn() === $b->getColumn()) {
                    return 0;
                }
                return $a->getColumn() < $b->getColumn() ? -1 : 1;
            }
            return $a->getLine() < $b->getLine() ? -1 : 1;
        });
        return $this->violations;
    }

Usage Example

Example #1
0
 /**
  * Assert a specific set of violations.
  *
  * @param  File  $file
  * @param  array $expectedViolations
  * @return void
  */
 public function assertRuleViolations(File $file, array $expectedViolations)
 {
     // Get all violations and convert them to an array for comparision.
     $violations = array();
     foreach ($file->getViolations() as $error) {
         $violations[] = array('line' => $error->getLine(), 'column' => $error->getColumn(), 'message' => $error->getMessage(), 'source' => $error->getSource());
     }
     $this->assertEquals($expectedViolations, $violations);
 }
All Usage Examples Of Flitch\File\File::getViolations