public function testNoLeadingWhitespace() { $tokenizer = new Tokenizer(); $file = $tokenizer->tokenize('foo.php', "<?php\n"); $rule = new MustStartWithOpenTag(); $rule->visitFile($file); $this->assertRuleViolations($file, array()); }
public function testTabulators() { $tokenizer = new Tokenizer(); $file = $tokenizer->tokenize('foo.php', "<?php\n\t"); $file->rewind(); $file->seekTokenType(T_WHITESPACE); $rule = new DisallowTabulators(); $rule->visitToken($file); $this->assertRuleViolations($file, array(array('line' => 2, 'column' => 1, 'message' => 'Tabulator found', 'source' => 'Flitch\\Whitespace\\DisallowTabulators'))); }
public function testConstantNaming() { $tokenizer = new Tokenizer(); $file = $tokenizer->tokenize('foo.php', "<?php class foo { const BAR = 'baz'; const BAZ = 'bar'; }"); $file->rewind(); $file->seekTokenType(T_CONST); $rule = new Constants(); $rule->setFormat('BAZ'); $rule->visitToken($file); $this->assertRuleViolations($file, array(array('line' => 1, 'column' => 25, 'message' => 'Constant name does not match format "BAZ"', 'source' => 'Flitch\\Naming\\Constants'))); }
public function testClassNaming() { $tokenizer = new Tokenizer(); $file = $tokenizer->tokenize('foo.php', "<?php class foo {} class bar {}"); $file->rewind(); $file->seekTokenType(T_CLASS); $rule = new Classes(); $rule->setFormat('bar'); $rule->visitToken($file); $this->assertRuleViolations($file, array(array('line' => 1, 'column' => 13, 'message' => 'Class name does not match format "bar"', 'source' => 'Flitch\\Naming\\Classes'))); }
public function testNoViolationOnClosures() { $tokenizer = new Tokenizer(); $file = $tokenizer->tokenize('foo.php', "<?php function() {}; class foo {}"); $file->rewind(); $file->seekTokenType(T_FUNCTION); $rule = new Methods(); $rule->setFormat('bar'); $rule->visitToken($file); $this->assertRuleViolations($file, array()); }
/** * Analyze single file for coding standard violations. * * @param string $path * @param Tokenizer $tokenizer * @param Manager $manager * @return File */ protected function analyzeFile($path, Tokenizer $tokenizer, Manager $manager) { $file = $tokenizer->tokenize($path, file_get_contents($path)); $manager->check($file); foreach ($this->reports as $report) { $report->addFile($file); } return $file; }