Subversion Repositories Applications.framework

Compare Revisions

No changes between revisions

Ignore whitespace Rev 4 → Rev 5

/trunk/tests/PHP_CodeSniffer-1.2.0RC1/tests/TestSuite.php
New file
0,0 → 1,57
<?php
/**
* A PHP_CodeSniffer specific test suite for PHPUnit.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: TestSuite.php,v 1.2 2007/08/15 01:27:30 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
require_once 'PHPUnit/Framework/TestSuite.php';
 
/**
* A PHP_CodeSniffer specific test suite for PHPUnit.
*
* Unregisters the PHP_CodeSniffer autoload function after the run.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_TestSuite extends PHPUnit_Framework_TestSuite
{
 
 
/**
* Runs the tests and collects their result in a TestResult.
*
* @param PHPUnit_Framework_TestResult $result A test result.
* @param mixed $filter The filter passed to each test.
*
* @return PHPUnit_Framework_TestResult
*/
public function run(PHPUnit_Framework_TestResult $result=null, $filter=false)
{
spl_autoload_register(array('PHP_CodeSniffer', 'autoload'));
$result = parent::run($result, $filter);
spl_autoload_unregister(array('PHP_CodeSniffer', 'autoload'));
return $result;
 
}//end run()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/tests/AllTests.php
New file
0,0 → 1,91
<?php
/**
* A test class for running all PHP_CodeSniffer unit tests.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: AllTests.php,v 1.6 2007/08/15 01:27:30 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (!defined('PHPUnit_MAIN_METHOD')) {
define('PHPUnit_MAIN_METHOD', 'PHP_CodeSniffer_AllTests::main');
}
 
require_once 'TestSuite.php';
require_once 'PHPUnit/TextUI/TestRunner.php';
 
if (is_file(dirname(__FILE__).'/../CodeSniffer.php') === true) {
// We are not installed.
include_once 'Core/AllTests.php';
include_once 'Standards/AllSniffs.php';
include_once dirname(__FILE__).'/../CodeSniffer.php';
} else {
include_once 'CodeSniffer/Core/AllTests.php';
include_once 'CodeSniffer/Standards/AllSniffs.php';
include_once 'PHP/CodeSniffer.php';
}
 
/**
* A test class for running all PHP_CodeSniffer unit tests.
*
* Usage: phpunit AllTests.php
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_AllTests
{
 
 
/**
* Prepare the test runner.
*
* @return void
*/
public static function main()
{
PHPUnit_TextUI_TestRunner::run(self::suite());
 
}//end main()
 
 
/**
* Add all PHP_CodeSniffer test suites into a single test suite.
*
* @return PHPUnit_Framework_TestSuite
*/
public static function suite()
{
// Use a special PHP_CodeSniffer test suite so that we can
// unset our autoload function after the run.
$suite = new PHP_CodeSniffer_TestSuite('PHP CodeSniffer');
 
$suite->addTest(PHP_CodeSniffer_Core_AllTests::suite());
$suite->addTest(PHP_CodeSniffer_Standards_AllSniffs::suite());
 
// Unregister this here because the PEAR tester loads
// all package suites before running then, so our autoloader
// will cause problems for the packages included after us.
spl_autoload_unregister(array('PHP_CodeSniffer', 'autoload'));
 
return $suite;
 
}//end suite()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/tests/Standards/AllSniffs.php
New file
0,0 → 1,134
<?php
/**
* A test class for testing all sniffs for installed standards.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: AllSniffs.php,v 1.7 2007/08/15 01:26:09 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
// Require this here so that the unit tests don't have to try and find the
// abstract class once it is installed into the PEAR tests directory.
require_once dirname(__FILE__).'/AbstractSniffUnitTest.php';
 
/**
* A test class for testing all sniffs for installed standards.
*
* Usage: phpunit AllSniffs.php
*
* This test class loads all unit tests for all installed standards into a
* single test suite and runs them. Errors are reported on the command line.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Standards_AllSniffs
{
 
 
/**
* Prepare the test runner.
*
* @return void
*/
public static function main()
{
PHPUnit_TextUI_TestRunner::run(self::suite());
 
}//end main()
 
 
/**
* Add all sniff unit tests into a test suite.
*
* Sniff unit tests are found by recursing through the 'Tests' directory
* of each installed coding standard.
*
* @return PHPUnit_Framework_TestSuite
*/
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('PHP CodeSniffer Standards');
 
$isInstalled = !is_file(dirname(__FILE__).'/../../CodeSniffer.php');
 
if ($isInstalled === false) {
// We have not been installed.
$standardsDir = realpath(dirname(__FILE__).'/../../CodeSniffer/Standards');
} else {
$standardsDir = '';
}
 
$standards = PHP_CodeSniffer::getInstalledStandards(true, $standardsDir);
 
foreach ($standards as $standard) {
if ($isInstalled === false) {
$standardDir = realpath($standardsDir.'/'.$standard.'/Tests/');
} else {
$standardDir = dirname(__FILE__).'/'.$standard.'/Tests/';
}
 
if (is_dir($standardDir) === false) {
// No tests for this standard.
continue;
}
 
$di = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($standardDir));
 
foreach ($di as $file) {
// Skip hidden files.
if (substr($file->getFilename(), 0, 1) === '.') {
continue;
}
 
// Tests must have the extention 'php'.
$parts = explode('.', $file);
$ext = array_pop($parts);
if ($ext !== 'php') {
continue;
}
 
$filePath = realpath($file->getPathname());
 
if ($isInstalled === false) {
$className = str_replace($standardDir.DIRECTORY_SEPARATOR, '', $filePath);
} else {
$className = str_replace(dirname(__FILE__).DIRECTORY_SEPARATOR, '', $filePath);
}
 
$className = substr($className, 0, -4);
$className = str_replace(DIRECTORY_SEPARATOR, '_', $className);
 
if ($isInstalled === false) {
$className = $standard.'_Tests_'.$className;
}
 
$niceName = substr($className, (strrpos($className, '_') + 1), -8);
 
include_once $filePath;
$class = new $className($niceName);
$suite->addTest($class);
}//end foreach
}//end foreach
 
return $suite;
 
}//end suite()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/tests/Standards/AbstractSniffUnitTest.php
New file
0,0 → 1,377
<?php
/**
* An abstract class that all sniff unit tests must extend.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: AbstractSniffUnitTest.php,v 1.14 2009/01/29 23:38:35 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
require_once 'PHPUnit/Framework/TestCase.php';
 
/**
* An abstract class that all sniff unit tests must extend.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings that are not found, or
* warnings and errors that are not expected, are considered test failures.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
abstract class AbstractSniffUnitTest extends PHPUnit_Framework_TestCase
{
 
/**
* The PHP_CodeSniffer object used for testing.
*
* @var PHP_CodeSniffer
*/
protected static $phpcs = null;
 
 
/**
* Sets up this unit test.
*
* @return void
*/
protected function setUp()
{
if (self::$phpcs === null) {
self::$phpcs = new PHP_CodeSniffer();
}
 
}//end setUp()
 
 
/**
* Should this test be skipped for some reason.
*
* @return void
*/
protected function shouldSkipTest()
{
return false;
 
}//end shouldSkipTest()
 
 
/**
* Tests the extending classes Sniff class.
*
* @return void
* @throws PHPUnit_Framework_Error
*/
protected final function runTest()
{
// Skip this test if we can't run in this environment.
if ($this->shouldSkipTest() === true) {
$this->markTestSkipped();
}
 
// The basis for determining file locations.
$basename = substr(get_class($this), 0, -8);
 
// The name of the coding standard we are testing.
$standardName = substr($basename, 0, strpos($basename, '_'));
 
// The class name of the sniff we are testing.
$sniffClass = str_replace('_Tests_', '_Sniffs_', $basename).'Sniff';
 
if (is_file(dirname(__FILE__).'/../../CodeSniffer.php') === true) {
// We have not been installed.
$standardsDir = realpath(dirname(__FILE__).'/../../CodeSniffer/Standards');
$testFileBase = $standardsDir.'/'.str_replace('_', '/', $basename).'UnitTest.';
} else {
// The name of the dummy file we are testing.
$testFileBase = dirname(__FILE__).'/'.str_replace('_', '/', $basename).'UnitTest.';
}
 
// Get a list of all test files to check. These will have the same base
// name but different extensions. We ignore the .php file as it is the
// class.
$testFiles = array();
 
$dir = substr($testFileBase, 0, strrpos($testFileBase, '/'));
$di = new DirectoryIterator($dir);
 
foreach ($di as $file) {
$path = $file->getPathname();
if (substr($path, 0, strlen($testFileBase)) === $testFileBase) {
if ($path !== $testFileBase.'php') {
$testFiles[] = $path;
}
}
}
 
// Get them in order. This is particularly important for multi-file sniffs.
sort($testFiles);
 
$failureMessages = array();
$multiFileSniff = false;
foreach ($testFiles as $testFile) {
try {
self::$phpcs->process($testFile, $standardName, array($sniffClass));
} catch (Exception $e) {
$this->fail('An unexpected exception has been caught: '.$e->getMessage());
}
 
// After processing a file, check if the sniff was actually
// a multi-file sniff (i.e., had no indivdual file sniffs).
// If it is, we can skip checking of the other files and
// do a single multi-file check.
$sniffs = self::$phpcs->getTokenSniffs();
if (empty($sniffs['file']) === true) {
$multiFileSniff = true;
break;
}
 
$files = self::$phpcs->getFiles();
$file = array_pop($files);
 
$failures = $this->generateFailureMessages($file, $testFile);
$failureMessages = array_merge($failureMessages, $failures);
}//end foreach
 
if ($multiFileSniff === true) {
try {
self::$phpcs->process($testFiles, $standardName, array($sniffClass));
} catch (Exception $e) {
$this->fail('An unexpected exception has been caught: '.$e->getMessage());
}
 
$files = self::$phpcs->getFiles();
foreach ($files as $file) {
$failures = $this->generateFailureMessages($file);
$failureMessages = array_merge($failureMessages, $failures);
}
}
 
if (empty($failureMessages) === false) {
$this->fail(implode(PHP_EOL, $failureMessages));
}
 
}//end testSniff()
 
 
/**
* Generate a list of test failures for a given sniffed file.
*
* @return array
* @throws PHP_CodeSniffer_Exception
*/
public function generateFailureMessages($file)
{
$testFile = $file->getFilename();
 
$foundErrors = $file->getErrors();
$foundWarnings = $file->getWarnings();
$expectedErrors = $this->getErrorList(basename($testFile));
$expectedWarnings = $this->getWarningList(basename($testFile));
 
if (is_array($expectedErrors) === false) {
throw new PHP_CodeSniffer_Exception('getErrorList() must return an array');
}
 
if (is_array($expectedWarnings) === false) {
throw new PHP_CodeSniffer_Exception('getWarningList() must return an array');
}
 
/*
We merge errors and warnings together to make it easier
to iterate over them and produce the errors string. In this way,
we can report on errors and warnings in the same line even though
it's not really structured to allow that.
*/
 
$allProblems = array();
$failureMessages = array();
 
foreach ($foundErrors as $line => $lineErrors) {
foreach ($lineErrors as $column => $errors) {
if (isset($allProblems[$line]) === false) {
$allProblems[$line] = array(
'expected_errors' => 0,
'expected_warnings' => 0,
'found_errors' => array(),
'found_warnings' => array(),
);
}
 
$foundErrorsTemp = array();
foreach ($allProblems[$line]['found_errors'] as $foundError) {
$foundErrorsTemp[] = $foundError['message'];
}
 
$errorsTemp = array();
foreach ($errors as $foundError) {
$errorsTemp[] = $foundError['message'];
}
 
$allProblems[$line]['found_errors'] = array_merge($foundErrorsTemp, $errorsTemp);
}
 
if (isset($expectedErrors[$line]) === true) {
$allProblems[$line]['expected_errors'] = $expectedErrors[$line];
} else {
$allProblems[$line]['expected_errors'] = 0;
}
 
unset($expectedErrors[$line]);
}//end foreach
 
foreach ($expectedErrors as $line => $numErrors) {
if (isset($allProblems[$line]) === false) {
$allProblems[$line] = array(
'expected_errors' => 0,
'expected_warnings' => 0,
'found_errors' => array(),
'found_warnings' => array(),
);
}
 
$allProblems[$line]['expected_errors'] = $numErrors;
}
 
foreach ($foundWarnings as $line => $lineWarnings) {
foreach ($lineWarnings as $column => $warnings) {
if (isset($allProblems[$line]) === false) {
$allProblems[$line] = array(
'expected_errors' => 0,
'expected_warnings' => 0,
'found_errors' => array(),
'found_warnings' => array(),
);
}
 
$warningsTemp = array();
foreach ($warnings as $warning) {
$warningsTemp[] = $warning['message'];
}
 
$allProblems[$line]['found_warnings'] = $warningsTemp;
}
 
if (isset($expectedWarnings[$line]) === true) {
$allProblems[$line]['expected_warnings'] = $expectedWarnings[$line];
} else {
$allProblems[$line]['expected_warnings'] = 0;
}
 
unset($expectedWarnings[$line]);
}//end foreach
 
foreach ($expectedWarnings as $line => $numWarnings) {
if (isset($allProblems[$line]) === false) {
$allProblems[$line] = array(
'expected_errors' => 0,
'expected_warnings' => 0,
'found_errors' => array(),
'found_warnings' => array(),
);
}
 
$allProblems[$line]['expected_warnings'] = $numWarnings;
}
 
// Order the messages by line number.
ksort($allProblems);
 
foreach ($allProblems as $line => $problems) {
$numErrors = count($problems['found_errors']);
$numWarnings = count($problems['found_warnings']);
$expectedErrors = $problems['expected_errors'];
$expectedWarnings = $problems['expected_warnings'];
 
$errors = '';
$foundString = '';
 
if ($expectedErrors !== $numErrors || $expectedWarnings !== $numWarnings) {
$lineMessage = "[LINE $line]";
$expectedMessage = 'Expected ';
$foundMessage = 'in '.basename($testFile).' but found ';
 
if ($expectedErrors !== $numErrors) {
$expectedMessage .= "$expectedErrors error(s)";
$foundMessage .= "$numErrors error(s)";
if ($numErrors !== 0) {
$foundString .= 'error(s)';
$errors .= implode(PHP_EOL.' -> ', $problems['found_errors']);
}
 
if ($expectedWarnings !== $numWarnings) {
$expectedMessage .= ' and ';
$foundMessage .= ' and ';
if ($numWarnings !== 0) {
if ($foundString !== '') {
$foundString .= ' and ';
}
}
}
}
 
if ($expectedWarnings !== $numWarnings) {
$expectedMessage .= "$expectedWarnings warning(s)";
$foundMessage .= "$numWarnings warning(s)";
if ($numWarnings !== 0) {
$foundString .= 'warning(s)';
if (empty($errors) === false) {
$errors .= PHP_EOL.' -> ';
}
 
$errors .= implode(PHP_EOL.' -> ', $problems['found_warnings']);
}
}
 
$fullMessage = "$lineMessage $expectedMessage $foundMessage.";
if ($errors !== '') {
$fullMessage .= " The $foundString found were:".PHP_EOL." -> $errors";
}
 
$failureMessages[] = $fullMessage;
}//end if
}//end foreach
 
return $failureMessages;
 
}//end generateFailureMessages()
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
protected abstract function getErrorList();
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
protected abstract function getWarningList();
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/tests/Core/IsCamelCapsTest.php
New file
0,0 → 1,153
<?php
/**
* Tests for the PHP_CodeSniffer:isCamelCaps method.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: IsCamelCapsTest.php,v 1.5 2007/08/02 00:05:40 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
require_once 'PHPUnit/Framework/TestCase.php';
 
/**
* Tests for the PHP_CodeSniffer:isCamelCaps method.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Core_IsCamelCapsTest extends PHPUnit_Framework_TestCase
{
 
 
/**
* Test valid public function/method names.
*
* @return void
*/
public function testValidNotClassFormatPublic()
{
$this->assertTrue(PHP_CodeSniffer::isCamelCaps('thisIsCamelCaps', false, true, true));
$this->assertTrue(PHP_CodeSniffer::isCamelCaps('thisISCamelCaps', false, true, false));
 
}//end testValidNotClassFormatPublic()
 
 
/**
* Test invalid public function/method names.
*
* @return void
*/
public function testInvalidNotClassFormatPublic()
{
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('_thisIsCamelCaps', false, true, true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('thisISCamelCaps', false, true, true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('ThisIsCamelCaps', false, true, true));
 
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('3thisIsCamelCaps', false, true, true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('*thisIsCamelCaps', false, true, true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('-thisIsCamelCaps', false, true, true));
 
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('this*IsCamelCaps', false, true, true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('this-IsCamelCaps', false, true, true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('this_IsCamelCaps', false, true, true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('this_is_camel_caps', false, true, true));
 
}//end testInvalidNotClassFormatPublic()
 
 
/**
* Test valid private method names.
*
* @return void
*/
public function testValidNotClassFormatPrivate()
{
$this->assertTrue(PHP_CodeSniffer::isCamelCaps('_thisIsCamelCaps', false, false, true));
$this->assertTrue(PHP_CodeSniffer::isCamelCaps('_thisISCamelCaps', false, false, false));
$this->assertTrue(PHP_CodeSniffer::isCamelCaps('_i18N', false, false, true));
$this->assertTrue(PHP_CodeSniffer::isCamelCaps('_i18n', false, false, true));
 
}//end testValidNotClassFormatPrivate()
 
 
/**
* Test invalid private method names.
*
* @return void
*/
public function testInvalidNotClassFormatPrivate()
{
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('thisIsCamelCaps', false, false, true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('_thisISCamelCaps', false, false, true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('_ThisIsCamelCaps', false, false, true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('__thisIsCamelCaps', false, false, true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('__thisISCamelCaps', false, false, false));
 
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('3thisIsCamelCaps', false, false, true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('*thisIsCamelCaps', false, false, true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('-thisIsCamelCaps', false, false, true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('_this_is_camel_caps', false, false, true));
 
}//end testInvalidNotClassFormatPrivate()
 
 
/**
* Test valid class names.
*
* @return void
*/
public function testValidClassFormatPublic()
{
$this->assertTrue(PHP_CodeSniffer::isCamelCaps('ThisIsCamelCaps', true, true, true));
$this->assertTrue(PHP_CodeSniffer::isCamelCaps('ThisISCamelCaps', true, true, false));
 
}//end testValidClassFormatPublic()
 
 
/**
* Test invalid class names.
*
* @return void
*/
public function testInvalidClassFormat()
{
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('thisIsCamelCaps', true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('This3IsCamelCaps', true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('This-IsCamelCaps', true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('This_Is_Camel_Caps', true));
 
}//end testInvalidClassFormat()
 
 
/**
* Test invalid class names with the private flag set.
*
* Note that the private flag is ignored if the class format
* flag is set, so these names are all invalid.
*
* @return void
*/
public function testInvalidClassFormatPrivate()
{
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('_ThisIsCamelCaps', true, true));
$this->assertFalse(PHP_CodeSniffer::isCamelCaps('_ThisIsCamelCaps', true, false));
 
}//end testInvalidClassFormatPrivate()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/tests/Core/AllTests.php
New file
0,0 → 1,66
<?php
/**
* A test class for testing the core.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: AllTests.php,v 1.4 2007/07/23 01:47:54 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
require_once 'IsCamelCapsTest.php';
 
/**
* A test class for testing the core.
*
* Do not run this file directly. Run the AllSniffs.php file in the root
* testing directory of PHP_CodeSniffer.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Core_AllTests
{
 
 
/**
* Prepare the test runner.
*
* @return void
*/
public static function main()
{
PHPUnit2_TextUI_TestRunner::run(self::suite());
 
}//end main()
 
 
/**
* Add all core unit tests into a test suite.
*
* @return PHPUnit_Framework_TestSuite
*/
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('PHP CodeSniffer Core');
$suite->addTestSuite('Core_IsCamelCapsTest');
return $suite;
 
}//end suite()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/AbstractVariableSniff.php
New file
0,0 → 1,236
<?php
/**
* A class to find T_VARIABLE tokens.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: AbstractVariableSniff.php,v 1.15 2008/12/01 05:41:28 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) {
$error = 'Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* A class to find T_VARIABLE tokens.
*
* This class can distingush between normal T_VARIABLE tokens, and those tokens
* that represent class members. If a class member is encountered, then then
* processMemberVar method is called so the extending class can process it. If
* the token is found to be a normal T_VARIABLE token, then processVariable is
* called.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
abstract class PHP_CodeSniffer_Standards_AbstractVariableSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff
{
 
/**
* The end token of the current function that we are in.
*
* @var int
*/
private $_endFunction = -1;
 
/**
* true if a function is currently open.
*
* @var boolean
*/
private $_functionOpen = false;
 
/**
* The current PHP_CodeSniffer file that we are processing.
*
* @var PHP_CodeSniffer_File
*/
protected $currentFile = null;
 
 
/**
* Constructs an AbstractVariableTest.
*/
public function __construct()
{
$listen = array(
T_CLASS,
T_INTERFACE,
);
 
$scopes = array(
T_FUNCTION,
T_VARIABLE,
T_DOUBLE_QUOTED_STRING,
);
 
parent::__construct($listen, $scopes, true);
 
}//end __construct()
 
 
/**
* Processes the token in the specified PHP_CodeSniffer_File.
*
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this
* token was found.
* @param int $stackPtr The position where the token was found.
* @param array $currScope The current scope opener token.
*
* @return void
*/
protected final function processTokenWithinScope(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr,
$currScope
) {
if ($this->currentFile !== $phpcsFile) {
$this->currentFile = $phpcsFile;
$this->_functionOpen = false;
$this->_endFunction = -1;
}
 
$tokens = $phpcsFile->getTokens();
 
if ($stackPtr > $this->_endFunction) {
$this->_functionOpen = false;
}
 
if ($tokens[$stackPtr]['code'] === T_FUNCTION
&& $this->_functionOpen === false
) {
$this->_functionOpen = true;
 
$methodProps = $phpcsFile->getMethodProperties($stackPtr);
 
// If the function is abstract, or is in an interface,
// then set the end of the function to it's closing semicolon.
if ($methodProps['is_abstract'] === true
|| $tokens[$currScope]['code'] === T_INTERFACE
) {
$this->_endFunction
= $phpcsFile->findNext(array(T_SEMICOLON), $stackPtr);
} else {
if (isset($tokens[$stackPtr]['scope_closer']) === false) {
$error = 'Possible parse error: non-abstract method defined as abstract';
$phpcsFile->addWarning($error, $stackPtr);
return;
}
 
$this->_endFunction = $tokens[$stackPtr]['scope_closer'];
}
 
}
 
if ($this->_functionOpen === true) {
if ($tokens[$stackPtr]['code'] === T_VARIABLE) {
$this->processVariable($phpcsFile, $stackPtr);
} else if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING) {
// Check to see if this string has a variable in it.
$pattern = '|[^\\\]\$[a-zA-Z0-9_]+|';
if (preg_match($pattern, $tokens[$stackPtr]['content']) !== 0) {
$this->processVariableInString($phpcsFile, $stackPtr);
}
}
 
return;
} else {
// What if we assign a member variable to another?
// ie. private $_count = $this->_otherCount + 1;.
$this->processMemberVar($phpcsFile, $stackPtr);
}
 
}//end processTokenWithinScope()
 
 
/**
* Processes the token outside the scope in the file.
*
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this
* token was found.
* @param int $stackPtr The position where the token was found.
*
* @return void
*/
protected final function processTokenOutsideScope(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr
) {
$tokens = $phpcsFile->getTokens();
// These variables are not member vars.
if ($tokens[$stackPtr]['code'] === T_VARIABLE) {
$this->processVariable($phpcsFile, $stackPtr);
} else {
$this->processVariableInString($phpcsFile, $stackPtr);
}
 
}//end processTokenOutsideScope()
 
 
/**
* Called to process class member vars.
*
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this
* token was found.
* @param int $stackPtr The position where the token was found.
*
* @return void
*/
abstract protected function processMemberVar(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr
);
 
 
/**
* Called to process normal member vars.
*
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this
* token was found.
* @param int $stackPtr The position where the token was found.
*
* @return void
*/
abstract protected function processVariable(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr
);
 
 
/**
* Called to process variables found in duoble quoted strings.
*
* Note that there may be more than one variable in the string, which will
* result only in one call for the string.
*
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this
* token was found.
* @param int $stackPtr The position where the double quoted
* string was found.
*
* @return void
*/
abstract protected function processVariableInString(
PHP_CodeSniffer_File
$phpcsFile,
$stackPtr
);
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Docs/Functions/ValidDefaultValueStandard.xml
New file
0,0 → 1,25
<documentation title="Default Values in Function Declarations">
<standard>
<![CDATA[
Arguments with default values go at the end of the argument list.
]]>
</standard>
<code_comparison>
<code title="Valid: argument with default value at end of declaration">
<![CDATA[
function connect($dsn, <em>$persistent = false</em>)
{
...
}
]]>
</code>
<code title="Invalid: argument with default value at start of declaration">
<![CDATA[
function connect(<em>$persistent = false</em>, $dsn)
{
...
}
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Docs/Functions/FunctionCallSignatureStandard.xml
New file
0,0 → 1,19
<documentation title="Function Calls">
<standard>
<![CDATA[
Functions should be called with no spaces between the function name, the opening parenthesis, and the first parameter; and no space between the last parameter, the closing parenthesis, and the semicolon.
]]>
</standard>
<code_comparison>
<code title="Valid: spaces between parameters">
<![CDATA[
$var = foo($bar, $baz, $quux);
]]>
</code>
<code title="Invalid: additional spaces used">
<![CDATA[
$var = foo<em> </em>(<em> </em>$bar, $baz, $quux<em> </em>)<em> </em>;
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Docs/Functions/FunctionCallArgumentSpacingStandard.xml
New file
0,0 → 1,19
<documentation title="Parameter Spacing in Function Calls">
<standard>
<![CDATA[
There must be one space between a comma and a parameter in a function call.
]]>
</standard>
<code_comparison>
<code title="Valid: spaces between parameters">
<![CDATA[
$var = foo($bar<em>, </em>$baz<em>, </em>$quux);
]]>
</code>
<code title="Invalid: no space between commas and parameters">
<![CDATA[
$var = foo($bar<em>,</em>$baz<em>,</em>$quux);
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Docs/NamingConventions/ValidClassNameStandard.xml
New file
0,0 → 1,23
<documentation title="Class Names">
<standard>
<![CDATA[
Classes should be given descriptive names. Avoid using abbreviations where possible. Class names should always begin with an uppercase letter. The PEAR class hierarchy is also reflected in the class name, each level of the hierarchy separated with a single underscore.
]]>
</standard>
<code_comparison>
<code title="Examples of valid class names">
<![CDATA[
Log
Net_Finger
HTML_Upload_Error
]]>
</code>
<code title="Examples of invalid class names">
<![CDATA[
log
NetFinger
HTML-Upload-Error
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Docs/NamingConventions/ValidFunctionNameStandard.xml
New file
0,0 → 1,23
<documentation title="Function and Method Names">
<standard>
<![CDATA[
Functions and methods should be named using the "studly caps" style (also referred to as "bumpy case" or "camel caps"). Functions should in addition have the package name as a prefix, to avoid name collisions between packages. The initial letter of the name (after the prefix) is lowercase, and each letter that starts a new "word" is capitalized.
]]>
</standard>
<code_comparison>
<code title="Examples of valid function names">
<![CDATA[
connect()
getData()
buildSomeWidget()
XML_RPC_serializeData()
]]>
</code>
<code title="Examples of invalid function names">
<![CDATA[
Connect()
get_data()
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Docs/Files/LineLengthStandard.xml
New file
0,0 → 1,7
<documentation title="Line Length">
<standard>
<![CDATA[
It is recommended to keep lines at approximately 85 characters long for better code readability.
]]>
</standard>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Docs/Files/IncludingFileStandard.xml
New file
0,0 → 1,24
<documentation title="Including Code">
<standard>
<![CDATA[
Anywhere you are unconditionally including a class file, use <em>require_once</em>. Anywhere you are conditionally including a class file (for example, factory methods), use <em>include_once</em>. Either of these will ensure that class files are included only once. They share the same file list, so you don't need to worry about mixing them - a file included with <em>require_once</em> will not be included again by <em>include_once</em>.
]]>
</standard>
<standard>
<![CDATA[
Note that <em>include_once</em> and <em>require_once</em> are statements, not functions. Parentheses should not surround the subject filename.
]]>
</standard>
<code_comparison>
<code title="Valid: used as statement">
<![CDATA[
require_once 'PHP/CodeSniffer.php';
]]>
</code>
<code title="Invalid: used as function">
<![CDATA[
require_once<em>(</em>'PHP/CodeSniffer.php'<em>)</em>;
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Classes/ClassDeclarationSniff.php
New file
0,0 → 1,116
<?php
/**
* Class Declaration Test.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ClassDeclarationSniff.php,v 1.5 2008/05/19 05:59:25 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Class Declaration Test.
*
* Checks the declaration of the class is correct.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_Classes_ClassDeclarationSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_CLASS,
T_INTERFACE,
);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
$error = 'Possible parse error: ';
$error .= $tokens[$stackPtr]['content'];
$error .= ' missing opening or closing brace';
$phpcsFile->addWarning($error, $stackPtr);
return;
}
 
$curlyBrace = $tokens[$stackPtr]['scope_opener'];
$lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($curlyBrace - 1), $stackPtr, true);
$classLine = $tokens[$lastContent]['line'];
$braceLine = $tokens[$curlyBrace]['line'];
if ($braceLine === $classLine) {
$error = 'Opening brace of a ';
$error .= $tokens[$stackPtr]['content'];
$error .= ' must be on the line after the definition';
$phpcsFile->addError($error, $curlyBrace);
return;
} else if ($braceLine > ($classLine + 1)) {
$difference = ($braceLine - $classLine - 1);
$difference .= ($difference === 1) ? ' line' : ' lines';
$error = 'Opening brace of a ';
$error .= $tokens[$stackPtr]['content'];
$error .= ' must be on the line following the ';
$error .= $tokens[$stackPtr]['content'];
$error .= ' declaration; found '.$difference;
$phpcsFile->addError($error, $curlyBrace);
return;
}
 
if ($tokens[($curlyBrace + 1)]['content'] !== $phpcsFile->eolChar) {
$type = strtolower($tokens[$stackPtr]['content']);
$error = "Opening $type brace must be on a line by itself";
$phpcsFile->addError($error, $curlyBrace);
}
 
if ($tokens[($curlyBrace - 1)]['code'] === T_WHITESPACE) {
$prevContent = $tokens[($curlyBrace - 1)]['content'];
if ($prevContent !== $phpcsFile->eolChar) {
$blankSpace = substr($prevContent, strpos($prevContent, $phpcsFile->eolChar));
$spaces = strlen($blankSpace);
if ($spaces !== 0) {
$error = "Expected 0 spaces before opening brace; $spaces found";
$phpcsFile->addError($error, $curlyBrace);
}
}
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidClassNameSniff.php
New file
0,0 → 1,113
<?php
/**
* PEAR_Sniffs_NamingConventions_ValidClassNameSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ValidClassNameSniff.php,v 1.10 2008/04/28 01:02:28 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_NamingConventions_ValidClassNameSniff.
*
* Ensures class and interface names start with a capital letter
* and use _ separators.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_NamingConventions_ValidClassNameSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_CLASS,
T_INTERFACE,
);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The current file being processed.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
$className = $phpcsFile->findNext(T_STRING, $stackPtr);
$name = trim($tokens[$className]['content']);
 
// Make sure the first letter is a capital.
if (preg_match('|^[A-Z]|', $name) === 0) {
$error = ucfirst($tokens[$stackPtr]['content']).' name must begin with a capital letter';
$phpcsFile->addError($error, $stackPtr);
}
 
// Check that each new word starts with a capital as well, but don't
// check the first word, as it is checked above.
$validName = true;
$nameBits = explode('_', $name);
$firstBit = array_shift($nameBits);
foreach ($nameBits as $bit) {
if ($bit === '' || $bit{0} !== strtoupper($bit{0})) {
$validName = false;
break;
}
}
 
if ($validName !== true) {
// Strip underscores because they cause the suggested name
// to be incorrect.
$nameBits = explode('_', trim($name, '_'));
$firstBit = array_shift($nameBits);
if ($firstBit === '') {
$error = ucfirst($tokens[$stackPtr]['content']).' name is not valid';
} else {
$newName = strtoupper($firstBit{0}).substr($firstBit, 1).'_';
foreach ($nameBits as $bit) {
if ($bit !== '') {
$newName .= strtoupper($bit{0}).substr($bit, 1).'_';
}
}
 
$newName = rtrim($newName, '_');
$error = ucfirst($tokens[$stackPtr]['content'])." name is not valid; consider $newName instead";
}
 
$phpcsFile->addError($error, $stackPtr);
}//end if
 
}//end process()
 
 
}//end class
 
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidFunctionNameSniff.php
New file
0,0 → 1,263
<?php
/**
* PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ValidFunctionNameSniff.php,v 1.18 2008/01/22 23:50:23 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) {
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found');
}
 
/**
* PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff.
*
* Ensures method names are correct depending on whether they are public
* or private, and that functions are named correctly.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff
{
 
/**
* A list of all PHP magic methods.
*
* @var array
*/
private $_magicMethods = array(
'construct',
'destruct',
'call',
'callStatic',
'get',
'set',
'isset',
'unset',
'sleep',
'wakeup',
'toString',
'set_state',
'clone',
);
 
/**
* A list of all PHP magic functions.
*
* @var array
*/
private $_magicFunctions = array(
'autoload',
);
 
 
/**
* Constructs a PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff.
*/
public function __construct()
{
parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION), true);
 
}//end __construct()
 
 
/**
* Processes the tokens within the scope.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being processed.
* @param int $stackPtr The position where this token was
* found.
* @param int $currScope The position of the current scope.
*
* @return void
*/
protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
{
$className = $phpcsFile->getDeclarationName($currScope);
$methodName = $phpcsFile->getDeclarationName($stackPtr);
 
// Is this a magic method. IE. is prefixed with "__".
if (preg_match('|^__|', $methodName) !== 0) {
$magicPart = substr($methodName, 2);
if (in_array($magicPart, $this->_magicMethods) === false) {
$error = "Method name \"$className::$methodName\" is invalid; only PHP magic methods should be prefixed with a double underscore";
$phpcsFile->addError($error, $stackPtr);
}
 
return;
}
 
// PHP4 constructors are allowed to break our rules.
if ($methodName === $className) {
return;
}
 
// PHP4 destructors are allowed to break our rules.
if ($methodName === '_'.$className) {
return;
}
 
$methodProps = $phpcsFile->getMethodProperties($stackPtr);
$isPublic = ($methodProps['scope'] === 'private') ? false : true;
$scope = $methodProps['scope'];
$scopeSpecified = $methodProps['scope_specified'];
 
// If it's a private method, it must have an underscore on the front.
if ($isPublic === false && $methodName{0} !== '_') {
$error = "Private method name \"$className::$methodName\" must be prefixed with an underscore";
$phpcsFile->addError($error, $stackPtr);
return;
}
 
// If it's not a private method, it must not have an underscore on the front.
if ($isPublic === true && $scopeSpecified === true && $methodName{0} === '_') {
$error = ucfirst($scope)." method name \"$className::$methodName\" must not be prefixed with an underscore";
$phpcsFile->addError($error, $stackPtr);
return;
}
 
// If the scope was specified on the method, then the method must be
// camel caps and an underscore should be checked for. If it wasn't
// specified, treat it like a public method and remove the underscore
// prefix if there is one because we cant determine if it is private or
// public.
$testMethodName = $methodName;
if ($scopeSpecified === false && $methodName{0} === '_') {
$testMethodName = substr($methodName, 1);
}
 
if (PHP_CodeSniffer::isCamelCaps($testMethodName, false, $isPublic, false) === false) {
if ($scopeSpecified === true) {
$error = ucfirst($scope)." method name \"$className::$methodName\" is not in camel caps format";
} else {
$error = "Method name \"$className::$methodName\" is not in camel caps format";
}
 
$phpcsFile->addError($error, $stackPtr);
return;
}
 
}//end processTokenWithinScope()
 
 
/**
* Processes the tokens outside the scope.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being processed.
* @param int $stackPtr The position where this token was
* found.
*
* @return void
*/
protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$functionName = $phpcsFile->getDeclarationName($stackPtr);
 
// Is this a magic function. IE. is prefixed with "__".
if (preg_match('|^__|', $functionName) !== 0) {
$magicPart = substr($functionName, 2);
if (in_array($magicPart, $this->_magicFunctions) === false) {
$error = "Function name \"$functionName\" is invalid; only PHP magic methods should be prefixed with a double underscore";
$phpcsFile->addError($error, $stackPtr);
}
 
return;
}
 
// Function names can be in two parts; the package name and
// the function name.
$packagePart = '';
$camelCapsPart = '';
$underscorePos = strrpos($functionName, '_');
if ($underscorePos === false) {
$camelCapsPart = $functionName;
} else {
$packagePart = substr($functionName, 0, $underscorePos);
$camelCapsPart = substr($functionName, ($underscorePos + 1));
 
// We don't care about _'s on the front.
$packagePart = ltrim($packagePart, '_');
}
 
// If it has a package part, make sure the first letter is a capital.
if ($packagePart !== '') {
if ($functionName{0} === '_') {
$error = "Function name \"$functionName\" is invalid; only private methods should be prefixed with an underscore";
$phpcsFile->addError($error, $stackPtr);
return;
}
 
if ($functionName{0} !== strtoupper($functionName{0})) {
$error = "Function name \"$functionName\" is prefixed with a package name but does not begin with a capital letter";
$phpcsFile->addError($error, $stackPtr);
return;
}
}
 
// If it doesn't have a camel caps part, it's not valid.
if (trim($camelCapsPart) === '') {
$error = "Function name \"$functionName\" is not valid; name appears incomplete";
$phpcsFile->addError($error, $stackPtr);
return;
}
 
$validName = true;
$newPackagePart = $packagePart;
$newCamelCapsPart = $camelCapsPart;
 
// Every function must have a camel caps part, so check that first.
if (PHP_CodeSniffer::isCamelCaps($camelCapsPart, false, true, false) === false) {
$validName = false;
$newCamelCapsPart = strtolower($camelCapsPart{0}).substr($camelCapsPart, 1);
}
 
if ($packagePart !== '') {
// Check that each new word starts with a capital.
$nameBits = explode('_', $packagePart);
foreach ($nameBits as $bit) {
if ($bit{0} !== strtoupper($bit{0})) {
$newPackagePart = '';
foreach ($nameBits as $bit) {
$newPackagePart .= strtoupper($bit{0}).substr($bit, 1).'_';
}
 
$validName = false;
break;
}
}
}
 
if ($validName === false) {
$newName = rtrim($newPackagePart, '_').'_'.$newCamelCapsPart;
if ($newPackagePart === '') {
$newName = $newCamelCapsPart;
} else {
$newName = rtrim($newPackagePart, '_').'_'.$newCamelCapsPart;
}
 
$error = "Function name \"$functionName\" is invalid; consider \"$newName\" instead";
$phpcsFile->addError($error, $stackPtr);
}
 
}//end processTokenOutsideScope()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidVariableNameSniff.php
New file
0,0 → 1,112
<?php
/**
* PEAR_Sniffs_NamingConventions_ValidVariableNameSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ValidVariableNameSniff.php,v 1.2 2008/06/13 04:10:43 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) {
$error = 'Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* PEAR_Sniffs_NamingConventions_ValidVariableNameSniff.
*
* Checks the naming of member variables.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_NamingConventions_ValidVariableNameSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff
{
 
 
/**
* Processes class member variables.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
$memberProps = $phpcsFile->getMemberProperties($stackPtr);
if (empty($memberProps) === true) {
return;
}
 
$memberName = ltrim($tokens[$stackPtr]['content'], '$');
$isPublic = ($memberProps['scope'] === 'private') ? false : true;
$scope = $memberProps['scope'];
$scopeSpecified = $memberProps['scope_specified'];
 
// If it's a private member, it must have an underscore on the front.
if ($isPublic === false && $memberName{0} !== '_') {
$error = "Private member variable \"$memberName\" must be prefixed with an underscore";
$phpcsFile->addError($error, $stackPtr);
return;
}
 
// If it's not a private member, it must not have an underscore on the front.
if ($isPublic === true && $scopeSpecified === true && $memberName{0} === '_') {
$error = ucfirst($scope)." member variable \"$memberName\" must not be prefixed with an underscore";
$phpcsFile->addError($error, $stackPtr);
return;
}
 
}//end processMemberVar()
 
 
/**
* Processes normal variables.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
* @param int $stackPtr The position where the token was found.
*
* @return void
*/
protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
// We don't care about normal variables.
return;
 
}//end processVariable()
 
 
/**
* Processes variables in double quoted strings.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
* @param int $stackPtr The position where the token was found.
*
* @return void
*/
protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
// We don't care about normal variables.
return;
 
}//end processVariableInString()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php
New file
0,0 → 1,762
<?php
/**
* Parses and verifies the doc comments for files.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: FileCommentSniff.php,v 1.32 2009/02/10 06:01:46 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_CommentParser_ClassCommentParser', true) === false) {
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_CommentParser_ClassCommentParser not found');
}
 
/**
* Parses and verifies the doc comments for files.
*
* Verifies that :
* <ul>
* <li>A doc comment exists.</li>
* <li>There is a blank newline after the short description.</li>
* <li>There is a blank newline between the long and short description.</li>
* <li>There is a blank newline between the long description and tags.</li>
* <li>A PHP version is specified.</li>
* <li>Check the order of the tags.</li>
* <li>Check the indentation of each tag.</li>
* <li>Check required and optional tags and the format of their content.</li>
* </ul>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
class PEAR_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* The header comment parser for the current file.
*
* @var PHP_CodeSniffer_Comment_Parser_ClassCommentParser
*/
protected $commentParser = null;
 
/**
* The current PHP_CodeSniffer_File object we are processing.
*
* @var PHP_CodeSniffer_File
*/
protected $currentFile = null;
 
/**
* Tags in correct order and related info.
*
* @var array
*/
protected $tags = array(
'category' => array(
'required' => true,
'allow_multiple' => false,
'order_text' => 'precedes @package',
),
'package' => array(
'required' => true,
'allow_multiple' => false,
'order_text' => 'follows @category',
),
'subpackage' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @package',
),
'author' => array(
'required' => true,
'allow_multiple' => true,
'order_text' => 'follows @subpackage (if used) or @package',
),
'copyright' => array(
'required' => false,
'allow_multiple' => true,
'order_text' => 'follows @author',
),
'license' => array(
'required' => true,
'allow_multiple' => false,
'order_text' => 'follows @copyright (if used) or @author',
),
'version' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @license',
),
'link' => array(
'required' => true,
'allow_multiple' => true,
'order_text' => 'follows @version',
),
'see' => array(
'required' => false,
'allow_multiple' => true,
'order_text' => 'follows @link',
),
'since' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @see (if used) or @link',
),
'deprecated' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @since (if used) or @see (if used) or @link',
),
);
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_OPEN_TAG);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$this->currentFile = $phpcsFile;
 
// We are only interested if this is the first open tag.
if ($stackPtr !== 0) {
if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
return;
}
}
 
$tokens = $phpcsFile->getTokens();
 
// Find the next non whitespace token.
$commentStart
= $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
 
// Allow declare() statements at the top of the file.
if ($tokens[$commentStart]['code'] === T_DECLARE) {
$semicolon = $phpcsFile->findNext(T_SEMICOLON, ($commentStart + 1));
$commentStart
= $phpcsFile->findNext(T_WHITESPACE, ($semicolon + 1), null, true);
}
 
// Ignore vim header.
if ($tokens[$commentStart]['code'] === T_COMMENT) {
if (strstr($tokens[$commentStart]['content'], 'vim:') !== false) {
$commentStart = $phpcsFile->findNext(
T_WHITESPACE,
($commentStart + 1),
null,
true
);
}
}
 
$errorToken = ($stackPtr + 1);
if (isset($tokens[$errorToken]) === false) {
$errorToken--;
}
 
if ($tokens[$commentStart]['code'] === T_CLOSE_TAG) {
// We are only interested if this is the first open tag.
return;
} else if ($tokens[$commentStart]['code'] === T_COMMENT) {
$error = 'You must use "/**" style comments for a file comment';
$phpcsFile->addError($error, $errorToken);
return;
} else if ($commentStart === false
|| $tokens[$commentStart]['code'] !== T_DOC_COMMENT
) {
$phpcsFile->addError('Missing file doc comment', $errorToken);
return;
} else {
 
// Extract the header comment docblock.
$commentEnd = $phpcsFile->findNext(
T_DOC_COMMENT,
($commentStart + 1),
null,
true
);
 
$commentEnd--;
 
// Check if there is only 1 doc comment between the
// open tag and class token.
$nextToken = array(
T_ABSTRACT,
T_CLASS,
T_FUNCTION,
T_DOC_COMMENT,
);
 
$commentNext = $phpcsFile->findNext($nextToken, ($commentEnd + 1));
if ($commentNext !== false
&& $tokens[$commentNext]['code'] !== T_DOC_COMMENT
) {
// Found a class token right after comment doc block.
$newlineToken = $phpcsFile->findNext(
T_WHITESPACE,
($commentEnd + 1),
$commentNext,
false,
$phpcsFile->eolChar
);
 
if ($newlineToken !== false) {
$newlineToken = $phpcsFile->findNext(
T_WHITESPACE,
($newlineToken + 1),
$commentNext,
false,
$phpcsFile->eolChar
);
 
if ($newlineToken === false) {
// No blank line between the class token and the doc block.
// The doc block is most likely a class comment.
$error = 'Missing file doc comment';
$phpcsFile->addError($error, $errorToken);
return;
}
}
}//end if
 
$comment = $phpcsFile->getTokensAsString(
$commentStart,
($commentEnd - $commentStart + 1)
);
 
// Parse the header comment docblock.
try {
$this->commentParser = new PHP_CodeSniffer_CommentParser_ClassCommentParser($comment, $phpcsFile);
$this->commentParser->parse();
} catch (PHP_CodeSniffer_CommentParser_ParserException $e) {
$line = ($e->getLineWithinComment() + $commentStart);
$phpcsFile->addError($e->getMessage(), $line);
return;
}
 
$comment = $this->commentParser->getComment();
if (is_null($comment) === true) {
$error = 'File doc comment is empty';
$phpcsFile->addError($error, $commentStart);
return;
}
 
// No extra newline before short description.
$short = $comment->getShortComment();
$newlineCount = 0;
$newlineSpan = strspn($short, $phpcsFile->eolChar);
if ($short !== '' && $newlineSpan > 0) {
$line = ($newlineSpan > 1) ? 'newlines' : 'newline';
$error = "Extra $line found before file comment short description";
$phpcsFile->addError($error, ($commentStart + 1));
}
 
$newlineCount = (substr_count($short, $phpcsFile->eolChar) + 1);
 
// Exactly one blank line between short and long description.
$long = $comment->getLongComment();
if (empty($long) === false) {
$between = $comment->getWhiteSpaceBetween();
$newlineBetween = substr_count($between, $phpcsFile->eolChar);
if ($newlineBetween !== 2) {
$error = 'There must be exactly one blank line between descriptions in file comment';
$phpcsFile->addError($error, ($commentStart + $newlineCount + 1));
}
 
$newlineCount += $newlineBetween;
}
 
// Exactly one blank line before tags.
$tags = $this->commentParser->getTagOrders();
if (count($tags) > 1) {
$newlineSpan = $comment->getNewlineAfter();
if ($newlineSpan !== 2) {
$error = 'There must be exactly one blank line before the tags in file comment';
if ($long !== '') {
$newlineCount += (substr_count($long, $phpcsFile->eolChar) - $newlineSpan + 1);
}
 
$phpcsFile->addError($error, ($commentStart + $newlineCount));
$short = rtrim($short, $phpcsFile->eolChar.' ');
}
}
 
// Check the PHP Version.
$this->processPHPVersion($commentStart, $commentEnd, $long);
 
// Check each tag.
$this->processTags($commentStart, $commentEnd);
}//end if
 
}//end process()
 
 
/**
* Check that the PHP version is specified.
*
* @param int $commentStart Position in the stack where the comment started.
* @param int $commentEnd Position in the stack where the comment ended.
* @param string $comment The text of the function comment.
*
* @return void
*/
protected function processPHPVersion($commentStart, $commentEnd, $commentText)
{
if (strstr(strtolower($commentText), 'php version') === false) {
$error = 'PHP version not specified';
$this->currentFile->addWarning($error, $commentEnd);
}
 
}//end processPHPVersion()
 
 
/**
* Processes each required or optional tag.
*
* @param int $commentStart Position in the stack where the comment started.
* @param int $commentEnd Position in the stack where the comment ended.
*
* @return void
*/
protected function processTags($commentStart, $commentEnd)
{
$docBlock = (get_class($this) === 'PEAR_Sniffs_Commenting_FileCommentSniff') ? 'file' : 'class';
$foundTags = $this->commentParser->getTagOrders();
$orderIndex = 0;
$indentation = array();
$longestTag = 0;
$errorPos = 0;
 
foreach ($this->tags as $tag => $info) {
 
// Required tag missing.
if ($info['required'] === true && in_array($tag, $foundTags) === false) {
$error = "Missing @$tag tag in $docBlock comment";
$this->currentFile->addError($error, $commentEnd);
continue;
}
 
// Get the line number for current tag.
$tagName = ucfirst($tag);
if ($info['allow_multiple'] === true) {
$tagName .= 's';
}
 
$getMethod = 'get'.$tagName;
$tagElement = $this->commentParser->$getMethod();
if (is_null($tagElement) === true || empty($tagElement) === true) {
continue;
}
 
$errorPos = $commentStart;
if (is_array($tagElement) === false) {
$errorPos = ($commentStart + $tagElement->getLine());
}
 
// Get the tag order.
$foundIndexes = array_keys($foundTags, $tag);
 
if (count($foundIndexes) > 1) {
// Multiple occurance not allowed.
if ($info['allow_multiple'] === false) {
$error = "Only 1 @$tag tag is allowed in a $docBlock comment";
$this->currentFile->addError($error, $errorPos);
} else {
// Make sure same tags are grouped together.
$i = 0;
$count = $foundIndexes[0];
foreach ($foundIndexes as $index) {
if ($index !== $count) {
$errorPosIndex
= ($errorPos + $tagElement[$i]->getLine());
$error = "@$tag tags must be grouped together";
$this->currentFile->addError($error, $errorPosIndex);
}
 
$i++;
$count++;
}
}
}//end if
 
// Check tag order.
if ($foundIndexes[0] > $orderIndex) {
$orderIndex = $foundIndexes[0];
} else {
if (is_array($tagElement) === true && empty($tagElement) === false) {
$errorPos += $tagElement[0]->getLine();
}
 
$orderText = $info['order_text'];
$error = "The @$tag tag is in the wrong order; the tag $orderText";
$this->currentFile->addError($error, $errorPos);
}
 
// Store the indentation for checking.
$len = strlen($tag);
if ($len > $longestTag) {
$longestTag = $len;
}
 
if (is_array($tagElement) === true) {
foreach ($tagElement as $key => $element) {
$indentation[] = array(
'tag' => $tag,
'space' => $this->getIndentation($tag, $element),
'line' => $element->getLine(),
);
}
} else {
$indentation[] = array(
'tag' => $tag,
'space' => $this->getIndentation($tag, $tagElement),
);
}
 
$method = 'process'.$tagName;
if (method_exists($this, $method) === true) {
// Process each tag if a method is defined.
call_user_func(array($this, $method), $errorPos);
} else {
if (is_array($tagElement) === true) {
foreach ($tagElement as $key => $element) {
$element->process(
$this->currentFile,
$commentStart,
$docBlock
);
}
} else {
$tagElement->process(
$this->currentFile,
$commentStart,
$docBlock
);
}
}
}//end foreach
 
foreach ($indentation as $indentInfo) {
if ($indentInfo['space'] !== 0
&& $indentInfo['space'] !== ($longestTag + 1)
) {
$expected = (($longestTag - strlen($indentInfo['tag'])) + 1);
$space = ($indentInfo['space'] - strlen($indentInfo['tag']));
$error = "@$indentInfo[tag] tag comment indented incorrectly. ";
$error .= "Expected $expected spaces but found $space.";
 
$getTagMethod = 'get'.ucfirst($indentInfo['tag']);
 
if ($this->tags[$indentInfo['tag']]['allow_multiple'] === true) {
$line = $indentInfo['line'];
} else {
$tagElem = $this->commentParser->$getTagMethod();
$line = $tagElem->getLine();
}
 
$this->currentFile->addError($error, ($commentStart + $line));
}
}
 
}//end processTags()
 
 
/**
* Get the indentation information of each tag.
*
* @param string $tagName The name of the
* doc comment
* element.
* @param PHP_CodeSniffer_CommentParser_DocElement $tagElement The doc comment
* element.
*
* @return void
*/
protected function getIndentation($tagName, $tagElement)
{
if ($tagElement instanceof PHP_CodeSniffer_CommentParser_SingleElement) {
if ($tagElement->getContent() !== '') {
return (strlen($tagName) + substr_count($tagElement->getWhitespaceBeforeContent(), ' '));
}
} else if ($tagElement instanceof PHP_CodeSniffer_CommentParser_PairElement) {
if ($tagElement->getValue() !== '') {
return (strlen($tagName) + substr_count($tagElement->getWhitespaceBeforeValue(), ' '));
}
}
 
return 0;
 
}//end getIndentation()
 
 
/**
* Process the category tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processCategory($errorPos)
{
$category = $this->commentParser->getCategory();
if ($category !== null) {
$content = $category->getContent();
if ($content !== '') {
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
$newContent = str_replace(' ', '_', $content);
$nameBits = explode('_', $newContent);
$firstBit = array_shift($nameBits);
$newName = ucfirst($firstBit).'_';
foreach ($nameBits as $bit) {
$newName .= ucfirst($bit).'_';
}
 
$validName = trim($newName, '_');
$error = "Category name \"$content\" is not valid; consider \"$validName\" instead";
$this->currentFile->addError($error, $errorPos);
}
} else {
$error = '@category tag must contain a name';
$this->currentFile->addError($error, $errorPos);
}
}
 
}//end processCategory()
 
 
/**
* Process the package tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processPackage($errorPos)
{
$package = $this->commentParser->getPackage();
if ($package !== null) {
$content = $package->getContent();
if ($content !== '') {
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
$newContent = str_replace(' ', '_', $content);
$nameBits = explode('_', $newContent);
$firstBit = array_shift($nameBits);
$newName = strtoupper($firstBit{0}).substr($firstBit, 1).'_';
foreach ($nameBits as $bit) {
$newName .= strtoupper($bit{0}).substr($bit, 1).'_';
}
 
$validName = trim($newName, '_');
$error = "Package name \"$content\" is not valid; consider \"$validName\" instead";
$this->currentFile->addError($error, $errorPos);
}
} else {
$error = '@package tag must contain a name';
$this->currentFile->addError($error, $errorPos);
}
}
 
}//end processPackage()
 
 
/**
* Process the subpackage tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processSubpackage($errorPos)
{
$package = $this->commentParser->getSubpackage();
if ($package !== null) {
$content = $package->getContent();
if ($content !== '') {
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
$newContent = str_replace(' ', '_', $content);
$nameBits = explode('_', $newContent);
$firstBit = array_shift($nameBits);
$newName = strtoupper($firstBit{0}).substr($firstBit, 1).'_';
foreach ($nameBits as $bit) {
$newName .= strtoupper($bit{0}).substr($bit, 1).'_';
}
 
$validName = trim($newName, '_');
$error = "Subpackage name \"$content\" is not valid; consider \"$validName\" instead";
$this->currentFile->addError($error, $errorPos);
}
} else {
$error = '@subpackage tag must contain a name';
$this->currentFile->addError($error, $errorPos);
}
}
 
}//end processSubpackage()
 
 
/**
* Process the author tag(s) that this header comment has.
*
* This function is different from other _process functions
* as $authors is an array of SingleElements, so we work out
* the errorPos for each element separately
*
* @param int $commentStart The position in the stack where
* the comment started.
*
* @return void
*/
protected function processAuthors($commentStart)
{
$authors = $this->commentParser->getAuthors();
// Report missing return.
if (empty($authors) === false) {
foreach ($authors as $author) {
$errorPos = ($commentStart + $author->getLine());
$content = $author->getContent();
if ($content !== '') {
$local = '\da-zA-Z-_+';
// Dot character cannot be the first or last character
// in the local-part.
$localMiddle = $local.'.\w';
if (preg_match('/^([^<]*)\s+<(['.$local.']['.$localMiddle.']*['.$local.']@[\da-zA-Z][-.\w]*[\da-zA-Z]\.[a-zA-Z]{2,7})>$/', $content) === 0) {
$error = 'Content of the @author tag must be in the form "Display Name <username@example.com>"';
$this->currentFile->addError($error, $errorPos);
}
} else {
$docBlock = (get_class($this) === 'PEAR_Sniffs_Commenting_FileCommentSniff') ? 'file' : 'class';
$error = "Content missing for @author tag in $docBlock comment";
$this->currentFile->addError($error, $errorPos);
}
}
}
 
}//end processAuthors()
 
 
/**
* Process the copyright tags.
*
* @param int $commentStart The position in the stack where
* the comment started.
*
* @return void
*/
protected function processCopyrights($commentStart)
{
$copyrights = $this->commentParser->getCopyrights();
foreach ($copyrights as $copyright) {
$errorPos = ($commentStart + $copyright->getLine());
$content = $copyright->getContent();
if ($content !== '') {
$matches = array();
if (preg_match('/^([0-9]{4})((.{1})([0-9]{4}))? (.+)$/', $content, $matches) !== 0) {
// Check earliest-latest year order.
if ($matches[3] !== '') {
if ($matches[3] !== '-') {
$error = 'A hyphen must be used between the earliest and latest year';
$this->currentFile->addError($error, $errorPos);
}
 
if ($matches[4] !== '' && $matches[4] < $matches[1]) {
$error = "Invalid year span \"$matches[1]$matches[3]$matches[4]\" found; consider \"$matches[4]-$matches[1]\" instead";
$this->currentFile->addWarning($error, $errorPos);
}
}
} else {
$error = '@copyright tag must contain a year and the name of the copyright holder';
$this->currentFile->addError($error, $errorPos);
}
} else {
$error = '@copyright tag must contain a year and the name of the copyright holder';
$this->currentFile->addError($error, $errorPos);
}//end if
}//end if
 
}//end processCopyrights()
 
 
/**
* Process the license tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processLicense($errorPos)
{
$license = $this->commentParser->getLicense();
if ($license !== null) {
$value = $license->getValue();
$comment = $license->getComment();
if ($value === '' || $comment === '') {
$error = '@license tag must contain a URL and a license name';
$this->currentFile->addError($error, $errorPos);
}
}
 
}//end processLicense()
 
 
/**
* Process the version tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processVersion($errorPos)
{
$version = $this->commentParser->getVersion();
if ($version !== null) {
$content = $version->getContent();
$matches = array();
if (empty($content) === true) {
$error = 'Content missing for @version tag in file comment';
$this->currentFile->addError($error, $errorPos);
} else if (strstr($content, 'CVS:') === false
&& strstr($content, 'SVN:') === false
) {
$error = "Invalid version \"$content\" in file comment; consider \"CVS: <cvs_id>\" or \"SVN: <svn_id>\" instead";
$this->currentFile->addWarning($error, $errorPos);
}
}
 
}//end processVersion()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Commenting/ClassCommentSniff.php
New file
0,0 → 1,233
<?php
/**
* Parses and verifies the doc comments for classes.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ClassCommentSniff.php,v 1.19 2008/12/02 02:38:34 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_CommentParser_ClassCommentParser', true) === false) {
$error = 'Class PHP_CodeSniffer_CommentParser_ClassCommentParser not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
if (class_exists('PEAR_Sniffs_Commenting_FileCommentSniff', true) === false) {
$error = 'Class PEAR_Sniffs_Commenting_FileCommentSniff not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* Parses and verifies the doc comments for classes.
*
* Verifies that :
* <ul>
* <li>A doc comment exists.</li>
* <li>There is a blank newline after the short description.</li>
* <li>There is a blank newline between the long and short description.</li>
* <li>There is a blank newline between the long description and tags.</li>
* <li>Check the order of the tags.</li>
* <li>Check the indentation of each tag.</li>
* <li>Check required and optional tags and the format of their content.</li>
* </ul>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_Commenting_ClassCommentSniff extends PEAR_Sniffs_Commenting_FileCommentSniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_CLASS,
T_INTERFACE,
);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$this->currentFile = $phpcsFile;
 
$tokens = $phpcsFile->getTokens();
$type = strtolower($tokens[$stackPtr]['content']);
$find = array(
T_ABSTRACT,
T_WHITESPACE,
T_FINAL,
);
 
// Extract the class comment docblock.
$commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true);
 
if ($commentEnd !== false && $tokens[$commentEnd]['code'] === T_COMMENT) {
$error = "You must use \"/**\" style comments for a $type comment";
$phpcsFile->addError($error, $stackPtr);
return;
} else if ($commentEnd === false
|| $tokens[$commentEnd]['code'] !== T_DOC_COMMENT
) {
$phpcsFile->addError("Missing $type doc comment", $stackPtr);
return;
}
 
$commentStart = ($phpcsFile->findPrevious(T_DOC_COMMENT, ($commentEnd - 1), null, true) + 1);
$commentNext = $phpcsFile->findPrevious(T_WHITESPACE, ($commentEnd + 1), $stackPtr, false, $phpcsFile->eolChar);
 
// Distinguish file and class comment.
$prevClassToken = $phpcsFile->findPrevious(T_CLASS, ($stackPtr - 1));
if ($prevClassToken === false) {
// This is the first class token in this file, need extra checks.
$prevNonComment = $phpcsFile->findPrevious(T_DOC_COMMENT, ($commentStart - 1), null, true);
if ($prevNonComment !== false) {
$prevComment = $phpcsFile->findPrevious(T_DOC_COMMENT, ($prevNonComment - 1));
if ($prevComment === false) {
// There is only 1 doc comment between open tag and class token.
$newlineToken = $phpcsFile->findNext(T_WHITESPACE, ($commentEnd + 1), $stackPtr, false, $phpcsFile->eolChar);
if ($newlineToken !== false) {
$newlineToken = $phpcsFile->findNext(
T_WHITESPACE,
($newlineToken + 1),
$stackPtr,
false,
$phpcsFile->eolChar
);
 
if ($newlineToken !== false) {
// Blank line between the class and the doc block.
// The doc block is most likely a file comment.
$error = "Missing $type doc comment";
$phpcsFile->addError($error, ($stackPtr + 1));
return;
}
}//end if
}//end if
}//end if
}//end if
 
$comment = $phpcsFile->getTokensAsString(
$commentStart,
($commentEnd - $commentStart + 1)
);
 
// Parse the class comment.docblock.
try {
$this->commentParser = new PHP_CodeSniffer_CommentParser_ClassCommentParser($comment, $phpcsFile);
$this->commentParser->parse();
} catch (PHP_CodeSniffer_CommentParser_ParserException $e) {
$line = ($e->getLineWithinComment() + $commentStart);
$phpcsFile->addError($e->getMessage(), $line);
return;
}
 
$comment = $this->commentParser->getComment();
if (is_null($comment) === true) {
$error = ucfirst($type).' doc comment is empty';
$phpcsFile->addError($error, $commentStart);
return;
}
 
// No extra newline before short description.
$short = $comment->getShortComment();
$newlineCount = 0;
$newlineSpan = strspn($short, $phpcsFile->eolChar);
if ($short !== '' && $newlineSpan > 0) {
$line = ($newlineSpan > 1) ? 'newlines' : 'newline';
$error = "Extra $line found before $type comment short description";
$phpcsFile->addError($error, ($commentStart + 1));
}
 
$newlineCount = (substr_count($short, $phpcsFile->eolChar) + 1);
 
// Exactly one blank line between short and long description.
$long = $comment->getLongComment();
if (empty($long) === false) {
$between = $comment->getWhiteSpaceBetween();
$newlineBetween = substr_count($between, $phpcsFile->eolChar);
if ($newlineBetween !== 2) {
$error = "There must be exactly one blank line between descriptions in $type comments";
$phpcsFile->addError($error, ($commentStart + $newlineCount + 1));
}
 
$newlineCount += $newlineBetween;
}
 
// Exactly one blank line before tags.
$tags = $this->commentParser->getTagOrders();
if (count($tags) > 1) {
$newlineSpan = $comment->getNewlineAfter();
if ($newlineSpan !== 2) {
$error = "There must be exactly one blank line before the tags in $type comments";
if ($long !== '') {
$newlineCount += (substr_count($long, $phpcsFile->eolChar) - $newlineSpan + 1);
}
 
$phpcsFile->addError($error, ($commentStart + $newlineCount));
$short = rtrim($short, $phpcsFile->eolChar.' ');
}
}
 
// Check each tag.
$this->processTags($commentStart, $commentEnd);
 
}//end process()
 
 
/**
* Process the version tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processVersion($errorPos)
{
$version = $this->commentParser->getVersion();
if ($version !== null) {
$content = $version->getContent();
$matches = array();
if (empty($content) === true) {
$error = 'Content missing for @version tag in doc comment';
$this->currentFile->addError($error, $errorPos);
} else if ((strstr($content, 'Release:') === false)) {
$error = "Invalid version \"$content\" in doc comment; consider \"Release: <package_version>\" instead";
$this->currentFile->addWarning($error, $errorPos);
}
}
 
}//end processVersion()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php
New file
0,0 → 1,463
<?php
/**
* Parses and verifies the doc comments for functions.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: FunctionCommentSniff.php,v 1.25 2008/12/17 22:36:41 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_CommentParser_FunctionCommentParser', true) === false) {
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_CommentParser_FunctionCommentParser not found');
}
 
/**
* Parses and verifies the doc comments for functions.
*
* Verifies that :
* <ul>
* <li>A comment exists</li>
* <li>There is a blank newline after the short description.</li>
* <li>There is a blank newline between the long and short description.</li>
* <li>There is a blank newline between the long description and tags.</li>
* <li>Parameter names represent those in the method.</li>
* <li>Parameter comments are in the correct order</li>
* <li>Parameter comments are complete</li>
* <li>A space is present before the first and after the last parameter</li>
* <li>A return type exists</li>
* <li>There must be one blank line between body and headline comments.</li>
* <li>Any throw tag must have an exception class.</li>
* </ul>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* The name of the method that we are currently processing.
*
* @var string
*/
private $_methodName = '';
 
/**
* The position in the stack where the fucntion token was found.
*
* @var int
*/
private $_functionToken = null;
 
/**
* The position in the stack where the class token was found.
*
* @var int
*/
private $_classToken = null;
 
/**
* The function comment parser for the current method.
*
* @var PHP_CodeSniffer_Comment_Parser_FunctionCommentParser
*/
protected $commentParser = null;
 
/**
* The current PHP_CodeSniffer_File object we are processing.
*
* @var PHP_CodeSniffer_File
*/
protected $currentFile = null;
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_FUNCTION);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$find = array(
T_COMMENT,
T_DOC_COMMENT,
T_CLASS,
T_FUNCTION,
T_OPEN_TAG,
);
 
$commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1));
 
if ($commentEnd === false) {
return;
}
 
$this->currentFile = $phpcsFile;
$tokens = $phpcsFile->getTokens();
 
// If the token that we found was a class or a function, then this
// function has no doc comment.
$code = $tokens[$commentEnd]['code'];
 
if ($code === T_COMMENT) {
$error = 'You must use "/**" style comments for a function comment';
$phpcsFile->addError($error, $stackPtr);
return;
} else if ($code !== T_DOC_COMMENT) {
$phpcsFile->addError('Missing function doc comment', $stackPtr);
return;
}
 
// If there is any code between the function keyword and the doc block
// then the doc block is not for us.
$ignore = PHP_CodeSniffer_Tokens::$scopeModifiers;
$ignore[] = T_STATIC;
$ignore[] = T_WHITESPACE;
$ignore[] = T_ABSTRACT;
$ignore[] = T_FINAL;
$prevToken = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true);
if ($prevToken !== $commentEnd) {
$phpcsFile->addError('Missing function doc comment', $stackPtr);
return;
}
 
$this->_functionToken = $stackPtr;
 
$this->_classToken = null;
foreach ($tokens[$stackPtr]['conditions'] as $condPtr => $condition) {
if ($condition === T_CLASS || $condition === T_INTERFACE) {
$this->_classToken = $condPtr;
break;
}
}
 
// If the first T_OPEN_TAG is right before the comment, it is probably
// a file comment.
$commentStart = ($phpcsFile->findPrevious(T_DOC_COMMENT, ($commentEnd - 1), null, true) + 1);
$prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($commentStart - 1), null, true);
if ($tokens[$prevToken]['code'] === T_OPEN_TAG) {
// Is this the first open tag?
if ($stackPtr === 0 || $phpcsFile->findPrevious(T_OPEN_TAG, ($prevToken - 1)) === false) {
$phpcsFile->addError('Missing function doc comment', $stackPtr);
return;
}
}
 
$comment = $phpcsFile->getTokensAsString($commentStart, ($commentEnd - $commentStart + 1));
$this->_methodName = $phpcsFile->getDeclarationName($stackPtr);
 
try {
$this->commentParser = new PHP_CodeSniffer_CommentParser_FunctionCommentParser($comment, $phpcsFile);
$this->commentParser->parse();
} catch (PHP_CodeSniffer_CommentParser_ParserException $e) {
$line = ($e->getLineWithinComment() + $commentStart);
$phpcsFile->addError($e->getMessage(), $line);
return;
}
 
$comment = $this->commentParser->getComment();
if (is_null($comment) === true) {
$error = 'Function doc comment is empty';
$phpcsFile->addError($error, $commentStart);
return;
}
 
$this->processParams($commentStart);
$this->processReturn($commentStart, $commentEnd);
$this->processThrows($commentStart);
 
// No extra newline before short description.
$short = $comment->getShortComment();
$newlineCount = 0;
$newlineSpan = strspn($short, $phpcsFile->eolChar);
if ($short !== '' && $newlineSpan > 0) {
$line = ($newlineSpan > 1) ? 'newlines' : 'newline';
$error = "Extra $line found before function comment short description";
$phpcsFile->addError($error, ($commentStart + 1));
}
 
$newlineCount = (substr_count($short, $phpcsFile->eolChar) + 1);
 
// Exactly one blank line between short and long description.
$long = $comment->getLongComment();
if (empty($long) === false) {
$between = $comment->getWhiteSpaceBetween();
$newlineBetween = substr_count($between, $phpcsFile->eolChar);
if ($newlineBetween !== 2) {
$error = 'There must be exactly one blank line between descriptions in function comment';
$phpcsFile->addError($error, ($commentStart + $newlineCount + 1));
}
 
$newlineCount += $newlineBetween;
}
 
// Exactly one blank line before tags.
$params = $this->commentParser->getTagOrders();
if (count($params) > 1) {
$newlineSpan = $comment->getNewlineAfter();
if ($newlineSpan !== 2) {
$error = 'There must be exactly one blank line before the tags in function comment';
if ($long !== '') {
$newlineCount += (substr_count($long, $phpcsFile->eolChar) - $newlineSpan + 1);
}
 
$phpcsFile->addError($error, ($commentStart + $newlineCount));
$short = rtrim($short, $phpcsFile->eolChar.' ');
}
}
 
}//end process()
 
 
/**
* Process any throw tags that this function comment has.
*
* @param int $commentStart The position in the stack where the
* comment started.
*
* @return void
*/
protected function processThrows($commentStart)
{
if (count($this->commentParser->getThrows()) === 0) {
return;
}
 
foreach ($this->commentParser->getThrows() as $throw) {
 
$exception = $throw->getValue();
$errorPos = ($commentStart + $throw->getLine());
 
if ($exception === '') {
$error = '@throws tag must contain the exception class name';
$this->currentFile->addError($error, $errorPos);
}
}
 
}//end processThrows()
 
 
/**
* Process the return comment of this function comment.
*
* @param int $commentStart The position in the stack where the comment started.
* @param int $commentEnd The position in the stack where the comment ended.
*
* @return void
*/
protected function processReturn($commentStart, $commentEnd)
{
// Skip constructor and destructor.
$className = '';
if ($this->_classToken !== null) {
$className = $this->currentFile->getDeclarationName($this->_classToken);
$className = strtolower(ltrim($className, '_'));
}
 
$methodName = strtolower(ltrim($this->_methodName, '_'));
$isSpecialMethod = ($this->_methodName === '__construct' || $this->_methodName === '__destruct');
 
if ($isSpecialMethod === false && $methodName !== $className) {
// Report missing return tag.
if ($this->commentParser->getReturn() === null) {
$error = 'Missing @return tag in function comment';
$this->currentFile->addError($error, $commentEnd);
} else if (trim($this->commentParser->getReturn()->getRawContent()) === '') {
$error = '@return tag is empty in function comment';
$errorPos = ($commentStart + $this->commentParser->getReturn()->getLine());
$this->currentFile->addError($error, $errorPos);
}
}
 
}//end processReturn()
 
 
/**
* Process the function parameter comments.
*
* @param int $commentStart The position in the stack where
* the comment started.
*
* @return void
*/
protected function processParams($commentStart)
{
$realParams = $this->currentFile->getMethodParameters($this->_functionToken);
 
$params = $this->commentParser->getParams();
$foundParams = array();
 
if (empty($params) === false) {
 
$lastParm = (count($params) - 1);
if (substr_count($params[$lastParm]->getWhitespaceAfter(), $this->currentFile->eolChar) !== 2) {
$error = 'Last parameter comment requires a blank newline after it';
$errorPos = ($params[$lastParm]->getLine() + $commentStart);
$this->currentFile->addError($error, $errorPos);
}
 
// Parameters must appear immediately after the comment.
if ($params[0]->getOrder() !== 2) {
$error = 'Parameters must appear immediately after the comment';
$errorPos = ($params[0]->getLine() + $commentStart);
$this->currentFile->addError($error, $errorPos);
}
 
$previousParam = null;
$spaceBeforeVar = 10000;
$spaceBeforeComment = 10000;
$longestType = 0;
$longestVar = 0;
 
foreach ($params as $param) {
 
$paramComment = trim($param->getComment());
$errorPos = ($param->getLine() + $commentStart);
 
// Make sure that there is only one space before the var type.
if ($param->getWhitespaceBeforeType() !== ' ') {
$error = 'Expected 1 space before variable type';
$this->currentFile->addError($error, $errorPos);
}
 
$spaceCount = substr_count($param->getWhitespaceBeforeVarName(), ' ');
if ($spaceCount < $spaceBeforeVar) {
$spaceBeforeVar = $spaceCount;
$longestType = $errorPos;
}
 
$spaceCount = substr_count($param->getWhitespaceBeforeComment(), ' ');
 
if ($spaceCount < $spaceBeforeComment && $paramComment !== '') {
$spaceBeforeComment = $spaceCount;
$longestVar = $errorPos;
}
 
// Make sure they are in the correct order,
// and have the correct name.
$pos = $param->getPosition();
 
$paramName = ($param->getVarName() !== '') ? $param->getVarName() : '[ UNKNOWN ]';
 
if ($previousParam !== null) {
$previousName = ($previousParam->getVarName() !== '') ? $previousParam->getVarName() : 'UNKNOWN';
 
// Check to see if the parameters align properly.
if ($param->alignsVariableWith($previousParam) === false) {
$error = 'The variable names for parameters '.$previousName.' ('.($pos - 1).') and '.$paramName.' ('.$pos.') do not align';
$this->currentFile->addError($error, $errorPos);
}
 
if ($param->alignsCommentWith($previousParam) === false) {
$error = 'The comments for parameters '.$previousName.' ('.($pos - 1).') and '.$paramName.' ('.$pos.') do not align';
$this->currentFile->addError($error, $errorPos);
}
}//end if
 
// Make sure the names of the parameter comment matches the
// actual parameter.
if (isset($realParams[($pos - 1)]) === true) {
$realName = $realParams[($pos - 1)]['name'];
$foundParams[] = $realName;
// Append ampersand to name if passing by reference.
if ($realParams[($pos - 1)]['pass_by_reference'] === true) {
$realName = '&'.$realName;
}
 
if ($realName !== $param->getVarName()) {
$error = 'Doc comment var "'.$paramName;
$error .= '" does not match actual variable name "'.$realName;
$error .= '" at position '.$pos;
 
$this->currentFile->addError($error, $errorPos);
}
} else {
// We must have an extra parameter comment.
$error = 'Superfluous doc comment at position '.$pos;
$this->currentFile->addError($error, $errorPos);
}
 
if ($param->getVarName() === '') {
$error = 'Missing parameter name at position '.$pos;
$this->currentFile->addError($error, $errorPos);
}
 
if ($param->getType() === '') {
$error = 'Missing type at position '.$pos;
$this->currentFile->addError($error, $errorPos);
}
 
if ($paramComment === '') {
$error = 'Missing comment for param "'.$paramName.'" at position '.$pos;
$this->currentFile->addError($error, $errorPos);
}
 
$previousParam = $param;
 
}//end foreach
 
if ($spaceBeforeVar !== 1 && $spaceBeforeVar !== 10000 && $spaceBeforeComment !== 10000) {
$error = 'Expected 1 space after the longest type';
$this->currentFile->addError($error, $longestType);
}
 
if ($spaceBeforeComment !== 1 && $spaceBeforeComment !== 10000) {
$error = 'Expected 1 space after the longest variable name';
$this->currentFile->addError($error, $longestVar);
}
 
}//end if
 
$realNames = array();
foreach ($realParams as $realParam) {
$realNames[] = $realParam['name'];
}
 
// Report and missing comments.
$diff = array_diff($realNames, $foundParams);
foreach ($diff as $neededParam) {
if (count($params) !== 0) {
$errorPos = ($params[(count($params) - 1)]->getLine() + $commentStart);
} else {
$errorPos = $commentStart;
}
 
$error = 'Doc comment for "'.$neededParam.'" missing';
$this->currentFile->addError($error, $errorPos);
}
 
}//end processParams()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Commenting/InlineCommentSniff.php
New file
0,0 → 1,71
<?php
/**
* PHP_CodeSniffer_Sniffs_PEAR_Commenting_InlineCommentSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: InlineCommentSniff.php,v 1.5 2008/12/02 02:38:34 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PHP_CodeSniffer_Sniffs_PEAR_Commenting_InlineCommentSniff.
*
* Checks that no perl-style comments are used.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_Commenting_InlineCommentSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_COMMENT);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
if ($tokens[$stackPtr]['content']{0} === '#') {
$error = 'Perl-style comments are not allowed. Use "// Comment."';
$error .= ' or "/* comment */" instead.';
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Files/LineLengthSniff.php
New file
0,0 → 1,57
<?php
/**
* PEAR_Sniffs_Files_LineLengthSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: LineLengthSniff.php,v 1.6 2007/07/27 05:36:23 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('Generic_Sniffs_Files_LineLengthSniff', true) === false) {
throw new PHP_CodeSniffer_Exception('Class Generic_Sniffs_Files_LineLengthSniff not found');
}
 
/**
* PEAR_Sniffs_Files_LineLengthSniff.
*
* Checks all lines in the file, and throws warnings if they are over 85
* characters in length.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_Files_LineLengthSniff extends Generic_Sniffs_Files_LineLengthSniff
{
 
/**
* The limit that the length of a line should not exceed.
*
* @var int
*/
protected $lineLimit = 85;
 
/**
* The limit that the length of a line must not exceed.
*
* Set to zero (0) to disable.
*
* @var int
*/
protected $absoluteLineLimit = 0;
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Files/IncludingFileSniff.php
New file
0,0 → 1,138
<?php
/**
* PEAR_Sniffs_Files_IncludingFileSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: IncludingFileSniff.php,v 1.5 2007/10/22 23:11:56 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_Files_IncludingFileSniff.
*
* Checks that the include_once is used in conditional situations, and
* require_once is used elsewhere. Also checks that brackets do not surround
* the file being included.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_Files_IncludingFileSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* Conditions that should use include_once
*
* @var array(int)
*/
private static $_conditions = array(
T_IF,
T_ELSE,
T_ELSEIF,
T_SWITCH,
);
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_INCLUDE_ONCE,
T_REQUIRE_ONCE,
T_REQUIRE,
T_INCLUDE,
);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
$nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
if ($tokens[$nextToken]['code'] === T_OPEN_PARENTHESIS) {
$error = '"'.$tokens[$stackPtr]['content'].'"';
$error .= ' is a statement, not a function; ';
$error .= 'no parentheses are required';
$phpcsFile->addError($error, $stackPtr);
}
 
$inCondition = (count($tokens[$stackPtr]['conditions']) !== 0) ? true : false;
 
// Check to see if this including statement is within the parenthesis of a condition.
// If that's the case then we need to process it as being within a condition, as they
// are checking the return value.
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
foreach ($tokens[$stackPtr]['nested_parenthesis'] as $left => $right) {
if (isset($tokens[$left]['parenthesis_owner']) === true) {
$inCondition = true;
}
}
}
 
// Check to see if they are assigning the return value of this including call.
// If they are then they are probably checking it, so its conditional.
$previous = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
if (in_array($tokens[$previous]['code'], PHP_CodeSniffer_Tokens::$assignmentTokens) === true) {
// The have assigned the return value to it, so its conditional.
$inCondition = true;
}
 
$tokenCode = $tokens[$stackPtr]['code'];
if ($inCondition === true) {
// We are inside a conditional statement. We need an include_once.
if ($tokenCode === T_REQUIRE_ONCE) {
$error = 'File is being conditionally included; ';
$error .= 'use "include_once" instead';
$phpcsFile->addError($error, $stackPtr);
} else if ($tokenCode === T_REQUIRE) {
$error = 'File is being conditionally included; ';
$error .= 'use "include" instead';
$phpcsFile->addError($error, $stackPtr);
}
} else {
// We are unconditionally including, we need a require_once.
if ($tokenCode === T_INCLUDE_ONCE) {
$error = 'File is being unconditionally included; ';
$error .= 'use "require_once" instead';
$phpcsFile->addError($error, $stackPtr);
} else if ($tokenCode === T_INCLUDE) {
$error = 'File is being unconditionally included; ';
$error .= 'use "require" instead';
$phpcsFile->addError($error, $stackPtr);
}
}//end if
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Files/LineEndingsSniff.php
New file
0,0 → 1,47
<?php
/**
* PEAR_Sniffs_Files_LineEndingsSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: LineEndingsSniff.php,v 1.3 2007/07/27 05:36:23 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('Generic_Sniffs_Files_LineEndingsSniff', true) === false) {
throw new PHP_CodeSniffer_Exception('Class Generic_Sniffs_Files_LineEndingsSniff not found');
}
 
/**
* PEAR_Sniffs_Files_LineEndingsSniff.
*
* Checks that end of line characters are "\n".
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_Files_LineEndingsSniff extends Generic_Sniffs_Files_LineEndingsSniff
{
 
/**
* The valid EOL character.
*
* @var string
*/
protected $eolChar = "\n";
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/MultiLineConditionSniff.php
New file
0,0 → 1,144
<?php
/**
* PEAR_Sniffs_ControlStructures_MultiLineConditionSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: MultiLineConditionSniff.php,v 1.2 2008/12/07 22:25:02 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_ControlStructures_MultiLineConditionSniff.
*
* Ensure multi-line IF conditions are defined correctly.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_ControlStructures_MultiLineConditionSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_IF);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
// We need to work out how far indented the if statement
// itself is, so we can work out how far to indent conditions.
$statementIndent = 0;
for ($i = ($stackPtr - 1); $i >= 0; $i--) {
if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
$i++;
break;
}
}
 
if ($tokens[$i]['code'] === T_WHITESPACE) {
$statementIndent = strlen($tokens[$i]['content']);
}
 
// Each line between the parenthesis should be indented 4 spaces
// and start with an operator.
$openBracket = $tokens[$stackPtr]['parenthesis_opener'];
$closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
$lastLine = $tokens[$openBracket]['line'];
for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
if ($tokens[$i]['line'] !== $lastLine) {
if ($tokens[$i]['line'] === $tokens[$closeBracket]['line']) {
$next = $phpcsFile->findNext(T_WHITESPACE, $i, null, true);
if ($next !== $closeBracket) {
// CLosing bracket is on the same line as a condition.
$error = 'Closing parenthesis of a multi-line IF statement must be on a new line';
$phpcsFile->addError($error, $i);
$expectedIndent = ($statementIndent + 4);
} else {
// Closing brace needs to be indented to the same level
// as the function.
$expectedIndent = $statementIndent;
}
} else {
$expectedIndent = ($statementIndent + 4);
}
 
// We changed lines, so this should be a whitespace indent token.
if ($tokens[$i]['code'] !== T_WHITESPACE) {
$foundIndent = 0;
} else {
$foundIndent = strlen($tokens[$i]['content']);
}
 
if ($expectedIndent !== $foundIndent) {
$error = "Multi-line IF statement not indented correctly; expected $expectedIndent spaces but found $foundIndent";
$phpcsFile->addError($error, $i);
}
 
if ($tokens[$i]['line'] !== $tokens[$closeBracket]['line']) {
$next = $phpcsFile->findNext(T_WHITESPACE, $i, null, true);
if (in_array($tokens[$next]['code'], PHP_CodeSniffer_Tokens::$booleanOperators) === false) {
$error = 'Each line in a multi-line IF statement must begin with a boolean operator';
$phpcsFile->addError($error, $i);
}
}
 
$lastLine = $tokens[$i]['line'];
}//end if
}//end for
 
// The openning brace needs to be one space away
// from the closing parenthesis.
if ($tokens[($closeBracket + 1)]['code'] !== T_WHITESPACE) {
$length = 0;
} else {
$length = strlen($tokens[($closeBracket + 1)]['content']);
}
 
if ($length !== 1) {
$error = "There must be a single space between the closing parenthesis and the openning brace of a multi-line IF statement; found $length spaces";
$phpcsFile->addError($error, ($closeBracket + 1));
}
 
// And just in case they do something funny before the brace...
$next = $phpcsFile->findNext(T_WHITESPACE, ($closeBracket + 1), null, true);
if ($next !== false && $tokens[$next]['code'] !== T_OPEN_CURLY_BRACKET) {
$error = 'There must be a single space between the closing parenthesis and the openning brace of a multi-line IF statement';
$phpcsFile->addError($error, $next);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/InlineControlStructureSniff.php
New file
0,0 → 1,48
<?php
/**
* PEAR_Sniffs_ControlStructures_InlineControlStructureSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: InlineControlStructureSniff.php,v 1.1 2008/05/01 00:49:32 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('Generic_Sniffs_ControlStructures_InlineControlStructureSniff', true) === false) {
$error = 'Class Generic_Sniffs_ControlStructures_InlineControlStructureSniff not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* PEAR_Sniffs_ControlStructures_InlineControlStructureSniff.
*
* Verifies that inline control statements are not present.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_ControlStructures_InlineControlStructureSniff extends Generic_Sniffs_ControlStructures_InlineControlStructureSniff
{
 
/**
* If true, an error will be thrown; otherwise a warning.
*
* @var bool
*/
protected $error = false;
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/ControlSignatureSniff.php
New file
0,0 → 1,71
<?php
/**
* Verifies that control statements conform to their coding standards.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ControlSignatureSniff.php,v 1.7 2007/10/23 06:05:14 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_Standards_AbstractPatternSniff', true) === false) {
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractPatternSniff not found');
}
 
/**
* Verifies that control statements conform to their coding standards.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_ControlStructures_ControlSignatureSniff extends PHP_CodeSniffer_Standards_AbstractPatternSniff
{
 
 
/**
* Constructs a PEAR_Sniffs_ControlStructures_ControlSignatureSniff.
*/
public function __construct()
{
parent::__construct(true);
 
}//end __construct()
 
 
/**
* Returns the patterns that this test wishes to verify.
*
* @return array(string)
*/
protected function getPatterns()
{
return array(
'do {EOL...} while (...);EOL',
'while (...) {EOL',
'for (...) {EOL',
'if (...) {EOL',
'foreach (...) {EOL',
'} else if (...) {EOL',
'} elseif (...) {EOL',
'} else {EOL',
'do {EOL',
);
 
}//end getPatterns()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Functions/ValidDefaultValueSniff.php
New file
0,0 → 1,110
<?php
/**
* PEAR_Sniffs_Functions_ValidDefaultValueSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ValidDefaultValueSniff.php,v 1.5 2007/07/23 01:47:53 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_Functions_ValidDefaultValueSniff.
*
* A Sniff to ensure that parameters defined for a function that have a default
* value come at the end of the function signature.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_Functions_ValidDefaultValueSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_FUNCTION);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
$argStart = $tokens[$stackPtr]['parenthesis_opener'];
$argEnd = $tokens[$stackPtr]['parenthesis_closer'];
 
// Flag for when we have found a default in our arg list.
// If there is a value without a default after this, it is an error.
$defaultFound = false;
 
$nextArg = $argStart;
while (($nextArg = $phpcsFile->findNext(T_VARIABLE, ($nextArg + 1), $argEnd)) !== false) {
$argHasDefault = self::_argHasDefault($phpcsFile, $nextArg);
if (($argHasDefault === false) && ($defaultFound === true)) {
$error = 'Arguments with default values must be at the end';
$error .= ' of the argument list';
$phpcsFile->addError($error, $nextArg);
return;
}
 
if ($argHasDefault === true) {
$defaultFound = true;
}
}
 
}//end process()
 
 
/**
* Returns true if the passed argument has a default value.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $argPtr The position of the argument
* in the stack.
*
* @return bool
*/
private static function _argHasDefault(PHP_CodeSniffer_File $phpcsFile, $argPtr)
{
$tokens = $phpcsFile->getTokens();
$nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($argPtr + 1), null, true);
if ($tokens[$nextToken]['code'] !== T_EQUAL) {
return false;
}
 
return true;
 
}//end _argHasDefault()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php
New file
0,0 → 1,243
<?php
/**
* PEAR_Sniffs_Functions_FunctionCallSignatureSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: FunctionCallSignatureSniff.php,v 1.7 2008/12/05 02:45:08 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_Functions_FunctionCallSignatureSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_Functions_FunctionCallSignatureSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_STRING);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
// Find the next non-empty token.
$openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
 
if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
// Not a function call.
return;
}
 
if (isset($tokens[$openBracket]['parenthesis_closer']) === false) {
// Not a function call.
return;
}
 
// Find the previous non-empty token.
$previous = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
if ($tokens[$previous]['code'] === T_FUNCTION) {
// It's a function definition, not a function call.
return;
}
 
if ($tokens[$previous]['code'] === T_NEW) {
// We are creating an object, not calling a function.
return;
}
 
$closeBracket = $tokens[$openBracket]['parenthesis_closer'];
 
if (($stackPtr + 1) !== $openBracket) {
// Checking this: $value = my_function[*](...).
$error = 'Space before opening parenthesis of function call prohibited';
$phpcsFile->addError($error, $stackPtr);
}
 
$next = $phpcsFile->findNext(T_WHITESPACE, ($closeBracket + 1), null, true);
if ($tokens[$next]['code'] === T_SEMICOLON) {
if (in_array($tokens[($closeBracket + 1)]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === true) {
$error = 'Space after closing parenthesis of function call prohibited';
$phpcsFile->addError($error, $closeBracket);
}
}
 
// Check if this is a single line or multi-line function call.
if ($tokens[$openBracket]['line'] === $tokens[$closeBracket]['line']) {
$this->processSingleLineCall($phpcsFile, $stackPtr, $openBracket, $tokens);
} else {
$this->processMultiLineCall($phpcsFile, $stackPtr, $openBracket, $tokens);
}
 
}//end process()
 
 
/**
* Processes single-line calls.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
* @param int $openBracket The position of the openning bracket
* in the stack passed in $tokens.
* @param array $tokens The stack of tokens that make up
* the file.
*
* @return void
*/
public function processSingleLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens)
{
if ($tokens[($openBracket + 1)]['code'] === T_WHITESPACE) {
// Checking this: $value = my_function([*]...).
$error = 'Space after opening parenthesis of function call prohibited';
$phpcsFile->addError($error, $stackPtr);
}
 
$closer = $tokens[$openBracket]['parenthesis_closer'];
 
if ($tokens[($closer - 1)]['code'] === T_WHITESPACE) {
// Checking this: $value = my_function(...[*]).
$between = $phpcsFile->findNext(T_WHITESPACE, ($openBracket + 1), null, true);
 
// Only throw an error if there is some content between the parenthesis.
// i.e., Checking for this: $value = my_function().
// If there is no content, then we would have thrown an error in the
// previous IF statement because it would look like this:
// $value = my_function( ).
if ($between !== $closer) {
$error = 'Space before closing parenthesis of function call prohibited';
$phpcsFile->addError($error, $closer);
}
}
 
}//end processSingleLineCall()
 
 
/**
* Processes multi-line calls.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
* @param int $openBracket The position of the openning bracket
* in the stack passed in $tokens.
* @param array $tokens The stack of tokens that make up
* the file.
*
* @return void
*/
public function processMultiLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens)
{
// We need to work out how far indented the function
// call itself is, so we can work out how far to
// indent the arguments.
$functionIndent = 0;
for ($i = ($stackPtr - 1); $i >= 0; $i--) {
if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
$i++;
break;
}
}
 
if ($tokens[$i]['code'] === T_WHITESPACE) {
$functionIndent = strlen($tokens[$i]['content']);
}
 
// Each line between the parenthesis should be indented 4 spaces.
$closeBracket = $tokens[$openBracket]['parenthesis_closer'];
$lastLine = $tokens[$openBracket]['line'];
for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
// Skip nested function calls.
if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS) {
$i = $tokens[$i]['parenthesis_closer'];
$lastLine = $tokens[$i]['line'];
continue;
}
 
if ($tokens[$i]['line'] !== $lastLine) {
$lastLine = $tokens[$i]['line'];
 
// We changed lines, so this should be a whitespace indent token.
if (in_array($tokens[$i]['code'], PHP_CodeSniffer_Tokens::$heredocTokens) === true) {
// Ignore heredoc indentation.
continue;
}
 
if (in_array($tokens[$i]['code'], PHP_CodeSniffer_Tokens::$stringTokens) === true) {
if ($tokens[$i]['code'] === $tokens[($i - 1)]['code']) {
// Ignore multi-line string indentation.
continue;
}
}
 
if ($tokens[$i]['line'] === $tokens[$closeBracket]['line']) {
// Closing brace needs to be indented to the same level
// as the function call.
$expectedIndent = $functionIndent;
} else {
$expectedIndent = ($functionIndent + 4);
}
 
if ($tokens[$i]['code'] !== T_WHITESPACE) {
$foundIndent = 0;
} else {
$foundIndent = strlen($tokens[$i]['content']);
}
 
if ($expectedIndent !== $foundIndent) {
$error = "Multi-line function call not indented correctly; expected $expectedIndent spaces but found $foundIndent";
$phpcsFile->addError($error, $i);
}
}//end if
}//end for
 
if ($tokens[($openBracket + 1)]['content'] !== $phpcsFile->eolChar) {
$error = 'Opening parenthesis of a multi-line function call must be the last content on the line';
$phpcsFile->addError($error, $stackPtr);
}
 
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($closeBracket - 1), null, true);
if ($tokens[$prev]['line'] === $tokens[$closeBracket]['line']) {
$error = 'Closing parenthesis of a multi-line function call must be on a line by itself';
$phpcsFile->addError($error, $closeBracket);
}
 
}//end processMultiLineCall()
 
 
}//end class
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php
New file
0,0 → 1,135
<?php
/**
* PEAR_Sniffs_Functions_FunctionCallArgumentSpacingSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: FunctionCallArgumentSpacingSniff.php,v 1.8 2007/07/23 01:47:53 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_Functions_FunctionCallArgumentSpacingSniff.
*
* Checks that calls to methods and functions are spaced correctly.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_Functions_FunctionCallArgumentSpacingSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_STRING);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
// Skip tokens that are the names of functions or classes
// within their definitions. For example:
// function myFunction...
// "myFunction" is T_STRING but we should skip because it is not a
// function or method *call*.
$functionName = $stackPtr;
$functionKeyword = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
if ($tokens[$functionKeyword]['code'] === T_FUNCTION || $tokens[$functionKeyword]['code'] === T_CLASS) {
return;
}
 
// If the next non-whitespace token after the function or method call
// is not an opening parenthesis then it cant really be a *call*.
$openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($functionName + 1), null, true);
if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
return;
}
 
$closeBracket = $tokens[$openBracket]['parenthesis_closer'];
 
$nextSeperator = $openBracket;
while (($nextSeperator = $phpcsFile->findNext(array(T_COMMA, T_VARIABLE), ($nextSeperator + 1), $closeBracket)) !== false) {
// Make sure the comma or variable belongs directly to this function call,
// and is not inside a nested function call or array.
$brackets = $tokens[$nextSeperator]['nested_parenthesis'];
$lastBracket = array_pop($brackets);
if ($lastBracket !== $closeBracket) {
continue;
}
 
if ($tokens[$nextSeperator]['code'] === T_COMMA) {
if ($tokens[($nextSeperator - 1)]['code'] === T_WHITESPACE) {
$error = 'Space found before comma in function call';
$phpcsFile->addError($error, $stackPtr);
}
 
if ($tokens[($nextSeperator + 1)]['code'] !== T_WHITESPACE) {
$error = 'No space found after comma in function call';
$phpcsFile->addError($error, $stackPtr);
} else {
// If there is a newline in the space, then the must be formatting
// each argument on a newline, which is valid, so ignore it.
if (strpos($tokens[($nextSeperator + 1)]['content'], $phpcsFile->eolChar) === false) {
$space = strlen($tokens[($nextSeperator + 1)]['content']);
if ($space > 1) {
$error = 'Expected 1 space after comma in function call; ';
$error .= $space.' found';
$phpcsFile->addError($error, $stackPtr);
}
}
}
} else {
// Token is a variable.
$nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($nextSeperator + 1), $closeBracket, true);
if ($nextToken !== false) {
if ($tokens[$nextToken]['code'] === T_EQUAL) {
if (($tokens[($nextToken - 1)]['code']) !== T_WHITESPACE) {
$error = 'Expected 1 space before = sign of default value';
$phpcsFile->addError($error, $stackPtr);
}
 
if ($tokens[($nextToken + 1)]['code'] !== T_WHITESPACE) {
$error = 'Expected 1 space after = sign of default value';
$phpcsFile->addError($error, $stackPtr);
}
}
}
}//end if
}//end while
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php
New file
0,0 → 1,196
<?php
/**
* PEAR_Sniffs_Functions_FunctionDeclarationSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: FunctionDeclarationSniff.php,v 1.4 2008/12/01 05:45:49 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_Functions_FunctionDeclarationSniff.
*
* Ensure single and multi-line function declarations are defined correctly.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_Functions_FunctionDeclarationSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_FUNCTION);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
// Check if this is a single line or multi-line declaration.
$openBracket = $tokens[$stackPtr]['parenthesis_opener'];
$closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
if ($tokens[$openBracket]['line'] === $tokens[$closeBracket]['line']) {
$this->processSingleLineDeclaration($phpcsFile, $stackPtr, $tokens);
} else {
$this->processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens);
}
 
}//end process()
 
 
/**
* Processes single-line declarations.
*
* Just uses the Generic BSD-Allman brace sniff.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
* @param array $tokens The stack of tokens that make up
* the file.
*
* @return void
*/
public function processSingleLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
{
if (class_exists('Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff', true) === false) {
throw new PHP_CodeSniffer_Exception('Class Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff not found');
}
 
$sniff = new Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff();
$sniff->process($phpcsFile, $stackPtr);
 
}//end processSingleLineDeclaration()
 
 
/**
* Processes mutli-line declarations.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
* @param array $tokens The stack of tokens that make up
* the file.
*
* @return void
*/
public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
{
// We need to work out how far indented the function
// declaration itself is, so we can work out how far to
// indent parameters.
$functionIndent = 0;
for ($i = ($stackPtr - 1); $i >= 0; $i--) {
if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
$i++;
break;
}
}
 
if ($tokens[$i]['code'] === T_WHITESPACE) {
$functionIndent = strlen($tokens[$i]['content']);
}
 
// Each line between the parenthesis should be indented 4 spaces.
$openBracket = $tokens[$stackPtr]['parenthesis_opener'];
$closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
$lastLine = $tokens[$openBracket]['line'];
for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
if ($tokens[$i]['line'] !== $lastLine) {
if ($tokens[$i]['line'] === $tokens[$closeBracket]['line']) {
// Closing brace needs to be indented to the same level
// as the function.
$expectedIndent = $functionIndent;
} else {
$expectedIndent = ($functionIndent + 4);
}
 
// We changed lines, so this should be a whitespace indent token.
if ($tokens[$i]['code'] !== T_WHITESPACE) {
$foundIndent = 0;
} else {
$foundIndent = strlen($tokens[$i]['content']);
}
 
if ($expectedIndent !== $foundIndent) {
$error = "Multi-line function declaration not indented correctly; expected $expectedIndent spaces but found $foundIndent";
$phpcsFile->addError($error, $i);
}
 
$lastLine = $tokens[$i]['line'];
}
}
 
if (isset($tokens[$stackPtr]['scope_opener']) === true) {
// The openning brace needs to be one space away
// from the closing parenthesis.
$next = $tokens[($closeBracket + 1)];
if ($next['code'] !== T_WHITESPACE) {
$length = 0;
} else if ($next['content'] === $phpcsFile->eolChar) {
$length = -1;
} else {
$length = strlen($next['content']);
}
 
if ($length !== 1) {
$error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found ';
if ($length === -1) {
$error .= 'newline';
} else {
$error .= "$length spaces";
}
 
$phpcsFile->addError($error, ($closeBracket + 1));
return;
}
 
// And just in case they do something funny before the brace...
$next = $phpcsFile->findNext(
T_WHITESPACE,
($closeBracket + 1),
null,
true
);
 
if ($next !== false && $tokens[$next]['code'] !== T_OPEN_CURLY_BRACKET) {
$error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration';
$phpcsFile->addError($error, $next);
}
}
 
}//end processMultiLineDeclaration()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/Formatting/MultiLineAssignmentSniff.php
New file
0,0 → 1,110
<?php
/**
* PEAR_Sniffs_Functions_FunctionDeclarationSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: MultiLineAssignmentSniff.php,v 1.2 2008/12/01 05:02:12 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_Formatting_MultiLineAssignmentSniff.
*
* If an assignment goes over two lines, ensure the equal sign is indented.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_Formatting_MultiLineAssignmentSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_EQUAL);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
// Equal sign can't be the last thing on the line.
$next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
if ($next === false) {
// Bad assignment.
return;
}
 
if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
$error = 'Multi-line assignments must have the equal sign on the second line';
$phpcsFile->addError($error, $stackPtr);
return;
}
 
// Make sure it is the first thing on the line, otherwise we ignore it.
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), false, true);
if ($prev === false) {
// Bad assignment.
return;
}
 
if ($tokens[$prev]['line'] === $tokens[$stackPtr]['line']) {
return;
}
 
// Find the required indent based on the ident of the previous line.
$assignmentIndent = 0;
$prevLine = $tokens[$prev]['line'];
for ($i = ($prev - 1); $i >= 0; $i--) {
if ($tokens[$i]['line'] !== $prevLine) {
$i++;
break;
}
}
 
if ($tokens[$i]['code'] === T_WHITESPACE) {
$assignmentIndent = strlen($tokens[$i]['content']);
}
 
// Find the actual indent.
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1));
 
$expectedIndent = ($assignmentIndent + 4);
$foundIndent = strlen($tokens[$prev]['content']);
if ($foundIndent !== $expectedIndent) {
$error = "Multi-line assignment not indented correctly; expected $expectedIndent spaces but found $foundIndent";
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ScopeIndentSniff.php
New file
0,0 → 1,49
<?php
/**
* PEAR_Sniffs_Whitespace_ScopeIndentSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ScopeIndentSniff.php,v 1.12 2008/03/03 02:51:39 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('Generic_Sniffs_WhiteSpace_ScopeIndentSniff', true) === false) {
$error = 'Class Generic_Sniffs_WhiteSpace_ScopeIndentSniff not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* PEAR_Sniffs_Whitespace_ScopeIndentSniff.
*
* Checks that control structures are structured correctly, and their content
* is indented correctly.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_WhiteSpace_ScopeIndentSniff extends Generic_Sniffs_WhiteSpace_ScopeIndentSniff
{
 
/**
* Any scope openers that should not cause an indent.
*
* @var array(int)
*/
protected $nonIndentingScopes = array(T_SWITCH);
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ObjectOperatorIndentSniff.php
New file
0,0 → 1,158
<?php
/**
* PEAR_Sniffs_WhiteSpace_ObjectOperatorIndentSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ObjectOperatorIndentSniff.php,v 1.2 2009/02/20 00:26:47 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_WhiteSpace_ObjectOperatorIndentSniff.
*
* Checks that object operators are indented 4 spaces if they are the first
* thing on a line.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_WhiteSpace_ObjectOperatorIndentSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_OBJECT_OPERATOR);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
// Make sure this is the first object operator in a chain of them.
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
if ($prev === false || $tokens[$prev]['code'] !== T_VARIABLE) {
return;
}
 
// Make sure this is a chained call.
$next = $phpcsFile->findNext(
T_OBJECT_OPERATOR,
($stackPtr + 1),
null,
false,
null,
true
);
 
if ($next === false) {
// Not a chained call.
return;
}
 
// Determine correct indent.
for ($i = ($stackPtr - 1); $i >= 0; $i--) {
if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
$i++;
break;
}
}
 
$requiredIndent = 0;
if ($tokens[$i]['code'] === T_WHITESPACE) {
$requiredIndent = strlen($tokens[$i]['content']);
}
 
$requiredIndent += 4;
 
// Determine the scope of the original object operator.
$origBrackets = null;
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
$origBrackets = $tokens[$stackPtr]['nested_parenthesis'];
}
 
$origConditions = null;
if (isset($tokens[$stackPtr]['conditions']) === true) {
$origConditions = $tokens[$stackPtr]['conditions'];
}
 
// Check indentation of each object operator in the chain.
while ($next !== false) {
// Make sure it is in the same scope, otherwise dont check indent.
$brackets = null;
if (isset($tokens[$next]['nested_parenthesis']) === true) {
$brackets = $tokens[$next]['nested_parenthesis'];
}
 
$conditions = null;
if (isset($tokens[$next]['conditions']) === true) {
$conditions = $tokens[$next]['conditions'];
}
 
if ($origBrackets === $brackets && $origConditions === $conditions) {
// Make sure it starts a line, otherwise dont check indent.
$indent = $tokens[($next - 1)];
if ($indent['code'] === T_WHITESPACE) {
if ($indent['line'] === $tokens[$next]['line']) {
$foundIndent = strlen($indent['content']);
} else {
$foundIndent = 0;
}
 
if ($foundIndent !== $requiredIndent) {
$error = "Object operator not indented correctly; expected $requiredIndent spaces but found $foundIndent";
$phpcsFile->addError($error, $next);
}
}
 
// It cant be the last thing on the line either.
$content = $phpcsFile->findNext(T_WHITESPACE, ($next + 1), null, true);
if ($tokens[$content]['line'] !== $tokens[$next]['line']) {
$error = 'Object operator must be at the start of the line, not the end';
$phpcsFile->addError($error, $next);
}
}//end if
 
$next = $phpcsFile->findNext(
T_OBJECT_OPERATOR,
($next + 1),
null,
false,
null,
true
);
}//end while
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php
New file
0,0 → 1,128
<?php
/**
* PEAR_Sniffs_Whitespace_ScopeClosingBraceSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ScopeClosingBraceSniff.php,v 1.10 2008/12/08 05:59:29 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* PEAR_Sniffs_Whitespace_ScopeClosingBraceSniff.
*
* Checks that the closing braces of scopes are aligned correctly.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Sniffs_WhiteSpace_ScopeClosingBraceSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return PHP_CodeSniffer_Tokens::$scopeOpeners;
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
// If this is an inline condition (ie. there is no scope opener), then
// return, as this is not a new scope.
if (isset($tokens[$stackPtr]['scope_closer']) === false) {
return;
}
 
// We need to actually find the first piece of content on this line,
// as if this is a method with tokens before it (public, static etc)
// or an if with an else before it, then we need to start the scope
// checking from there, rather than the current token.
$lineStart = ($stackPtr - 1);
for ($lineStart; $lineStart > 0; $lineStart--) {
if (strpos($tokens[$lineStart]['content'], $phpcsFile->eolChar) !== false) {
break;
}
}
 
// We found a new line, now go forward and find the first non-whitespace
// token.
$lineStart= $phpcsFile->findNext(
array(T_WHITESPACE),
($lineStart + 1),
null,
true
);
 
$startColumn = $tokens[$lineStart]['column'];
$scopeStart = $tokens[$stackPtr]['scope_opener'];
$scopeEnd = $tokens[$stackPtr]['scope_closer'];
 
// Check that the closing brace is on it's own line.
$lastContent = $phpcsFile->findPrevious(
array(T_WHITESPACE),
($scopeEnd - 1),
$scopeStart,
true
);
 
if ($tokens[$lastContent]['line'] === $tokens[$scopeEnd]['line']) {
$error = 'Closing brace must be on a line by itself';
$phpcsFile->addError($error, $scopeEnd);
return;
}
 
// Check now that the closing brace is lined up correctly.
$braceIndent = $tokens[$scopeEnd]['column'];
$isBreakCloser = ($tokens[$scopeEnd]['code'] === T_BREAK);
if (in_array($tokens[$stackPtr]['code'], array(T_CASE, T_DEFAULT)) === true
&& $isBreakCloser === true
) {
// BREAK statements should be indented 4 spaces from the
// CASE or DEFAULT statement.
if ($braceIndent !== ($startColumn + 4)) {
$error = 'Break statement indented incorrectly; expected '.($startColumn + 3).' spaces, found '.($braceIndent - 1);
$phpcsFile->addError($error, $scopeEnd);
}
} else {
if ($braceIndent !== $startColumn) {
$error = 'Closing brace indented incorrectly; expected '.($startColumn - 1).' spaces, found '.($braceIndent - 1);
$phpcsFile->addError($error, $scopeEnd);
}
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/PEARCodingStandard.php
New file
0,0 → 1,57
<?php
/**
* PEAR Coding Standard.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: PEARCodingStandard.php,v 1.8 2008/11/17 05:04:07 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_Standards_CodingStandard', true) === false) {
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_CodingStandard not found');
}
 
/**
* PEAR Coding Standard.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Standards_PEAR_PEARCodingStandard extends PHP_CodeSniffer_Standards_CodingStandard
{
 
 
/**
* Return a list of external sniffs to include with this standard.
*
* The PEAR standard uses some generic sniffs.
*
* @return array
*/
public function getIncludedSniffs()
{
return array(
'Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php',
'Generic/Sniffs/PHP/LowerCaseConstantSniff.php',
'Generic/Sniffs/PHP/DisallowShortOpenTagSniff.php',
'Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php',
);
 
}//end getIncludedSniffs()
 
 
}//end class
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Files/IncludingFileUnitTest.php
New file
0,0 → 1,85
<?php
/**
* Unit test class for the IncludingFile sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: IncludingFileUnitTest.php,v 1.3 2007/01/10 03:14:43 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the IncludingFile sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_Files_IncludingFileUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
4 => 1,
5 => 1,
11 => 1,
12 => 1,
16 => 1,
17 => 1,
33 => 1,
34 => 1,
47 => 1,
48 => 1,
64 => 1,
65 => 1,
73 => 1,
74 => 1,
85 => 1,
86 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Files/IncludingFileUnitTest.inc
New file
0,0 → 1,98
<?php
 
// These are statements and should not have brackets.
require_once('blank.inc');
require('blank.inc');
 
$test = true;
 
// Conditionally including a class file: use include_once
if ($test) {
require_once 'blank.inc';
require 'blank.inc';
}
 
// Unconditionally including a class file: use require_once
include_once 'blank.inc';
include 'blank.inc';
 
 
// These are ok
if ($test) {
include_once 'blank.inc';
include 'blank.inc';
}
 
require_once 'blank.inc';
require 'blank.inc';
 
?>
<pre>
Some content goes here.
<?php
include_once 'blank.inc';
include 'blank.inc';
require_once 'blank.inc';
require 'blank.inc';
?>
</pre>
<?php
 
if (include_once 'blank.inc') {
$var = include_once 'blank.inc';
if ($var === true) {
}
}
 
if (require_once 'blank.inc') {
$var = require_once 'blank.inc';
if ($var === true) {
}
}
 
function get_some_value()
{
include_once 'blank.inc';
include 'blank.inc';
 
// These are ok
if ($test) {
include_once 'blank.inc';
include 'blank.inc';
}
 
require_once 'blank.inc';
require 'blank.inc';
 
?>
<pre>
Some content goes here.
<?php
include_once 'blank.inc';
include 'blank.inc';
require_once 'blank.inc';
require 'blank.inc';
?>
</pre>
<?php
 
if (include_once 'blank.inc') {
$var = include_once 'blank.inc';
if ($var === true) {
}
}
if (require_once 'blank.inc') {
$var = require_once 'blank.inc';
if ($var === true) {
}
}
}
 
 
$var = include_once 'blank.inc';
if ($var == false) {
 
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/ControlStructures/ControlSignatureUnitTest.php
New file
0,0 → 1,90
<?php
/**
* Unit test class for the ControlSignature sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ControlSignatureUnitTest.php,v 1.3 2007/01/10 03:14:43 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ControlSignature sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_ControlStructures_ControlSignatureUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
9 => 1,
14 => 1,
20 => 1,
22 => 1,
32 => 1,
36 => 1,
44 => 1,
48 => 1,
56 => 1,
60 => 1,
68 => 1,
72 => 1,
84 => 1,
88 => 2,
100 => 1,
104 => 2,
122 => 2,
128 => 1,
132 => 3,
133 => 2,
147 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/ControlStructures/ControlSignatureUnitTest.inc
New file
0,0 → 1,155
<?php
 
// do ... while
$i = 0;
do {
echo $i;
} while ($i > 0);
 
do
{
echo $i;
} while ($i > 0);
 
do
{
echo $i;
}
while ($i > 0);
 
do { echo $i; } while ($i > 0);
 
do{
echo $i;
}while($i > 0);
 
 
// while
while ($i < 1) {
echo $i;
}
 
while($i < 1){
echo $i;
}
 
while ($i < 1) { echo $i; }
 
 
// for
for ($i = 1; $i < 1; $i++) {
echo $i;
}
 
for($i = 1; $i < 1; $i++){
echo $i;
}
 
for ($i = 1; $i < 1; $i++) { echo $i; }
 
 
// foreach
foreach ($items as $item) {
echo $item;
}
 
foreach($items as $item){
echo $item;
}
 
for ($items as $item) { echo $item; }
 
 
// if
if ($i == 0) {
$i = 1;
}
 
if($i == 0){
$i = 1;
}
 
if ($i == 0) { $i = 1; }
 
 
// else
if ($i == 0) {
$i = 1;
} else {
$i = 0;
}
 
if ($i == 0) {
$i = 1;
}else{
$i = 0;
}
 
if ($i == 0) { $i = 1; } else { $i = 0; }
 
 
// else
if ($i == 0) {
$i = 1;
} else {
$i = 0;
}
 
if ($i == 0) {
$i = 1;
}else{
$i = 0;
}
 
if ($i == 0) { $i = 1; } else { $i = 0; }
 
 
// else if
if ($i == 0) {
$i = 1;
} else if ($i == 2) {
$i = 0;
}
 
if ($i == 0) {
$i = 1;
} elseif ($i == 2) {
$i = 0;
}
 
if ($i == 0) {
$i = 1;
}else if($i == 2){
$i = 0;
}
 
if ($i == 0) {
$i = 1;
}elseif($i == 2){
$i = 0;
}
 
if ($i == 0) { $i = 1; } else if ($i == 2) { $i = 0; }
if ($i == 0) { $i = 1; } elseif ($1 == 2) { $i = 0; }
 
if ($i == 0) { // this is ok because comments are allowed
$i = 1;
}
 
if ($i == 0) {// this is ok because comments are allowed
$i = 1;
}
 
if ($i == 0) { /* this is ok because comments are allowed*/
$i = 1;
}
 
if ($i == 0)
{ // this is not ok
$i = 1;
}
 
if ($i == 0) /* this is ok */ {
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/ControlStructures/MultiLineConditionUnitTest.php
New file
0,0 → 1,84
<?php
/**
* Unit test class for the MultiLineCondition sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: MultiLineConditionUnitTest.php,v 1.2 2008/12/07 22:25:02 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the MultiLineCondition sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_ControlStructures_MultiLineConditionUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
19 => 1,
32 => 1,
37 => 1,
38 => 1,
39 => 1,
40 => 1,
46 => 1,
51 => 1,
55 => 1,
56 => 1,
58 => 1,
85 => 1,
86 => 1,
87 => 1,
93 => 2,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/ControlStructures/MultiLineConditionUnitTest.inc
New file
0,0 → 1,100
<?php
if (($condition1
|| $condition2)
&& $condition3
&& $condition4
&& $condition5
) {
}
 
if (($condition1 || $condition2) && $condition3 && $condition4 && $condition5) {
}
 
if (($condition1 || $condition2)
&& $condition3
) {
}
 
if (
($condition1 || $condition2)
&& $condition3
) {
}
 
if (($condition1
|| $condition2)
) {
}
 
if (($condition1
|| $condition2)
&& $condition3 &&
$condition4
) {
}
 
if (($condition1
|| $condition2)
&& $condition3
&& $condition4
&& $condition5
) {
}
 
if (($condition1
|| $condition2)
) {
}
 
if (($condition1
|| $condition2)
) {
}
 
if (
(
$condition1
|| $condition2
)
&& $condition3
) {
}
 
 
if ( $condition1
|| $condition2
|| $condition3
) {
}
 
if ($condition1
|| $condition2
|| $condition3
) {
} else if ($condition1
|| $condition2
|| $condition3
) {
}
 
if ($condition1
|| $condition2
|| $condition3
) {
} else if (
$condition1
|| $condition2 &&
$condition3
) {
}
 
if ($condition1
|| $condition2
|| $condition3) {
}
 
if ($condition1
|| $condition2 || $condition3
) {
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc
New file
0,0 → 1,54
<?php
 
$result = myFunction();
$result = myFunction($arg1, $arg2);
$result = myFunction($arg1,$arg2);
$result = myFunction($arg1 , $arg2);
$result = myFunction($arg1 , $arg2);
$result = myFunction($arg1, $arg2, $arg3,$arg4, $arg5);
$result = myFunction($arg1, $arg2, $arg3, $arg4, $arg5);
$result = myFunction($arg1, $arg2 = array());
$result = myFunction($arg1 , $arg2 =array());
$result = myFunction($arg1 , $arg2= array());
$result = myFunction($arg1 , $arg2=array());
 
$result = myFunction($arg1,
$arg2 = array(),
$arg3,
$arg4,
$arg5);
 
throw new Exception("This is some massive string for a message",
$cause);
 
// Function definitions are ignored
function myFunction($arg1,$arg2)
{
}
 
function myFunction ($arg1,$arg2)
{
}
 
function myFunction($arg1=1,$arg2=2)
{
}
 
 
function myFunction($arg1 = 1,$arg2 = 2)
{
}
 
$key = array_search($this->getArray($one, $two,$three),$this->arrayMap);
$this->error($obj->getCode(),$obj->getMessage(),$obj->getFile(),$obj->getLine());
 
make_foo($string /*the string*/ , true /*test*/);
make_foo($string/*the string*/ , /*test*/ true);
make_foo($string /*the string*/, /*test*/ true);
 
class MyClass {
function myFunction() {
blah($foo, "{{$config['host']}}", "{$config}", "hi there{}{}{{{}{}{}}");
}
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.php
New file
0,0 → 1,78
<?php
/**
* Unit test class for the FunctionDeclaration sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: FunctionDeclarationUnitTest.php,v 1.2 2008/12/01 05:45:50 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the FunctionDeclaration sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_Functions_FunctionDeclarationUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
3 => 1,
4 => 1,
5 => 1,
9 => 1,
10 => 1,
11 => 1,
14 => 1,
27 => 1,
46 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc
New file
0,0 → 1,50
<?php
public function someFunctionWithAVeryLongName($firstParameter='something',
$secondParameter='booooo', $third=null, $fourthParameter=false,
$fifthParameter=123.12, $sixthParam=true
){
}
 
function someFunctionWithAVeryLongName2($firstParameter='something',
$secondParameter='booooo', $third=null, $fourthParameter=false,
$fifthParameter=123.12, $sixthParam=true
) {
}
 
function blah() {
}
 
function blah()
{
}
 
class MyClass
{
 
public function someFunctionWithAVeryLongName($firstParameter='something',
$secondParameter='booooo', $third=null, $fourthParameter=false,
$fifthParameter=123.12, $sixthParam=true
) /** w00t */ {
}
 
public function someFunctionWithAVeryLongName2(
$firstParameter='something', $secondParameter='booooo', $third=null
) {
}
 
protected abstract function processTokenWithinScope(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr,
$currScope
);
 
}
 
function getInstalledStandards(
$includeGeneric=false,
$standardsDir=''
)
{
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Functions/ValidDefaultValueUnitTest.php
New file
0,0 → 1,75
<?php
/**
* Unit test class for the ValidDefaultValue sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ValidDefaultValueUnitTest.php,v 1.1 2006/12/27 23:19:18 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ValidDefaultValue sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_Functions_ValidDefaultValueUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
29 => 1,
34 => 1,
39 => 1,
71 => 1,
76 => 1,
81 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.php
New file
0,0 → 1,83
<?php
/**
* Unit test class for the FunctionCallSignature sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: FunctionCallSignatureUnitTest.php,v 1.4 2008/12/05 02:45:08 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the FunctionCallSignature sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_Functions_FunctionCallSignatureUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
5 => 1,
6 => 1,
7 => 1,
8 => 1,
9 => 2,
10 => 3,
17 => 1,
18 => 1,
31 => 1,
34 => 1,
57 => 1,
59 => 1,
63 => 1,
64 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Functions/ValidDefaultValueUnitTest.inc
New file
0,0 → 1,86
<?php
 
// No args.
function myFunction()
{
}
 
// No default args.
function myFunction($arg1)
{
}
 
// Valid
function myFunction($arg1, $arg2='hello')
{
}
 
// Valid with lots of args
function myFunction($arg1, $arg2, $arg3, $arg4='hello', $arg5=array(), $arg6='hello')
{
}
 
// Valid type hints
function myFunction(array $arg1, array $arg2=array())
{
}
 
// Invalid
function myFunction($arg2='hello', $arg1)
{
}
 
// Invalid with lots of args
function myFunction($arg1, $arg2, $arg3, $arg4='hello', $arg5, $arg6='hello')
{
}
 
// Invalid type hints
function myFunction(array $arg2=array(), array $arg1)
{
}
 
class myClass()
{
// No args.
function myFunction()
{
}
 
// No default args.
function myFunction($arg1)
{
}
 
// Valid
function myFunction($arg1, $arg2='hello')
{
}
 
// Valid with lots of args
function myFunction($arg1, $arg2, $arg3, $arg4='hello', $arg5=array(), $arg6='hello')
{
}
 
// Valid type hints
function myFunction(array $arg1, array $arg2=array())
{
}
 
// Invalid
function myFunction($arg2='hello', $arg1)
{
}
 
// Invalid with lots of args
function myFunction($arg1, $arg2, $arg3, $arg4='hello', $arg5, $arg6='hello')
{
}
 
// Invalid type hints
function myFunction(array $arg2=array(), array $arg1)
{
}
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc
New file
0,0 → 1,65
<?php
 
test();
test($arg, $arg2);
test ();
test( );
test() ;
test( $arg);
test( $arg );
test ( $arg );
 
if (is_array($arg) === true) {
 
}
 
$something = get($arg1, $arg2);
$something = get($arg1, $arg2) ;
$something = get($arg1, $arg2) ;
 
// No errors as this test only checks for function calls.
class TestClass extends MyClass
{
 
const const1 = 'hello';
const CONST2 = 'hello';
 
public function test () { }
}
 
make_foo($string/*the string*/, true/*test*/);
make_foo($string/*the string*/, true/*test*/ );
make_foo($string /*the string*/, true /*test*/);
make_foo(/*the string*/$string, /*test*/true);
make_foo( /*the string*/$string, /*test*/true);
 
// No errors should be throw here because
// this is not a function call per se.
throw new Exception(
'Exception text'
);
 
// Or here.
$obj = new TestClass( );
 
// Heredocs dont need to be indented.
method_call(
<<<EOH
Anyone want to recomment parse errors?
 
EOH
);
 
fputs(
STDOUT,
'Examples:
$ {$app} --all
$ {$app} --all');
 
fputs(STDOUT,
"Examples:
$ {$app} --all
$ {$app} --all",
$something
);
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionCallArgumentSpacingUnitTest.php
New file
0,0 → 1,80
<?php
/**
* Unit test class for the FunctionCallArgumentSpacing sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: FunctionCallArgumentSpacingUnitTest.php,v 1.3 2007/01/10 03:14:43 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the FunctionCallArgumentSpacing sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_Functions_FunctionCallArgumentSpacingUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
5 => 1,
6 => 1,
7 => 2,
8 => 1,
11 => 2,
12 => 2,
13 => 3,
42 => 3,
43 => 3,
45 => 1,
46 => 2,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Formatting/MultiLineAssignmentUnitTest.php
New file
0,0 → 1,70
<?php
/**
* Unit test class for the MultiLineAssignment sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: MultiLineAssignmentUnitTest.php,v 1.1 2008/11/17 05:59:24 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the MultiLineAssignment sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_Formatting_MultiLineAssignmentUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
3 => 1,
6 => 1,
8 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Formatting/MultiLineAssignmentUnitTest.inc
New file
0,0 → 1,22
<?php
$GLOBALS['TSFE']->additionalHeaderData[$this->strApplicationName]
= $this->xajax->getJavascript(t3lib_extMgm::siteRelPath('nr_xajax'));
 
$GLOBALS['TSFE']->additionalHeaderData[$this->strApplicationName]
= $this->xajax->getJavascript(t3lib_extMgm::siteRelPath('nr_xajax'));
 
$GLOBALS['TSFE']->additionalHeaderData[$this->strApplicationName] =
$this->xajax->getJavascript(t3lib_extMgm::siteRelPath('nr_xajax'));
 
$GLOBALS['TSFE']->additionalHeaderData[$this->strApplicationName]
= $this->xajax->getJavascript(t3lib_extMgm::siteRelPath('nr_xajax'));
$GLOBALS['TSFE']->additionalHeaderData[$this->strApplicationName] = 'boo'
 
$var='string';
 
function getInstalledStandards(
$includeGeneric=false,
$standardsDir=''
) {
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/WhiteSpace/ScopeIndentUnitTest.php
New file
0,0 → 1,83
<?php
/**
* Unit test class for the ScopeIndent sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ScopeIndentUnitTest.php,v 1.5 2006/12/12 02:57:38 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ScopeIndent sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_WhiteSpace_ScopeIndentUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
7 => 1,
10 => 1,
17 => 1,
20 => 1,
24 => 1,
27 => 1,
28 => 1,
58 => 1,
123 => 1,
126 => 1,
224 => 1,
225 => 1,
279 => 1,
284 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/WhiteSpace/ScopeIndentUnitTest.inc
New file
0,0 → 1,306
<?php
 
class Test
{
function __construct()
{
$this->hello(); // error here
}
 
function hello() // error here
{ // no error here as brackets can be put anywhere in the pear standard
echo 'hello';
}
 
function hello2()
{
if (TRUE) { // error here
echo 'hello'; // no error here as its more than 4 spaces.
} else {
echo 'bye'; // error here
}
 
while (TRUE) {
echo 'hello'; // error here
}// no error here as its handled by another test.
 
do { // error here
echo 'hello'; // error here
} while (TRUE); // no error here as its aligned with the do.
}// no error here as its handled by another test.
 
function hello3()
{
switch ($hello) {
case 'hello': // no error here as switch statements shouldn't be indented ???
break;
}
}
 
}
 
?>
<pre>
</head>
<body>
<?php
if ($form->validate()) {
$safe = $form->getSubmitValues();
}
?>
</pre>
<?php
 
class Test2
{
function __construct()
{
// $this->open(); // error here
}
 
public function open()
{
// Some inline stuff that shouldn't error
if (TRUE) echo 'hello';
foreach ($tokens as $token) echo $token;
}
 
/**
* This is a comment 1.
* This is a comment 2.
* This is a comment 3.
* This is a comment 4.
*/
public function close()
{
// All ok.
if (TRUE) {
if (TRUE) {
} else if (FALSE) {
foreach ($tokens as $token) {
switch ($token) {
case '1':
case '2':
if (true) {
if (false) {
if (false) {
if (false) {
echo 'hello';
}
}
}
}
break;
case '5':
break;
}
do {
while (true) {
foreach ($tokens as $token) {
for ($i = 0; $i < $token; $i++) {
echo 'hello';
}
}
}
} while (true);
}
}
}
}
 
/*
This is another c style comment 1.
This is another c style comment 2.
This is another c style comment 3.
This is another c style comment 4.
This is another c style comment 5.
*/
 
/*
*
*
*
*/
 
/**
*/
 
/*
This comment has a newline in it.
 
*/
 
public function read()
{
echo 'hello';
 
// no errors below.
$array = array(
'this',
'that' => array(
'hello',
'hello again' => array(
'hello',
),
),
);
}
}
 
abstract class Test3
{
public function parse()
{
 
foreach ($t as $ndx => $token) {
if (is_array($token)) {
echo 'here';
} else {
$ts[] = array("token" => $token, "value" => '');
 
$last = count($ts) - 1;
 
switch ($token) {
case '(':
 
if ($last >= 3 &&
$ts[0]['token'] != T_CLASS &&
$ts[$last - 2]['token'] == T_OBJECT_OPERATOR &&
$ts[$last - 3]['token'] == T_VARIABLE ) {
 
 
if (true) {
echo 'hello';
}
}
array_push($braces, $token);
break;
}
}
}
}
}
 
public function test()
{
$o = <<<EOF
this is some text
this is some text
this is some text
this is some text
this is some text
this is some text
EOF;
 
return $o;
}
 
if ($a === true || $a === true || $a === true || $a === true ||
$a === true || $a === true || $a === true || $a === true) {
 
echo 'hello';
}
 
if ($true) {
/* First comment line
*
* Comment test here
* Comment test here
*
*/
/* First comment line
*
* Comment test here
* Comment test here
*
this si something */
}
 
function test()
{
/* taken from http://de3.php.net/manual/en/reserved.php */
# $m[] = 'declare';
/* taken from http://de3.php.net/manual/en/reserved.php */
# $m[] = 'declare';
}
 
foreach ($elements as $element) {
if ($something) {
// Do IF.
} else if ($somethingElse) {
// Do ELSE.
}
}
 
if ($condition) {
echo "This is a long
string that spans $numLines lines
without indenting.
";
}
 
if ($condition) {
echo 'This is a long
string that spans nultiple lines
with indenting.
';
}
 
if ($condition) {
echo 'This is a long
string that spans nultiple lines
with indenting.';
}
 
switch ($foo) {
case 1:
switch ($bar) {
default:
echo $string{1};
}
break;
}
 
function temp($foo, $bar) {
switch ($foo) {
case 1:
switch ($bar) {
default:
return $foo;
}
break;
}
}
 
switch ($foo) {
case 1:
switch ($bar) {
default:
if ($something) {
echo $string{1};
} else if ($else) {
switch ($else) {
default:
}
}
}
break;
}
 
switch ($name) {
case "1":
case "2":
case "3":
return true;
}
 
switch ($name) {
case "1":
case "2":
case "3":
default :
return true;
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/WhiteSpace/ObjectOperatorIndentUnitTest.php
New file
0,0 → 1,71
<?php
/**
* Unit test class for the ObjectOperatorIndent sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ObjectOperatorIndentUnitTest.php,v 1.2 2009/02/20 00:26:47 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ObjectOperatorIndent sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_WhiteSpace_ObjectOperatorIndentUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
3 => 2,
6 => 1,
15 => 1,
27 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.php
New file
0,0 → 1,74
<?php
/**
* Unit test class for the ScopeClosingBrace sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ScopeClosingBraceUnitTest.php,v 1.4 2006/12/12 02:57:38 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ScopeClosingBrace sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_WhiteSpace_ScopeClosingBraceUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
11 => 1,
13 => 1,
24 => 1,
61 => 1,
65 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/WhiteSpace/ObjectOperatorIndentUnitTest.inc
New file
0,0 → 1,31
<?php
$someObject->someFunction("some", "parameter")
->someOtherFunc(23, 42)->
someOtherFunc2($one, $two)
 
->someOtherFunc3(23, 42)
->andAThirdFunction();
 
$someObject->someFunction("some", "parameter")
->someOtherFunc(23, 42);
 
$someObject->someFunction("some", "parameter")->someOtherFunc(23, 42);
 
$someObject->someFunction("some", "parameter")
->someOtherFunc(23, 42);
 
func(
$bar->foo()
)
->bar();
 
func(
$bar->foo()
)
->bar(
$bar->foo()
->bar()
->func()
);
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/WhiteSpace/ScopeClosingBraceUnitTest.inc
New file
0,0 → 1,71
<?php
 
class Test
{
public function __construct()
{
}
 
function test1()
{
}
 
function test2() {}
 
private function _test3()
{
}
 
}
 
 
class Test2
{
}
 
 
public function test2()
{
if ($str{0}) {
$chr = $str{0};
}
if (!class_exists($class_name)) {
echo $error;
}
$this->{$property} =& new $class_name($this->db_index);
$this->modules[$module] =& $this->{$property};
}
 
foreach ($elements as $element) {
if ($something) {
// Do IF.
} else if ($somethingElse) {
// Do ELSE.
}
}
 
switch ($foo) {
case 1:
switch ($bar) {
default:
if ($something) {
echo $string{1};
} else if ($else) {
switch ($else) {
case 1:
// Do something.
break;
default:
// Do something.
break;
}
}
}
break;
case 2:
// Do something;
break;
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Classes/ClassDeclarationUnitTest.php
New file
0,0 → 1,76
<?php
/**
* Unit test class for the ClassDeclaration sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ClassDeclarationUnitTest.php,v 1.3 2007/12/04 23:23:33 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ClassDeclaration sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_Classes_ClassDeclarationUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
21 => 1,
22 => 1,
23 => 1,
27 => 1,
33 => 1,
38 => 1,
49 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Classes/ClassDeclarationUnitTest.inc
New file
0,0 → 1,63
<?php
 
// Correct declarations.
class CorrectClassDeclaration
{
 
}
 
abstract class CorrectClassDeclarationWithExtends extends correctClassDeclaration
{
 
}
 
final class CorrectClassDeclarationWithImplements implements correctClassDeclaration
{
 
}
 
 
// Incorrect placement of opening braces
class IncorrectBracePlacement {}
class IncorrectBracePlacementWithExtends extends correctClassDeclaration {}
class IncorrectBracePlacementWithImplements implements correctClassDeclaration {}
 
// Incorrect code placement for opening brace.
class IncorrectCodeAfterOpeningBrace
{ echo phpinfo();
 
}//end class
 
class IncorrectClassDeclarationWithExtends extends correctClassDeclaration
 
{
 
}
 
class IncorrectBracePlacement
{
}
 
abstract class CodeSnifferFail
extends
ArrayObject
implements
Serializable,
Iterator,
Countable,
OuterIterator,
RecursiveIterator {
}
 
abstract class CodeSnifferFail
extends
ArrayObject
implements
Serializable,
Iterator,
Countable,
OuterIterator,
RecursiveIterator
{
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.php
New file
0,0 → 1,81
<?php
/**
* Unit test class for the ValidClassName sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ValidClassNameUnitTest.php,v 1.5 2008/04/28 01:02:28 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ValidClassName sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_NamingConventions_ValidClassNameUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
5 => 1,
7 => 2,
9 => 1,
19 => 1,
24 => 1,
26 => 2,
28 => 1,
38 => 1,
40 => 2,
42 => 2,
44 => 1,
46 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.php
New file
0,0 → 1,176
<?php
/**
* Unit test class for the ValidFunctionName sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ValidFunctionNameUnitTest.php,v 1.7 2008/01/22 23:50:23 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ValidFunctionName sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_NamingConventions_ValidFunctionNameUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
11 => 1,
12 => 1,
13 => 1,
14 => 1,
15 => 1,
16 => 1,
17 => 1,
18 => 1,
19 => 1,
20 => 1,
24 => 1,
25 => 1,
26 => 1,
27 => 1,
28 => 1,
29 => 1,
30 => 1,
31 => 1,
32 => 1,
33 => 1,
35 => 1,
36 => 1,
37 => 1,
38 => 1,
39 => 1,
40 => 1,
43 => 1,
44 => 1,
45 => 1,
46 => 1,
50 => 1,
51 => 1,
52 => 1,
53 => 1,
56 => 1,
57 => 1,
58 => 1,
59 => 1,
67 => 1,
68 => 1,
69 => 1,
70 => 1,
71 => 1,
72 => 1,
73 => 1,
74 => 1,
75 => 1,
76 => 1,
80 => 1,
81 => 1,
82 => 1,
83 => 1,
84 => 1,
85 => 1,
86 => 1,
87 => 1,
88 => 1,
89 => 1,
91 => 1,
92 => 1,
93 => 1,
94 => 1,
95 => 1,
96 => 1,
99 => 1,
100 => 1,
101 => 1,
102 => 1,
106 => 1,
107 => 1,
108 => 1,
109 => 1,
112 => 1,
113 => 1,
114 => 1,
115 => 1,
121 => 1,
122 => 1,
123 => 1,
124 => 1,
125 => 1,
126 => 1,
127 => 1,
128 => 1,
129 => 1,
130 => 1,
149 => 1,
150 => 1,
151 => 1,
154 => 1,
155 => 1,
156 => 1,
157 => 1,
158 => 1,
159 => 1,
160 => 1,
161 => 1,
162 => 1,
163 => 1,
164 => 1,
165 => 1,
166 => 1,
168 => 1,
169 => 1,
171 => 1,
172 => 1,
173 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/NamingConventions/ValidVariableNameUnitTest.php
New file
0,0 → 1,70
<?php
/**
* Unit test class for the ValidVariableName sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ValidVariableNameUnitTest.php,v 1.1 2008/01/31 22:17:02 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ValidVariableName sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_NamingConventions_ValidVariableNameUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
12 => 1,
17 => 1,
22 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.inc
New file
0,0 → 1,48
<?php
 
class Valid_Name {}
 
class invalid_Name {}
 
class invalid_name {}
 
class Invalid_name {}
 
class VALID_Name {}
 
class VALID_NAME {}
 
class VALID_Name {}
 
class ValidName {}
 
class _Invalid_Name {}
 
 
interface Valid_Name {}
 
interface invalid_Name {}
 
interface invalid_name {}
 
interface Invalid_name {}
 
interface VALID_Name {}
 
interface VALID_NAME {}
 
interface VALID_Name {}
 
interface ValidName {}
 
interface _Invalid_Name {}
 
class ___ {}
 
interface ___ {}
 
class Invalid__Name {}
 
interface Invalid__Name {}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.inc
New file
0,0 → 1,175
<?php
 
abstract class My_Class {
 
public function __construct() {}
public function My_Class() {}
public function _My_Class() {}
 
public function getSomeValue() {}
public function parseMyDSN() {}
public function get_some_value() {}
public function GetSomeValue() {}
public function getSomeValue_Again() {}
public function My_Package_getSomeValue() {}
public function _getSomeValue() {}
public function _parseMyDSN() {}
public function _get_some_value() {}
public function _GetSomeValue() {}
public function _getSomeValue_Again() {}
public function _My_Package_getSomeValue() {}
 
protected function getSomeValue() {}
protected function parseMyDSN() {}
protected function get_some_value() {}
protected function GetSomeValue() {}
protected function getSomeValue_Again() {}
protected function My_Package_getSomeValue() {}
protected function _getSomeValue() {}
protected function _parseMyDSN() {}
protected function _get_some_value() {}
protected function _GetSomeValue() {}
protected function _getSomeValue_Again() {}
protected function _My_Package_getSomeValue() {}
 
private function getSomeValue() {}
private function parseMyDSN() {}
private function get_some_value() {}
private function GetSomeValue() {}
private function getSomeValue_Again() {}
private function My_Package_getSomeValue() {}
private function _getSomeValue() {}
private function _parseMyDSN() {}
private function _get_some_value() {}
private function _GetSomeValue() {}
private function _getSomeValue_Again() {}
private function _My_Package_getSomeValue() {}
 
function getSomeValue() {}
function parseMyDSN() {}
function get_some_value() {}
function GetSomeValue() {}
function getSomeValue_Again() {}
function My_Package_getSomeValue() {}
function _getSomeValue() {}
function _parseMyDSN() {}
function _get_some_value() {}
function _GetSomeValue() {}
function _getSomeValue_Again() {}
function _My_Package_getSomeValue() {}
 
}//end class
 
interface My_Interface {
 
public function getSomeValue() {}
public function parseMyDSN() {}
public function get_some_value() {}
public function GetSomeValue() {}
public function getSomeValue_Again() {}
public function My_Package_getSomeValue() {}
public function _getSomeValue() {}
public function _parseMyDSN() {}
public function _get_some_value() {}
public function _GetSomeValue() {}
public function _getSomeValue_Again() {}
public function _My_Package_getSomeValue() {}
 
protected function getSomeValue() {}
protected function parseMyDSN() {}
protected function get_some_value() {}
protected function GetSomeValue() {}
protected function getSomeValue_Again() {}
protected function My_Package_getSomeValue() {}
protected function _getSomeValue() {}
protected function _parseMyDSN() {}
protected function _get_some_value() {}
protected function _GetSomeValue() {}
protected function _getSomeValue_Again() {}
protected function _My_Package_getSomeValue() {}
 
private function getSomeValue() {}
private function parseMyDSN() {}
private function get_some_value() {}
private function GetSomeValue() {}
private function getSomeValue_Again() {}
private function My_Package_getSomeValue() {}
private function _getSomeValue() {}
private function _parseMyDSN() {}
private function _get_some_value() {}
private function _GetSomeValue() {}
private function _getSomeValue_Again() {}
private function _My_Package_getSomeValue() {}
 
function getSomeValue() {}
function parseMyDSN() {}
function get_some_value() {}
function GetSomeValue() {}
function getSomeValue_Again() {}
function My_Package_getSomeValue() {}
function _getSomeValue() {}
function _parseMyDSN() {}
function _get_some_value() {}
function _GetSomeValue() {}
function _getSomeValue_Again() {}
function _My_Package_getSomeValue() {}
 
}//end interface
 
function My_Package_getSomeValue() {}
function My_Package_parseMyDSN() {}
function My_Package_get_some_value() {}
function My_PackagegetSomeValue() {}
function My_Package_getSomeValue_Again() {}
function My_Package() {}
function _My_Package_getSomeValue() {}
function _My_Package_parseMyDSN() {}
function _My_Package_get_some_value() {}
function _My_PackagegetSomeValue() {}
function _My_Package_getSomeValue_Again() {}
function _My_Package() {}
 
 
/* Test for magic functions */
 
class Magic_Test {
function __construct() {}
function __destruct() {}
function __call() {}
function __callStatic() {}
function __get() {}
function __set() {}
function __isset() {}
function __unset() {}
function __sleep() {}
function __wakeup() {}
function __toString() {}
function __set_state() {}
function __clone() {}
function __autoload() {}
function __myFunction() {}
function __my_function() {}
}
 
function __construct() {}
function __destruct() {}
function __call() {}
function __callStatic() {}
function __get() {}
function __set() {}
function __isset() {}
function __unset() {}
function __sleep() {}
function __wakeup() {}
function __toString() {}
function __set_state() {}
function __clone() {}
function __autoload() {}
function __myFunction() {}
function __my_function() {}
 
function my_package_function() {}
function Package_() {}
function Package() {}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/NamingConventions/ValidVariableNameUnitTest.inc
New file
0,0 → 1,60
<?php
class MyClass
{
$varName = 'hello';
$var_name = 'hello';
$varname = 'hello';
$_varName = 'hello';
 
public $varName = 'hello';
public $var_name = 'hello';
public $varname = 'hello';
public $_varName = 'hello';
 
protected $varName = 'hello';
protected $var_name = 'hello';
protected $varname = 'hello';
protected $_varName = 'hello';
 
private $_varName = 'hello';
private $_var_name = 'hello';
private $_varname = 'hello';
private $varName = 'hello';
}
 
class MyClass
{
function func1()
{
function func2()
{
return $a;
}
return $data;
}
}
 
class MyClass
{
public function prepare() {}
public function paint() {}
}
 
if (true) {
class MyClass
{
$varName = 'hello';
$var_name = 'hello';
}
}
 
class MyClass {
function myFunction($cc, $cv) {
$req = "delete from blah
where not (POP_{$cc}_A =
'{$this->def["POP_{$cc}_A"]}'
and POP_{$cc}_B =
'{$this->def["POP_{$cc}_B"]}')";
}
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Commenting/InlineCommentUnitTest.php
New file
0,0 → 1,72
<?php
/**
* Unit test class for the InlineComment sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: InlineCommentUnitTest.php,v 1.2 2006/12/12 02:57:38 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the InlineComment sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_Commenting_InlineCommentUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
15 => 1,
24 => 1,
25 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Commenting/FileCommentUnitTest.php
New file
0,0 → 1,98
<?php
/**
* Unit test class for FunctionCommentSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: FileCommentUnitTest.php,v 1.9 2007/11/05 03:00:12 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for FunctionCommentSniff.
*
* Verifies that :
* <ul>
* <li>A doc comment exists.</li>
* <li>Short description must start with a capital letter and end with a period.</li>
* <li>There must be one blank newline after the short description.</li>
* <li>A PHP version is specified.</li>
* <li>Check the order of the tags.</li>
* <li>Check the indentation of each tag.</li>
* <li>Check required and optional tags and the format of their content.</li>
* </ul>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_Commenting_FileCommentUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
6 => 1,
8 => 1,
21 => 2,
23 => 2,
24 => 1,
26 => 2,
27 => 1,
28 => 1,
29 => 1,
30 => 1,
31 => 2,
32 => 1,
34 => 1,
35 => 1,
36 => 1,
39 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array(
28 => 1,
29 => 1,
33 => 1,
39 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Commenting/InlineCommentUnitTest.inc
New file
0,0 → 1,27
<?php
 
// Some code goes here.
 
// This comment contains # multiple
// hash signs (#).
 
/*
* Here is a small function comment.
*/
function test()
{
// Some code goes here.
 
# This comment is banned.
 
}//end test()
 
/*
A longer comment goes here.
It spans multiple lines.
*/
 
# This is a long comment
# that is banned.
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Commenting/FileCommentUnitTest.inc
New file
0,0 → 1,48
<?php
declare(encoding='utf-8');
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
 
/**
*
* Short description for fileasdasd.
*
*
* asdasd
* long description for file (if any)
* asdasdadada
*
* PHP versio
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @category _wrong_category
* @package PHP_CodeSniffer
* @package ADDITIONAL PACKAGE TAG
* @subpackage SUBPACKAGE TAG
* @author Antônio Carlos Venâncio Júnior <foreign@character.net>
* @author Rayn Ong rong@squiz.net
* @author
* @copyright 1997~1994 The PHP Group
* @copyright 1997~1994 The PHP Group
* @license http://www.php.net/license/3_0.txt
* @see
* @see
* @version INVALID VERSION CONTENT
* @see Net_Sample::Net_Sample()
* @see Net_Other
* @deprecated asd
* @since Class available since Release 1.2.0
* @summary An unknown summary tag
*/
?>
<?php
/**
* This bit here is not qualified as file comment
*
* as it is not after the first open tag
*
*/
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Commenting/ClassCommentUnitTest.php
New file
0,0 → 1,91
<?php
/**
* Unit test class for ClassCommentSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ClassCommentUnitTest.php,v 1.12 2008/02/06 02:54:57 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for ClassCommentSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_Commenting_ClassCommentUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
4 => 1,
15 => 1,
22 => 1,
25 => 1,
28 => 1,
46 => 1,
51 => 1,
63 => 1,
65 => 2,
66 => 1,
68 => 2,
69 => 1,
70 => 1,
71 => 1,
73 => 2,
74 => 1,
76 => 1,
77 => 1,
78 => 1,
84 => 1,
92 => 1,
102 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array(
70 => 1,
72 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.php
New file
0,0 → 1,92
<?php
/**
* Unit test class for FunctionCommentSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: FunctionCommentUnitTest.php,v 1.16 2007/11/06 09:14:05 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for FunctionCommentSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PEAR_Tests_Commenting_FunctionCommentUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
10 => 1,
12 => 2,
13 => 2,
14 => 1,
15 => 1,
28 => 1,
35 => 1,
38 => 1,
41 => 1,
53 => 1,
103 => 1,
109 => 1,
112 => 1,
122 => 1,
123 => 3,
124 => 3,
125 => 5,
126 => 6,
139 => 1,
155 => 1,
165 => 1,
172 => 1,
183 => 1,
193 => 2,
204 => 1,
234 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Commenting/ClassCommentUnitTest.inc
New file
0,0 → 1,110
<?php
define('OK', 1);
 
class No_Comment
{
 
}//end class
 
 
//
// Sample class comment
//
//
//
class Invalid_Comment_Style1
{
 
}//end class
 
 
/**
*
*
* Sample class comment
*
*
* Long description with extra blank line before and after
*
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.0
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Extra_Description_Newlines
{
 
}//end class
 
 
/**
* Sample class comment
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Missing_Newlines_Before_Tags
{
 
}//end class
 
 
/**
* Simple class comment
*
* @category _wrong_category
* @package PHP_CodeSniffer
* @package ADDITIONAL PACKAGE TAG
* @subpackage SUBPACKAGE TAG
* @author Original Author <author@example.com>
* @author Rayn Ong rong@squiz.net
* @author
* @copyright 1997~1994 The PHP Group
* @license http://www.php.net/license/3_0.txt
* @version INVALID VERSION CONTENT
* @see
* @see
* @link sdfsdf
* @see Net_Sample::Net_Sample()
* @see Net_Other
* @deprecated asd
* @unknown Unknown tag
* @since Class available since Release 1.2.0
*/
class Checking_Tags
{
class Sub_Class {
 
}//end class
 
 
}//end class
 
 
/**
*
*
*/
class Empty_Class_Doc
{
 
}//end class
 
 
/**
*
*
*/
interface Empty_Interface_Doc
{
 
}//end interface
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc
New file
0,0 → 1,254
<?php
class PHP_CodeSniffer_File
{
 
/**
* A simple function comment.
*
* long desc here
*
* @param int $stackPtr The position in @ @unknown the stack of the token
* that opened the scope
* @param int $detph How many scope levels down we are.
* @param int $index The index
* @return
* @throws
*/
private function _functionCall($stackPtr, $depth=1, $index)
{
return $stackPtr;
 
}//end _functionCall()
 
//
// Sample function comment
//
//
//
public function invalidCommentStyle()
{
 
}//end invalidCommentStyle()
 
 
/**
*
*
* A simple function comment
*
*
* Long description with extra blank line before and after
*
*
* @return void
*/
public function extraDescriptionNewlines()
{
 
}//end extraDescriptionNewlines()
 
 
/**
* A simple function comment
* @return void
*/
public function missingNewlinesBeforeTags()
{
 
}//end missingNewlinesBeforeTags()
 
 
/**
* Access tag should not be treated as a long description
*
* @access public
* @return void
*/
public function accessTag()
{
 
}//end accessTag()
 
/**
* Constructor
*
* No return tag
*/
function PHP_CodeSniffer_File()
{
return;
}
 
 
/**
* Destructor
*
* No return tag too
*/
function _PHP_CodeSniffer_File()
{
return;
}
 
 
/**
* Destructor PHP5
*/
function __destruct()
{
return;
}
 
 
function missingComment()
{
return;
}
 
 
/**
* no return tag
*
*/
public function noReturn($one)
{
 
}//end noReturn()
 
 
/**
* Param not immediate
*
* @return
* @param int $threeSpaces
* @param int $superfluous
* @param missing
* @param
*/
public function missingDescroption($threeSpaces)
{
 
}//end missingDescroption()
 
 
/**
* Param not immediate
*
* @param int $one comment
* @param int $two comment
* @param string $three comment
*
* @return void
*/
public function oneSpaceAfterLongestVar($one, $two, $three)
{
 
}//end oneSpaceAfterLongestVar()
 
 
}//end class
 
 
/**
* A simple function comment
*
* @param string $str The string passed in by reference
*
* @return void
*/
public function functionOutsideClass(&$str)
{
return;
}//end functionOutsideClass()
 
 
function missingCommentOutsideClass()
{
return;
}//end missingCommentOutsideClass()
 
 
?><?php
function tagBeforeComment()
{
return;
}//end tagBeforeComment()
 
 
/**
* no return tag
*
*
*
*/
public function noReturnOutsideClass()
{
 
}//end noReturnOutsideClass()
 
 
/**
* Missing param comment
*
* @param int $one comment
*
* @return void
* @fine Unknown tag
*/
public function missingTwoParamComment($one, $two, $three)
{
 
}//end missingTwoParamComment()
 
 
/**
*
*/
function emptyFunctionDocComment()
{
}//end emptyFunctionDocComment()
 
 
/**
* Test function.
*
* @param string $arg1 An argument
*
* @access public
* @return bool
*/
function myFunction($arg1) {}
 
 
/**
* Test function.
*
* @param string $arg1 An argument
*
* @access public
* @return bool
*/
 
echo $blah;
 
function myFunction($arg1) {}
 
/**
* Test function.
*
* @access public
* @return bool
* @throws MyException
* @throws MyException When I feel like it
*/
function myFunction() {}
 
class MyClass() {
/**
* An abstract function.
*
* @return array(string)
*/
abstract final protected function myFunction();
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/AbstractScopeSniff.php
New file
0,0 → 1,239
<?php
/**
* An AbstractScopeTest allows for tests that extend from this class to
* listen for tokens within a particluar scope.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: AbstractScopeSniff.php,v 1.11 2008/12/01 05:41:28 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* An AbstractScopeTest allows for tests that extend from this class to
* listen for tokens within a particluar scope.
*
* Below is a test that listens to methods that exist only within classes:
* <code>
* class ClassScopeTest extends PHP_CodeSniffer_Standards_AbstractScopeSniff
* {
* public function __construct()
* {
* parent::__construct(array(T_CLASS), array(T_FUNCTION));
* }
*
* protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $)
* {
* $className = $phpcsFile->getDeclarationName($currScope);
* echo 'encountered a method within class '.$className;
* }
* }
* </code>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
abstract class PHP_CodeSniffer_Standards_AbstractScopeSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* The token types that this test wishes to listen to within the scope.
*
* @var array()
*/
private $_tokens = array();
 
/**
* The type of scope opener tokens that this test wishes to listen to.
*
* @var string
*/
private $_scopeTokens = array();
 
/**
* The position in the tokens array that opened the current scope.
*
* @var array()
*/
protected $currScope = null;
 
/**
* The current file being checked.
*
* @var string
*/
protected $currFile = '';
 
/**
* True if this test should fire on tokens outside of the scope.
*
* @var boolean
*/
private $_listenOutside = false;
 
 
/**
* Constructs a new AbstractScopeTest.
*
* @param array $scopeTokens The type of scope the test wishes to listen to.
* @param array $tokens The tokens that the test wishes to listen to
* within the scope.
* @param boolean $listenOutside If true this test will also alert the
* extending class when a token is found outside
* the scope, by calling the
* processTokenOutideScope method.
*
* @see PHP_CodeSniffer.getValidScopeTokeners()
* @throws PHP_CodeSniffer_Test_Exception If the specified tokens array is empty.
*/
public function __construct(
array $scopeTokens,
array $tokens,
$listenOutside=false
) {
if (empty($scopeTokens) === true) {
$error = 'The scope tokens list cannot be empty';
throw new PHP_CodeSniffer_Test_Exception($error);
}
 
if (empty($tokens) === true) {
$error = 'The tokens list cannot be empty';
throw new PHP_CodeSniffer_Test_Exception($error);
}
 
$invalidScopeTokens = array_intersect($scopeTokens, $tokens);
if (empty($invalidScopeTokens) === false) {
$invalid = implode(', ', $invalidScopeTokens);
$error = "Scope tokens [$invalid] cant be in the tokens array";
throw new PHP_CodeSniffer_Test_Exception($error);
}
 
$this->_listenOutside = $listenOutside;
$this->_scopeTokens = $scopeTokens;
$this->_tokens = $tokens;
 
}//end __construct()
 
 
/**
* The method that is called to register the tokens this test wishes to
* listen to.
*
* DO NOT OVERRIDE THIS METHOD. Use the constructor of this class to register
* for the desired tokens and scope.
*
* @return array(int)
* @see __constructor()
*/
public final function register()
{
if ($this->_listenOutside === false) {
return $this->_scopeTokens;
} else {
return array_merge($this->_scopeTokens, $this->_tokens);
}
 
}//end register()
 
 
/**
* Processes the tokens that this test is listening for.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
* @param int $stackPtr The position in the stack where this
* token was found.
*
* @return void
* @see processTokenWithinScope()
*/
public final function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$file = $phpcsFile->getFilename();
if ($this->currFile !== $file) {
// We have changed files, so clean up.
$this->currScope = null;
$this->currFile = $file;
}
 
$tokens = $phpcsFile->getTokens();
 
if (in_array($tokens[$stackPtr]['code'], $this->_scopeTokens) === true) {
$this->currScope = $stackPtr;
$phpcsFile->addTokenListener($this, $this->_tokens);
} else if ($this->currScope !== null
&& isset($tokens[$this->currScope]['scope_closer']) === true
&& $stackPtr > $tokens[$this->currScope]['scope_closer']
) {
$this->currScope = null;
if ($this->_listenOutside === true) {
// This is a token outside the current scope, so notify the
// extender as they wish to know about this.
$this->processTokenOutsideScope($phpcsFile, $stackPtr);
} else {
// Don't remove the listener if the extender wants to know about
// tokens that live outside the current scope.
$phpcsFile->removeTokenListener($this, $this->_tokens);
}
} else if ($this->currScope !== null) {
$this->processTokenWithinScope($phpcsFile, $stackPtr, $this->currScope);
} else {
$this->processTokenOutsideScope($phpcsFile, $stackPtr);
}
 
}//end process()
 
 
/**
* Processes a token that is found within the scope that this test is
* listening to.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
* @param int $stackPtr The position in the stack where this
* token was found.
* @param int $currScope The position in the tokens array that
* opened the scope that this test is
* listening for.
*
* @return void
*/
protected abstract function processTokenWithinScope(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr,
$currScope
);
 
 
/**
* Processes a token that is found within the scope that this test is
* listening to.
*
* @param PHP_CodeSniffer_File $phpcsFile The file where this token was found.
* @param int $stackPtr The position in the stack where this
* token was found.
*
* @return void
*/
protected function processTokenOutsideScope(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr
) {
return;
 
}//end processTokenOutsideScope()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/CodingStandard.php
New file
0,0 → 1,73
<?php
/**
* Bass Coding Standard class.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: CodingStandard.php,v 1.4 2008/02/01 03:19:53 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Base Coding Standard class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Standards_CodingStandard
{
 
 
/**
* Return a list of external sniffs to include with this standard.
*
* External locations can be single sniffs, a whole directory of sniffs, or
* an entire coding standard. Locations start with the standard name. For
* example:
* PEAR => include all sniffs in this standard
* PEAR/Sniffs/Files => include all sniffs in this dir
* PEAR/Sniffs/Files/LineLengthSniff => include this single sniff
*
* @return array
*/
public function getIncludedSniffs()
{
return array();
 
}//end getIncludedSniffs()
 
 
/**
* Return a list of external sniffs to exclude from this standard.
*
* External locations can be single sniffs, a whole directory of sniffs, or
* an entire coding standard. Locations start with the standard name. For
* example:
* PEAR => exclude all sniffs in this standard
* PEAR/Sniffs/Files => exclude all sniffs in this dir
* PEAR/Sniffs/Files/LineLengthSniff => exclude this single sniff
*
* @return array
*/
public function getExcludedSniffs()
{
return array();
 
}//end getExcludedSniffs()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/IncorrectPatternException.php
New file
0,0 → 1,36
<?php
/**
* An exception thrown if the pattern being processed is not supposed to be
* validating the code in question.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: IncorrectPatternException.php,v 1.2 2006/12/12 02:19:03 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* An exception thrown if the pattern being processed is not supposed to be
* validating the code in question.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Standards_IncorrectPatternException extends Exception
{
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Files/LineEndingsUnitTest.css
New file
0,0 → 1,3
#login-container {
margin-left: -225px;
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Files/LineEndingsUnitTest.inc
New file
0,0 → 1,7
<?php
echo 'hi';
?>
 
<?php
echo 'hi';
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Files/LineEndingsUnitTest.js
New file
0,0 → 1,2
alert('hi');
alert('hi');
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Files/LineLengthUnitTest.php
New file
0,0 → 1,79
<?php
/**
* Unit test class for the LineLength sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: LineLengthUnitTest.php,v 1.5 2008/06/27 01:58:38 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the LineLength sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Files_LineLengthUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
31 => 1,
34 => 1,
55 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array(
9 => 1,
15 => 1,
21 => 1,
24 => 1,
29 => 1,
37 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Files/LineLengthUnitTest.inc
New file
0,0 → 1,55
<?php
 
// This line is okay... just!
if (($reallyLongVarName === true) || (is_array($anotherLongVarName) == false)) {
// Do something.
}
 
// This line is not okay... just!
if (($reallyLongVarName === true) || (is_array($anotherLongVarName) === false)) {
// Do something.
}
 
 
// This line is is too long.
if (($anotherReallyLongVarName === true) || (is_array($anotherReallyLongVarName) === false)) {
// Do something.
}
 
// This is a really really long comment that is going to go to exactly 80 chars.
 
// This is another really really long comment that is going to go well over 80 characters.
 
// And here is just a bunch of spaces that exceeds the line length.
 
// And here are some spaces exactly 80 chars long.
 
// This is a really really really really long long comment that is going to go to exactly 100 chars.
 
// This is another really really really really really long comment that is going to go well over 100 characters.
 
// And here is just a bunch of spaces that exceeds the max line length.
 
// And here are some spaces exactly 100 chars long.
?>
<b>Hello</b>b>
<?php
echo 'hi';
?>
 
<?php
/**
* Comments contining CVS IDs can be long, but should be ignored because
* they cannot be changed by the developer. Same with license URLs.
*
* @version CVS: $Id: LineLengthUnitTest.inc,v 1.6 2008/06/27 01:58:38 squiz Exp $
* @license http://www.freebsd.org/copyright/freebsd-license.html BSD License (2 Clause)
*/
?>
 
<?php
// This is another really long comment that is going to go well over 100 characters, with no closing php tag after it.
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Files/LineEndingsUnitTest.php
New file
0,0 → 1,70
<?php
/**
* Unit test class for the LineEndings sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: LineEndingsUnitTest.php,v 1.1 2007/06/06 23:31:35 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the LineEndings sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Files_LineEndingsUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
1 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc
New file
0,0 → 1,26
<?php
 
if ($something) echo 'hello';
 
if ($something) {
echo 'hello';
} else echo 'hi';
 
if ($something) {
echo 'hello';
} else if ($else) echo 'hi';
 
foreach ($something as $thing) echo 'hello';
 
for ($i; $i > 0; $i--) echo 'hello';
 
while ($something) echo 'hello';
 
do {
$i--;
} while ($something);
 
if(true)
$someObject->{$name};
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.js
New file
0,0 → 1,21
<?php
 
if ($something) echo 'hello';
 
if ($something) {
echo 'hello';
} else echo 'hi';
 
if ($something) {
echo 'hello';
} else if ($else) echo 'hi';
 
for ($i; $i > 0; $i--) echo 'hello';
 
while ($something) echo 'hello';
 
do {
$i--;
} while ($something);
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php
New file
0,0 → 1,94
<?php
/**
* Unit test class for the InlineControlStructure sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: InlineControlStructureUnitTest.php,v 1.2 2008/07/01 01:25:08 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the InlineControlStructure sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_ControlStructures_InlineControlStructureUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
*/
public function getErrorList($testFile='InlineControlStructureUnitTest.inc')
{
switch ($testFile) {
case 'InlineControlStructureUnitTest.inc':
return array(
3 => 1,
7 => 1,
11 => 1,
13 => 1,
15 => 1,
17 => 1,
23 => 1,
);
break;
case 'InlineControlStructureUnitTest.js':
return array(
3 => 1,
7 => 1,
11 => 1,
13 => 1,
15 => 1,
);
break;
default:
return array();
break;
}//end switch
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Metrics/NestingLevelUnitTest.php
New file
0,0 → 1,73
<?php
/**
* Unit test class for the NestingLevel sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: NestingLevelUnitTest.php,v 1.1 2007/07/30 04:55:35 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the NestingLevel sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Metrics_NestingLevelUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
73 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array(
27 => 1,
46 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Metrics/NestingLevelUnitTest.inc
New file
0,0 → 1,102
<?php
 
function nestingOne()
{
if ($condition) {
echo 'hi';
}
}
 
function nestingFive()
{
if ($condition) {
echo 'hi';
switch ($condition)
{
case '1':
if ($condition === '1') {
if ($cond) {
echo 'hi';
}
}
break;
}
}
}
 
function nestingSix()
{
if ($condition) {
echo 'hi';
switch ($condition)
{
case '1':
if ($condition === '1') {
if ($cond) {
foreach ($conds as $cond) {
echo 'hi';
}
}
}
break;
}
}
}
 
function nestingTen()
{
if ($condition) {
echo 'hi';
switch ($condition)
{
case '1':
if ($condition === '1') {
if ($cond) {
switch ($cond) {
case '1':
if ($cond === '1') {
foreach ($conds as $cond) {
if ($cond === 'hi') {
echo 'hi';
}
}
}
break;
}
}
}
break;
}
}
}
 
function nestingEleven()
{
if ($condition) {
echo 'hi';
switch ($condition)
{
case '1':
if ($condition === '1') {
if ($cond) {
switch ($cond) {
case '1':
if ($cond === '1') {
foreach ($conds as $cond) {
if ($cond === 'hi') {
if ($cond !== 'bye') {
echo 'hi';
}
}
}
}
break;
}
}
}
break;
}
}
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.php
New file
0,0 → 1,73
<?php
/**
* Unit test class for the CyclomaticComplexity sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: CyclomaticComplexityUnitTest.php,v 1.1 2007/07/30 04:55:35 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the CyclomaticComplexity sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Metrics_CyclomaticComplexityUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
116 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array(
45 => 1,
72 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.inc
New file
0,0 → 1,160
<?php
 
function complexityOne() { }
 
function comlexityFive()
{
if ($condition) {
}
 
switch ($condition) {
case '1':
break;
case '2':
break;
case '3':
break;
}
}
 
function comlexityTen()
{
while ($condition === true) {
if ($condition) {
}
}
 
switch ($condition) {
case '1':
if ($condition) {
} else if ($cond) {
}
break;
case '2':
while ($cond) {
echo 'hi';
}
break;
case '3':
break;
default:
break;
}
}
 
function comlexityEleven()
{
while ($condition === true) {
if ($condition) {
} else if ($cond) {
}
}
 
switch ($condition) {
case '1':
if ($condition) {
} else if ($cond) {
}
break;
case '2':
while ($cond) {
echo 'hi';
}
break;
case '3':
break;
default:
break;
}
}
 
 
function comlexityTwenty()
{
while ($condition === true) {
if ($condition) {
} else if ($cond) {
}
}
 
switch ($condition) {
case '1':
if ($condition) {
} else if ($cond) {
}
break;
case '2':
while ($cond) {
echo 'hi';
}
break;
case '3':
switch ($cond) {
case '1':
break;
case '2':
break;
}
break;
case '4':
do {
if ($condition) {
if ($cond) {
} else if ($con) {
}
}
} while ($cond);
break;
default:
if ($condition) {
}
break;
}
}
 
 
function comlexityTwentyOne()
{
while ($condition === true) {
if ($condition) {
} else if ($cond) {
}
}
 
switch ($condition) {
case '1':
if ($condition) {
} else if ($cond) {
}
break;
case '2':
while ($cond) {
echo 'hi';
}
break;
case '3':
switch ($cond) {
case '1':
break;
case '2':
break;
}
break;
case '4':
do {
if ($condition) {
if ($cond) {
} else if ($con) {
}
}
} while ($cond);
break;
default:
if ($condition) {
} else if ($cond) {
}
break;
}
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/ForbiddenFunctionsUnitTest.inc
New file
0,0 → 1,22
<?php
$size = sizeof($array);
$size = count($array);
delete($filepath);
unset($filepath);
 
// No errors thrown for class methods.
$size = MyClass::sizeof($array);
$size = MyClass::count($array);
MyClass::delete($filepath);
MyClass::unset($filepath);
 
$size = $class->sizeof($array);
$size = $class->count($array);
$class->delete($filepath);
$class->unset($filepath);
 
function delete() {}
function unset() {}
function sizeof() {}
function count() {}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/DisallowShortOpenTagUnitTest.php
New file
0,0 → 1,77
<?php
/**
* Unit test class for the DisallowShortOpenTag sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: DisallowShortOpenTagUnitTest.php,v 1.2 2006/12/12 02:31:20 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the DisallowShortOpenTag sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_PHP_DisallowShortOpenTagUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
$option = (boolean) ini_get('short_open_tag');
 
if ($option === false) {
return array();
}
 
return array(
4 => 1,
5 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/DisallowShortOpenTagUnitTest.inc
New file
0,0 → 1,6
<div>
<?php echo $var; ?>
Some content here.
<?= $var; ?>
<? echo $var; ?>
</div>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.php
New file
0,0 → 1,102
<?php
/**
* Unit test class for the LowerCaseConstant sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: LowerCaseConstantUnitTest.php,v 1.4 2008/02/18 00:01:06 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the LowerCaseConstant sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_PHP_LowerCaseConstantUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
*/
public function getErrorList($testFile='LowerCaseConstantUnitTest.inc')
{
switch ($testFile) {
case 'LowerCaseConstantUnitTest.inc':
return array(
7 => 1,
10 => 1,
15 => 1,
16 => 1,
23 => 1,
26 => 1,
31 => 1,
32 => 1,
39 => 1,
42 => 1,
47 => 1,
48 => 1,
);
break;
case 'LowerCaseConstantUnitTest.js':
return array(
2 => 1,
3 => 1,
4 => 1,
7 => 1,
8 => 1,
12 => 1,
13 => 1,
14 => 1,
);
break;
default:
return array();
break;
}
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.inc
New file
0,0 → 1,50
<?php
 
// True
function myFunction($arg1, $arg2=true)
{
}
function myFunction($arg1, $arg2=TRUE)
{
}
function myFunction($arg1, $arg2=True)
{
}
 
if ($variable === true) { }
if ($variable === TRUE) { }
if ($variable === True) { }
 
 
// False
function myFunction($arg1, $arg2=false)
{
}
function myFunction($arg1, $arg2=FALSE)
{
}
function myFunction($arg1, $arg2=False)
{
}
 
if ($variable === false) { }
if ($variable === FALSE) { }
if ($variable === False) { }
 
 
// Null
function myFunction($arg1, $arg2=null)
{
}
function myFunction($arg1, $arg2=NULL)
{
}
function myFunction($arg1, $arg2=Null)
{
}
 
if ($variable === null) { }
if ($variable === NULL) { }
if ($variable === Null) { }
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/NoSilencedErrorsUnitTest.php
New file
0,0 → 1,68
<?php
/**
* Unit test class for the NoSilencedErrors sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: NoSilencedErrorsUnitTest.php,v 1.1 2008/12/03 04:42:07 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the NoSilencedErrors sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_PHP_NoSilencedErrorsUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array();
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array(
5 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.php
New file
0,0 → 1,81
<?php
/**
* Unit test class for the UpperCaseConstant sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: UpperCaseConstantUnitTest.php,v 1.3 2007/01/10 03:14:43 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the UpperCaseConstant sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_PHP_UpperCaseConstantUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
7 => 1,
10 => 1,
15 => 1,
16 => 1,
23 => 1,
26 => 1,
31 => 1,
32 => 1,
39 => 1,
42 => 1,
47 => 1,
48 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/NoSilencedErrorsUnitTest.inc
New file
0,0 → 1,9
<?php
/**
* @see something
*/
if (@in_array($array, $needle))
{
echo '@';
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.js
New file
0,0 → 1,14
if (variable === true) { }
if (variable === TRUE) { }
if (variable === True) { }
variable = True;
 
if (variable === false) { }
if (variable === FALSE) { }
if (variable === False) { }
variable = false;
 
if (variable === null) { }
if (variable === NULL) { }
if (variable === Null) { }
variable = NULL;
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.inc
New file
0,0 → 1,50
<?php
 
// True
function myFunction($arg1, $arg2=TRUE)
{
}
function myFunction($arg1, $arg2=true)
{
}
function myFunction($arg1, $arg2=True)
{
}
 
if ($variable === TRUE) { }
if ($variable === true) { }
if ($variable === True) { }
 
 
// False
function myFunction($arg1, $arg2=FALSE)
{
}
function myFunction($arg1, $arg2=false)
{
}
function myFunction($arg1, $arg2=False)
{
}
 
if ($variable === FALSE) { }
if ($variable === false) { }
if ($variable === False) { }
 
 
// Null
function myFunction($arg1, $arg2=NULL)
{
}
function myFunction($arg1, $arg2=null)
{
}
function myFunction($arg1, $arg2=Null)
{
}
 
if ($variable === NULL) { }
if ($variable === null) { }
if ($variable === Null) { }
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/PHP/ForbiddenFunctionsUnitTest.php
New file
0,0 → 1,71
<?php
/**
* Unit test class for the ForbiddenFunctions sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ForbiddenFunctionsUnitTest.php,v 1.1 2006/12/28 06:01:17 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ForbiddenFunctions sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_PHP_ForbiddenFunctionsUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
2 => 1,
4 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.php
New file
0,0 → 1,88
<?php
/**
* Unit test class for the OpeningFunctionBraceBsdAllman sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: OpeningFunctionBraceBsdAllmanUnitTest.php,v 1.3 2007/12/04 23:24:33 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the OpeningFunctionBraceBsdAllman sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Functions_OpeningFunctionBraceBsdAllmanUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
4 => 1,
13 => 1,
19 => 1,
24 => 1,
30 => 1,
40 => 1,
44 => 1,
50 => 1,
55 => 1,
67 => 1,
78 => 1,
85 => 1,
91 => 1,
98 => 1,
110 => 1,
115 => 1,
122 => 1,
128 => 1,
155 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Functions/OpeningFunctionBraceKernighanRitchieUnitTest.php
New file
0,0 → 1,82
<?php
/**
* Unit test class for the OpeningFunctionBraceKernighanRitchie sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: OpeningFunctionBraceKernighanRitchieUnitTest.php,v 1.3 2007/12/04 23:24:33 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the OpeningFunctionBraceKernighanRitchie sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Functions_OpeningFunctionBraceKernighanRitchieUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
9 => 1,
13 => 1,
17 => 1,
29 => 1,
33 => 1,
37 => 1,
53 => 1,
58 => 1,
63 => 1,
77 => 1,
82 => 1,
87 => 1,
104 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Functions/OpeningFunctionBraceBsdAllmanUnitTest.inc
New file
0,0 → 1,157
<?php
 
// Brace should be on new line.
function myFunction() {
}
 
// Good.
function myFunction()
{
}
 
// Too many spaces.
function myFunction() {
}
 
// Too many newlines.
function myFunction()
 
{
}
 
// Space before brace.
function myFunction()
{
}
 
class myClass()
{
// Brace should be on new line.
function myFunction() {
}
// Good.
function myFunction()
{
}
 
// No aligned correctly.
function myFunction()
{
}
// Too many spaces.
function myFunction() {
}
// Too many newlines.
function myFunction()
 
{
}
// Space before brace.
function myFunction()
{
}
}
 
 
 
/* Multi-line declarations */
 
 
 
// Brace should be on new line.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
 
// Good.
function myFunction($variable1, $variable2,
$variable3, $variable4)
{
}
 
// Too many spaces.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
 
// Too many newlines.
function myFunction($variable1, $variable2,
$variable3, $variable4)
 
{
}
 
// Space before brace.
function myFunction($variable1, $variable2,
$variable3, $variable4)
{
}
 
class myClass()
{
// Brace should be on new line.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
// Good.
function myFunction($variable1, $variable2,
$variable3, $variable4)
{
}
 
// No aligned correctly.
function myFunction($variable1, $variable2,
$variable3, $variable4)
{
}
// Too many spaces.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
// Too many newlines.
function myFunction($variable1, $variable2,
$variable3, $variable4)
 
{
}
// Space before brace.
function myFunction($variable1, $variable2,
$variable3, $variable4)
{
}
}
 
interface MyInterface()
{
function myFunction();
}
 
function myFunction(
$arg1,
$arg2,
$arg3,
$arg4,
$arg5,
$arg6
)
{
}
 
function myFunction(
$arg1,
$arg2,
$arg3,
$arg4,
$arg5,
$arg6
) {
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Functions/OpeningFunctionBraceKernighanRitchieUnitTest.inc
New file
0,0 → 1,117
<?php
 
// Good.
function myFunction() {
}
 
// Brace should be on same line.
function myFunction()
{
}
 
// Too many spaces.
function myFunction() {
}
 
// Uses tab.
function myFunction() {
}
 
 
class myClass()
{
// Good.
function myFunction() {
}
// Brace should be on same line.
function myFunction()
{
}
// Too many spaces.
function myFunction() {
}
// Uses tab.
function myFunction() {
}
}
 
 
 
/* Multi-line declarations */
 
// Good.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
 
// Brace should be on same line.
function myFunction($variable1, $variable2,
$variable3, $variable4)
{
}
 
// Too many spaces.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
 
// Uses tab.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
 
 
class myClass()
{
// Good.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
// Brace should be on same line.
function myFunction($variable1, $variable2,
$variable3, $variable4)
{
}
// Too many spaces.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
// Uses tab.
function myFunction($variable1, $variable2,
$variable3, $variable4) {
}
}
 
interface MyInterface()
{
function myFunction();
}
 
function myFunction(
$arg1,
$arg2,
$arg3,
$arg4,
$arg5,
$arg6
)
{
}
 
function myFunction(
$arg1,
$arg2,
$arg3,
$arg4,
$arg5,
$arg6
) {
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Strings/UnnecessaryStringConcatUnitTest.inc
New file
0,0 → 1,10
<?php
$x = 'My '.'string';
$x = 'My '.1234;
$x = 'My '.$y.' test';
 
echo $data['my'.'index'];
echo $data['my'.4];
echo $data['my'.$x];
echo $data[$x.$y.'My'.'String'];
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Strings/UnnecessaryStringConcatUnitTest.js
New file
0,0 → 1,11
var x = 'My ' + 'string';
var x = 'My ' + 1234;
var x = 'My ' + y + ' test';
 
this.errors['test'] = x;
this.errors['test' + 10] = x;
this.errors['test' + y] = x;
this.errors['test' + 'blah'] = x;
this.errors[y] = x;
this.errors[y + z] = x;
this.errors[y + z + 'My' + 'String'] = x;
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Strings/UnnecessaryStringConcatUnitTest.php
New file
0,0 → 1,86
<?php
/**
* Unit test class for the UnnecessaryStringConcat sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: UnnecessaryStringConcatUnitTest.php,v 1.1 2008/12/05 04:39:00 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the UnnecessaryStringConcat sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Strings_UnnecessaryStringConcatUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
*/
public function getErrorList($testFile='UnnecessaryStringConcatUnitTest.inc')
{
switch ($testFile) {
case 'UnnecessaryStringConcatUnitTest.inc':
return array(
2 => 1,
6 => 1,
9 => 1,
);
break;
case 'UnnecessaryStringConcatUnitTest.js':
return array(
1 => 1,
8 => 1,
11 => 1,
);
break;
default:
return array();
break;
}
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.php
New file
0,0 → 1,135
<?php
/**
* Unit test class for the MultipleStatementAlignment sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: MultipleStatementAlignmentUnitTest.php,v 1.9 2008/02/21 05:21:12 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the MultipleStatementAlignment sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Formatting_MultipleStatementAlignmentUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array();
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
*/
public function getWarningList($testFile='MultipleStatementAlignmentUnitTest.inc')
{
switch ($testFile) {
case 'MultipleStatementAlignmentUnitTest.inc':
return array(
11 => 1,
12 => 1,
23 => 1,
24 => 1,
26 => 1,
27 => 1,
37 => 1,
38 => 1,
48 => 1,
50 => 1,
61 => 1,
62 => 1,
64 => 1,
65 => 1,
71 => 1,
78 => 1,
79 => 1,
86 => 1,
92 => 1,
93 => 1,
94 => 1,
95 => 1,
123 => 1,
124 => 1,
126 => 1,
129 => 1,
154 => 1,
161 => 1,
178 => 1,
179 => 1,
182 => 1,
);
break;
case 'MultipleStatementAlignmentUnitTest.js':
return array(
11 => 1,
12 => 1,
23 => 1,
24 => 1,
26 => 1,
27 => 1,
37 => 1,
38 => 1,
48 => 1,
50 => 1,
61 => 1,
62 => 1,
64 => 1,
65 => 1,
71 => 1,
78 => 1,
79 => 1,
81 => 1,
82 => 1,
83 => 1,
85 => 1,
86 => 1,
);
break;
default:
return array();
break;
}
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc
New file
0,0 → 1,198
<?php
 
// Valid
$var1 = 'var1';
$var10 = 'var1';
$var100 = 'var1';
$var1000 = 'var1';
 
// Invalid
$var1 = 'var1';
$var10 = 'var1';
$var100 = 'var1';
$var1000 = 'var1';
 
// Valid
$var1 = 'var1';
$var10 = 'var1';
 
$var100 = 'var1';
$var1000 = 'var1';
 
// Invalid
$var1 = 'var1';
$var10 = 'var1';
 
$var100 = 'var1';
$var1000 = 'var1';
 
// Valid
$var1 .= 'var1';
$var10 .= 'var1';
$var100 .= 'var1';
$var1000 .= 'var1';
 
// Invalid
$var1 .= 'var1';
$var10 .= 'var1';
$var100 .= 'var1';
$var1000 .= 'var1';
 
// Valid
$var1 = 'var1';
$var10 .= 'var1';
$var100 = 'var1';
$var1000 .= 'var1';
 
// Invalid
$var1 = 'var1';
$var10 .= 'var1';
$var100 = 'var1';
$var1000 .= 'var1';
 
// Valid
$var1 .= 'var1';
$var10 .= 'var1';
 
$var100 .= 'var1';
$var1000 .= 'var1';
 
// Invalid
$var1 .= 'var1';
$var10 .= 'var1';
 
$var100 .= 'var1';
$var1000 .= 'var1';
 
// Valid
$var = 100;
 
// InValid
$var = 100;
 
$commentStart = $phpcsFile->findPrevious();
$commentEnd = $this->_phpcsFile;
$expected .= '...';
 
// Invalid
$this->okButton = new Button();
$content = new MyClass();
 
 
$GLOBALS['_PEAR_ERRORSTACK_SINGLETON'] = array();
 
class MyClass
{
const MODE_DEBUG = 'debug';
const MODE_DEBUG2 = 'debug';
 
$array[$test] = 'anything';
$var = 'anything';
 
const MODE_DEBUG2 = 'debug';
$array[$test] = 'anything';
$var = 'anything';
$array[($test + 1)] = 'anything';
$array[($blah + (10 - $test))] = 'anything';
}
 
function myFunction($var=true)
{
if ($strict === true) {
$length = strlen($string);
$lastCharWasCaps = ($classFormat === false) ? false : true;
 
for ($i = 1; $i < $length; $i++) {
$isCaps = (strtoupper($string{$i}) === $string{$i}) ? true : false;
if ($isCaps === true && $lastCharWasCaps === true) {
return false;
}
 
$lastCharWasCaps = $isCaps;
}
}
}
 
// Valid
for ($i = 0; $i < 10; $i += 2) {
$i = ($i - 1);
}
 
// Invalid
foreach ($files as $file) {
$saves[$file] = array();
$contents = stripslashes(file_get_contents($file));
list($assetid, $time, $content) = explode("\n", $contents);
$saves[$file]['assetid'] = $assetid;
}
 
$i = ($i - 10);
$ip = ($i - 10);
for ($i = 0; $i < 10; $i += 2) {
$i = ($i - 10);
}
 
// Valid
$variable = 12;
$var = a_very(long_line('that', 'contains'),
a_bunch('of long', 'parameters'),
'that_need to be aligned with the equal sign');
$var2 = 12;
 
// Valid
$variable = 12;
$var = 'a very long line of text that contains '
.$someVar
.' and some other stuff that is too long to fit on one line';
$var2 = 12;
 
// Invalid
$variable = 12;
$var = a_very(long_line('that', 'contains'),
a_bunch('of long', 'parameters'),
'that_need to be aligned with the equal sign');
$var2 = 12;
 
// Invalid
$variable = 12;
$var = 'a very long line of text that contains '
.$someVar
.' and some other stuff that is too long to fit on one line';
$var2 = 12;
 
// Valid
$variable = 12;
$var .= 'a very long line of text that contains '
.$someVar
.' and some other stuff that is too long to fit on one line';
$var2 = 12;
 
// Valid
$variable += 12;
$var .= 'a very long line of text that contains '
.$someVar
.' and some other stuff that is too long to fit on one line';
$var2 = 12;
 
// Invalid
$variable = 12;
$var .= 'a very long line of text that contains '
.$someVar
.' and some other stuff that is too long to fit on one line';
$var2 = 12;
 
// Valid
$error = false;
while (list($h, $f) = each($handle)) {
$error = true;
}
 
// Valid
$value = false;
function blah ($value = true) {
$value = false;
if ($value === true) {
$value = false;
}
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/DisallowMultipleStatementsUnitTest.php
New file
0,0 → 1,73
<?php
/**
* Unit test class for the DisallowMultipleStatements sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: DisallowMultipleStatementsUnitTest.php,v 1.1 2008/06/24 06:37:54 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the DisallowMultipleStatements sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Formatting_DisallowMultipleStatementsUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
2 => 1,
6 => 1,
7 => 1,
8 => 2,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/DisallowMultipleStatementsUnitTest.inc
New file
0,0 → 1,9
<?php
$y = 2;;
echo $y;
for ($i = 1; $i < $length; $i++) {}
for (; $i < $length; $i++) {}
echo 'x'; echo $y;
$x = 10; echo $y;
$this->wizardid = 10; $this->paint(); echo 'x';
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.js
New file
0,0 → 1,93
 
 
// Valid
var1 = 'var1';
var10 = 'var1';
var100 = 'var1';
var1000 = 'var1';
 
// Invalid
var1 = 'var1';
var10 = 'var1';
var100 = 'var1';
var1000 = 'var1';
 
// Valid
var1 = 'var1';
var10 = 'var1';
 
var100 = 'var1';
var1000 = 'var1';
 
// Invalid
var1 = 'var1';
var10 = 'var1';
 
var100 = 'var1';
var1000 = 'var1';
 
// Valid
var1 += 'var1';
var10 += 'var1';
var100 += 'var1';
var1000 += 'var1';
 
// Invalid
var1 += 'var1';
var10 += 'var1';
var100 += 'var1';
var1000 += 'var1';
 
// Valid
var1 = 'var1';
var10 += 'var1';
var100 = 'var1';
var1000 += 'var1';
 
// Invalid
var1 = 'var1';
var10 += 'var1';
var100 = 'var1';
var1000 += 'var1';
 
// Valid
var1 += 'var1';
var10 += 'var1';
 
var100 += 'var1';
var1000 += 'var1';
 
// Invalid
var1 += 'var1';
var10 += 'var1';
 
var100 += 'var1';
var1000 += 'var1';
 
// Valid
var test = 100;
 
// InValid
var test = 100;
 
commentStart = phpcsFile.findPrevious();
commentEnd = this._phpcsFile;
expected += '...';
 
// Invalid
this.okButton = {};
content = {};
 
var buttonid = [this.id, '-positionFormats-add'].join('');
var buttonWidget = WidgetStore.get(buttonid);
var spinButtonid = [this.id, '-positionFormats-spinButton'].join('');
var spinButtonWidget = WidgetStore.get(spinButtonid);
var position = spinButtonWidget.getValue();
var posForamatsList = WidgetStore.get([self.id, '-positionFormats-list'].join(''));
 
dfx.stripTags = function(content, allowedTags)
{
var match;
var re = 'blah';
};
 
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/NoSpaceAfterCastUnitTest.php
New file
0,0 → 1,91
<?php
/**
* Unit test class for the NoSpaceAfterCast sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: NoSpaceAfterCastUnitTest.php,v 1.1 2007/06/29 00:57:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the NoSpaceAfterCast sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Formatting_NoSpaceAfterCastUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
3 => 1,
5 => 1,
7 => 1,
9 => 1,
11 => 1,
13 => 1,
15 => 1,
17 => 1,
19 => 1,
21 => 1,
23 => 1,
25 => 1,
27 => 1,
29 => 1,
31 => 1,
33 => 1,
35 => 1,
37 => 1,
39 => 1,
41 => 1,
43 => 1,
45 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/NoSpaceAfterCastUnitTest.inc
New file
0,0 → 1,47
<?php
 
$var = (int) $var2;
$var = (int)$var2;
$var = (int) $var2;
 
$var = (integer) $var2;
$var = (integer)$var2;
$var = (integer) $var2;
 
$var = (string) $var2;
$var = (string)$var2;
$var = (string) $var2;
 
$var = (float) $var2;
$var = (float)$var2;
$var = (float) $var2;
 
$var = (double) $var2;
$var = (double)$var2;
$var = (double) $var2;
 
$var = (real) $var2;
$var = (real)$var2;
$var = (real) $var2;
 
$var = (array) $var2;
$var = (array)$var2;
$var = (array) $var2;
 
$var = (bool) $var2;
$var = (bool)$var2;
$var = (bool) $var2;
 
$var = (boolean) $var2;
$var = (boolean)$var2;
$var = (boolean) $var2;
 
$var = (object) $var2;
$var = (object)$var2;
$var = (object) $var2;
 
$var = (unset) $var2;
$var = (unset)$var2;
$var = (unset) $var2;
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.php
New file
0,0 → 1,91
<?php
/**
* Unit test class for the SpaceAfterCast sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: SpaceAfterCastUnitTest.php,v 1.1 2007/06/29 00:57:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the SpaceAfterCast sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Formatting_SpaceAfterCastUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
4 => 1,
5 => 1,
8 => 1,
9 => 1,
12 => 1,
13 => 1,
16 => 1,
17 => 1,
20 => 1,
21 => 1,
24 => 1,
25 => 1,
28 => 1,
29 => 1,
32 => 1,
33 => 1,
36 => 1,
37 => 1,
40 => 1,
41 => 1,
44 => 1,
45 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.inc
New file
0,0 → 1,47
<?php
 
$var = (int) $var2;
$var = (int)$var2;
$var = (int) $var2;
 
$var = (integer) $var2;
$var = (integer)$var2;
$var = (integer) $var2;
 
$var = (string) $var2;
$var = (string)$var2;
$var = (string) $var2;
 
$var = (float) $var2;
$var = (float)$var2;
$var = (float) $var2;
 
$var = (double) $var2;
$var = (double)$var2;
$var = (double) $var2;
 
$var = (real) $var2;
$var = (real)$var2;
$var = (real) $var2;
 
$var = (array) $var2;
$var = (array)$var2;
$var = (array) $var2;
 
$var = (bool) $var2;
$var = (bool)$var2;
$var = (bool) $var2;
 
$var = (boolean) $var2;
$var = (boolean)$var2;
$var = (boolean) $var2;
 
$var = (object) $var2;
$var = (object)$var2;
$var = (object) $var2;
 
$var = (unset) $var2;
$var = (unset)$var2;
$var = (unset) $var2;
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.php
New file
0,0 → 1,92
<?php
/**
* Unit test class for the DisallowTabIndent sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: DisallowTabIndentUnitTest.php,v 1.4 2008/10/28 04:43:57 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the DisallowTabIndent sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_WhiteSpace_DisallowTabIndentUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
*/
public function getErrorList($testFile='DisallowTabIndentUnitTest.inc')
{
switch ($testFile) {
case 'DisallowTabIndentUnitTest.inc':
return array(
5 => 1,
9 => 1,
15 => 1,
);
break;
case 'DisallowTabIndentUnitTest.js':
return array(
3 => 1,
6 => 1,
);
break;
case 'DisallowTabIndentUnitTest.css':
return array(
2 => 1,
);
break;
default:
return array();
break;
}//end switch
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.css
New file
0,0 → 1,4
#login-container {
margin-left: -225px;
width: 450px;
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.inc
New file
0,0 → 1,17
<?php
 
class ExampleClass
{
function exampleFunction() {}
 
}
 
$o = <<<EOF
this is some text
this is some text
EOF;
 
$correctVar = true;
$correctVar = false;
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php
New file
0,0 → 1,88
<?php
/**
* Unit test class for the ScopeIndent sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ScopeIndentUnitTest.php,v 1.5 2007/06/07 06:04:30 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ScopeIndent sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_WhiteSpace_ScopeIndentUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
7 => 1,
10 => 1,
17 => 1,
20 => 1,
24 => 1,
27 => 1,
28 => 1,
58 => 1,
123 => 1,
126 => 1,
224 => 1,
225 => 1,
279 => 1,
280 => 1,
281 => 1,
282 => 1,
283 => 1,
284 => 1,
311 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/WhiteSpace/DisallowTabIndentUnitTest.js
New file
0,0 → 1,9
var x = {
abc: 1,
zyz: 2,
abc: 5,
mno: {
abc: 4
},
abc: 5
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.inc
New file
0,0 → 1,329
<?php
 
class Test
{
function __construct()
{
$this->hello(); // error here
}
 
function hello() // error here
{ // no error here as brackets can be put anywhere in the pear standard
echo 'hello';
}
 
function hello2()
{
if (TRUE) { // error here
echo 'hello'; // no error here as its more than 4 spaces.
} else {
echo 'bye'; // error here
}
 
while (TRUE) {
echo 'hello'; // error here
}// no error here as its handled by another test.
 
do { // error here
echo 'hello'; // error here
} while (TRUE); // no error here as its aligned with the do.
}// no error here as its handled by another test.
 
function hello3()
{
switch ($hello) {
case 'hello':
break;
}
}
 
}
 
?>
<pre>
</head>
<body>
<?php
if ($form->validate()) {
$safe = $form->getSubmitValues();
}
?>
</pre>
<?php
 
class Test2
{
function __construct()
{
// $this->open(); // error here
}
 
public function open()
{
// Some inline stuff that shouldn't error
if (TRUE) echo 'hello';
foreach ($tokens as $token) echo $token;
}
 
/**
* This is a comment 1.
* This is a comment 2.
* This is a comment 3.
* This is a comment 4.
*/
public function close()
{
// All ok.
if (TRUE) {
if (TRUE) {
} else if (FALSE) {
foreach ($tokens as $token) {
switch ($token) {
case '1':
case '2':
if (true) {
if (false) {
if (false) {
if (false) {
echo 'hello';
}
}
}
}
break;
case '5':
break;
}
do {
while (true) {
foreach ($tokens as $token) {
for ($i = 0; $i < $token; $i++) {
echo 'hello';
}
}
}
} while (true);
}
}
}
}
 
/*
This is another c style comment 1.
This is another c style comment 2.
This is another c style comment 3.
This is another c style comment 4.
This is another c style comment 5.
*/
 
/*
*
*
*
*/
 
/**
*/
 
/*
This comment has a newline in it.
 
*/
 
public function read()
{
echo 'hello';
 
// no errors below.
$array = array(
'this',
'that' => array(
'hello',
'hello again' => array(
'hello',
),
),
);
}
}
 
abstract class Test3
{
public function parse()
{
 
foreach ($t as $ndx => $token) {
if (is_array($token)) {
echo 'here';
} else {
$ts[] = array("token" => $token, "value" => '');
 
$last = count($ts) - 1;
 
switch ($token) {
case '(':
 
if ($last >= 3 &&
$ts[0]['token'] != T_CLASS &&
$ts[$last - 2]['token'] == T_OBJECT_OPERATOR &&
$ts[$last - 3]['token'] == T_VARIABLE ) {
 
 
if (true) {
echo 'hello';
}
}
array_push($braces, $token);
break;
}
}
}
}
}
 
public function test()
{
$o = <<<EOF
this is some text
this is some text
this is some text
this is some text
this is some text
this is some text
EOF;
 
return $o;
}
 
if ($a === true || $a === true || $a === true || $a === true ||
$a === true || $a === true || $a === true || $a === true) {
 
echo 'hello';
}
 
if ($true) {
/* First comment line
*
* Comment test here
* Comment test here
*
*/
/* First comment line
*
* Comment test here
* Comment test here
*
this si something */
}
 
function test()
{
/* taken from http://de3.php.net/manual/en/reserved.php */
# $m[] = 'declare';
/* taken from http://de3.php.net/manual/en/reserved.php */
# $m[] = 'declare';
}
 
foreach ($elements as $element) {
if ($something) {
// Do IF.
} else if ($somethingElse) {
// Do ELSE.
}
}
 
if ($condition) {
echo "This is a long
string that spans $numLines lines
without indenting.
";
}
 
if ($condition) {
echo 'This is a long
string that spans nultiple lines
with indenting.
';
}
 
if ($condition) {
echo 'This is a long
string that spans nultiple lines
with indenting.';
}
 
switch ($foo) {
case 1:
switch ($bar) {
default:
echo $string{1};
}
break;
}
 
function temp($foo, $bar) {
switch ($foo) {
case 1:
switch ($bar) {
default:
return $foo;
}
break;
}
}
 
switch ($foo) {
case 1:
switch ($bar) {
default:
if ($something) {
echo $string{1};
} else if ($else) {
switch ($else) {
default:
}
}
}
break;
}
 
switch ($name) {
case "1":
case "2":
case "3":
return true;
}
 
switch ($name) {
case "1":
case "2":
case "3":
default :
return true;
}
 
function myFunction()
{
?>
<dynamic_content>
 
</dynamic_content>
<?php
 
}
 
switch ($name) {
case "1":
switch ($name2) {
case "1":
break;
case "2":
break;
}
break;
case "2":
break;
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.php
New file
0,0 → 1,82
<?php
/**
* Unit test class for the DuplicateClassName multi-file sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: DuplicateClassNameUnitTest.php,v 1.1 2008/07/25 04:24:10 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the DuplicateClassName multi-file sniff.
*
* A multi-file sniff unit test checks a .1.inc and a .2.inc file for expected violations
* of a single coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Classes_DuplicateClassNameUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array();
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList($testFile='')
{
switch ($testFile) {
case 'DuplicateClassNameUnitTest.1.inc':
return array(
6 => 1,
7 => 1,
);
break;
case 'DuplicateClassNameUnitTest.2.inc':
return array(
2 => 1,
3 => 1,
);
break;
default:
return array();
break;
}//end switch
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.1.inc
New file
0,0 → 1,8
<?php
class MyClass {}
class YourClass {}
interface MyInterface {}
interface YourInterface {}
class MyClass {}
interface MyInterface {}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.2.inc
New file
0,0 → 1,4
<?php
class MyClass {}
interface MyInterface {}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.php
New file
0,0 → 1,70
<?php
/**
* Unit test class for the UselessOverridingMethod sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: UselessOverridingMethodUnitTest.php,v 1.1 2008/02/06 02:38:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the UselessOverridingMethod sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_CodeAnalysis_UselessOverridingMethodUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array();
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array(
4 => 1,
16 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/ForLoopWithTestFunctionCallUnitTest.php
New file
0,0 → 1,70
<?php
/**
* Unit test class for the ForLoopWithTestFunctionCall sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: ForLoopWithTestFunctionCallUnitTest.php,v 1.1 2008/02/06 02:38:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ForLoopWithTestFunctionCall sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_CodeAnalysis_ForLoopWithTestFunctionCallUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array();
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array(
4 => 1,
13 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/JumbledIncrementerUnitTest.php
New file
0,0 → 1,71
<?php
/**
* Unit test class for the JumbledIncrementer sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: JumbledIncrementerUnitTest.php,v 1.1 2008/02/06 02:38:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the JumbledIncrementer sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_CodeAnalysis_JumbledIncrementerUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array();
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array(
3 => 2,
4 => 1,
20 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/EmptyStatementUnitTest.php
New file
0,0 → 1,81
<?php
/**
* Unit test class for the EmptyStatement sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: EmptyStatementUnitTest.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the EmptyStatement sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_CodeAnalysis_EmptyStatementUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
64 => 1,
68 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array(
3 => 1,
15 => 1,
17 => 1,
19 => 1,
30 => 1,
35 => 1,
41 => 1,
47 => 1,
52 => 1,
55 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/UnnecessaryFinalModifierUnitTest.php
New file
0,0 → 1,71
<?php
/**
* Unit test class for the UnnecessaryFinalModifier sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: UnnecessaryFinalModifierUnitTest.php,v 1.1 2008/02/06 02:38:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the UnnecessaryFinalModifier sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_CodeAnalysis_UnnecessaryFinalModifierUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array();
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array(
11 => 1,
14 => 1,
17 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/ForLoopShouldBeWhileLoopUnitTest.php
New file
0,0 → 1,70
<?php
/**
* Unit test class for the ForLoopShouldBeWhileLoop sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: ForLoopShouldBeWhileLoopUnitTest.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ForLoopShouldBeWhileLoop sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_CodeAnalysis_ForLoopShouldBeWhileLoopUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array();
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array(
6 => 1,
10 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/UnconditionalIfStatementUnitTest.inc
New file
0,0 → 1,13
<?php
 
if (true) {
 
} else if (false) {
} elseif (true) {
}
 
if (file_exists(__FILE__) === true) {
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/UnusedFunctionParameterUnitTest.inc
New file
0,0 → 1,27
<?php
 
function foo($a, $b) {
return $a * 2;
}
 
function baz($a, $b) {
echo "baz({$a});";
}
 
function bar($a, $b) {
$x = $b;
for ($i = 0; $i <$a; $i++) {
$x += $a * $i;
}
return $x;
}
 
function foobar($a, &$b) {
return (preg_match('/foo/', $a, $b) !== 0);
}
 
class Foo {
function barfoo($a, $b) {
// Empty body means interface method in many cases.
}
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.inc
New file
0,0 → 1,25
<?php
 
class FooBar {
public function __construct($a, $b) {
parent::__construct($a, $b);
}
}
 
class BarFoo {
public function __construct($a, $b) {
parent::__construct($a, 'XML', $b);
}
}
 
class Foo {
public function export($a, $b = null) {
return parent::export($a, $b);
}
}
 
class Bar {
public function export($a, $b = null) {
return parent::export($a);
}
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/ForLoopWithTestFunctionCallUnitTest.inc
New file
0,0 → 1,15
<?php
 
$a = array(1, 2, 3, 4);
for ($i = 0; $i < count($a); $i++) {
$a[$i] *= $i;
}
 
for ($i = 0, $c = sizeof($a); $i < $c; ++$i) {
$a[$i] *= $i;
}
 
$it = new ArrayIterator($a);
for ($it->rewind(); $it->valid(); $it->next()) {
echo $it->current();
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/JumbledIncrementerUnitTest.inc
New file
0,0 → 1,25
<?php
 
for ($i = 0; $i < 20; $i++) {
for ($j = 0; $j < 5; $i += 2) {
for ($k = 0; $k > 3; $i++) {
}
}
}
 
for ($i = 0; $i < 20; $i++) {
for ($j = 0; $j < 5; $j += 2) {
for ($k = 0; $k > 3; $k++) {
}
}
}
 
for ($i = 0; $i < 20; $i++) {
for ($j = 0; $j < 5; $j += 2) {
for ($k = 0; $k > 3; $j++) {
}
}
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/EmptyStatementUnitTest.inc
New file
0,0 → 1,70
<?php
 
switch ($foo) {
// Empty switch statement body
}
 
switch ($foo) {
case 'bar':
break;
default:
break;
}
 
 
if ($foo) {
// Just a comment
} elseif ($bar) {
// Yet another comment
} else {
}
 
if ($foo) {
$foo = 'bar';
} else if ($bar) {
$bar = 'foo';
}
 
for ($i = 0; $i < 10; $i++) {
for ($j = 0; $j < 10; $j++) {
// Just a comment
}
}
 
foreach ($foo as $bar) {}
 
foreach ($foo as $bar) {
$bar *= 2;
}
 
do {
// Just a comment
// Just another comment
} while ($foo);
 
do {
while ($bar) {
}
} while (true);
 
while ($foo) { /* Comment in the same line */ }
 
while ($foo) {
try {
} catch (Exception $e) {
echo $e->getTraceAsString();
}
}
 
try {
throw Exception('Error...');
} catch (Exception $e) {}
 
try {
throw Exception('Error...');
} catch (Exception $e) {
// TODO: Handle this exception later :-)
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/UnconditionalIfStatementUnitTest.php
New file
0,0 → 1,71
<?php
/**
* Unit test class for the UnconditionalIfStatement sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: UnconditionalIfStatementUnitTest.php,v 1.1 2008/02/06 02:38:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the UnconditionalIfStatement sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_CodeAnalysis_UnconditionalIfStatementUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array();
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array(
3 => 1,
5 => 1,
7 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/UnnecessaryFinalModifierUnitTest.inc
New file
0,0 → 1,24
<?php
 
class Foo {
public final $FOOBAR = 23;
protected final $FOO = 42;
private final $BAR = 17;
}
 
final class Foo_Bar {
public $foobar;
public final $FOOBAR = 23;
protected $foo;
protected final $FOO = 42;
private $bar;
private final $BAR = 17;
}
 
final class Bar_Foo {
public $foobar;
protected $foo;
private $bar;
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/UnusedFunctionParameterUnitTest.php
New file
0,0 → 1,70
<?php
/**
* Unit test class for the UnusedFunctionParameter sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: UnusedFunctionParameterUnitTest.php,v 1.1 2008/02/06 02:38:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the UnusedFunctionParameter sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_CodeAnalysis_UnusedFunctionParameterUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array();
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array(
3 => 1,
7 => 1,
);
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/CodeAnalysis/ForLoopShouldBeWhileLoopUnitTest.inc
New file
0,0 → 1,13
<?php
for ($i = 0; $i < 10; $i++) {
// Everything is fine
}
 
for (; $it->valid();) {
$it->next();
}
 
for (;(($it1->valid() && $foo) || (!$it2->value && ($bar || false)));/*Could be ingored*/) {
$it1->next();
$it2->next();
}
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/NamingConventions/UpperCaseConstantNameUnitTest.php
New file
0,0 → 1,79
<?php
/**
* Unit test class for the ValidConstantName sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: UpperCaseConstantNameUnitTest.php,v 1.3 2007/01/10 03:14:43 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ValidConstantName sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_NamingConventions_UpperCaseConstantNameUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
4 => 1,
6 => 1,
11 => 1,
21 => 1,
22 => 1,
23 => 1,
24 => 1,
25 => 1,
28 => 1,
31 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/NamingConventions/UpperCaseConstantNameUnitTest.inc
New file
0,0 → 1,83
<?php
 
define('VALID_NAME', true);
define('invalidName', true);
define("VALID_NAME", true);
define("invalidName", true);
 
class TestClass extends MyClass, YourClass
{
 
const const1 = 'hello';
const CONST2 = 'hello';
 
function test()
{
echo constant('VALID_NAME');
echo VALID_NAME;
print VALID_NAME;
echo(VALID_NAME);
print(VALID_NAME);
echo constant('invalidName');
echo invalidName;
print invalidName;
echo(invalidName);
print(invalidName);
 
echo constant("VALID_NAME");
echo constant("invalidName");
 
echo 'Hello', VALID_NAME;
echo 'Hello', invalidName;
 
// These might look like constants to
// poorly written code.
echo 'Hello there';
echo "HELLO";
echo 'HELLO';
print 'Hello there';
print "HELLO";
print 'HELLO';
}
 
function myFunc(PHP_CodeSniffer &$blah) {}
function myFunc(PHP_CodeSniffer $blah) {}
 
}
 
interface MyInterface
{
}
 
if (($object instanceof Some_Class) === false) {
$var = <<<EOF
This is some heredoc text.
This is some heredoc text.
This is some heredoc text.
 
This is some heredoc text.
This is some heredoc text.
This is some heredoc text.
EOF;
}
 
$var = <<<EOF
This is some heredoc text.
This is some heredoc text.
This is some heredoc text.
 
This is some heredoc text.
This is some heredoc text.
This is some heredoc text.
EOF;
 
throw new InvalidSomethingException;
 
declare(ticks = 1) {
foreach ($var as $bit) {
echo $bit;
}
}
 
$binary = (binary) $string;
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.php
New file
0,0 → 1,71
<?php
/**
* Unit test class for the ConstructorName sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ConstructorNameUnitTest.php,v 1.1 2009/02/23 05:16:22 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the ConstructorName sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_NamingConventions_ConstructorNameUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @return array(int => int)
*/
public function getErrorList()
{
return array(
5 => 1,
6 => 1,
11 => 1,
20 => 1,
);
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @return array(int => int)
*/
public function getWarningList()
{
return array();
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.inc
New file
0,0 → 1,31
<?php
class TestClass extends MyClass
{
 
function TestClass() {
parent::MyClass();
parent::__construct();
}
 
function __construct() {
parent::MyClass();
parent::__construct();
}
 
}
 
class MyClass
{
 
function MyClass() {
parent::YourClass();
parent::__construct();
}
 
function __construct() {
parent::YourClass();
parent::__construct();
}
 
}
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Commenting/TodoUnitTest.php
New file
0,0 → 1,98
<?php
/**
* Unit test class for the Todo sniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: TodoUnitTest.php,v 1.2 2008/08/19 05:26:35 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Unit test class for the Todo sniff.
*
* A sniff unit test checks a .inc file for expected violations of a single
* coding standard. Expected errors and warnings are stored in this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Tests_Commenting_TodoUnitTest extends AbstractSniffUnitTest
{
 
 
/**
* Returns the lines where errors should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of errors that should occur on that line.
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
*/
public function getErrorList($testFile='TodoUnitTest.inc')
{
return array();
 
}//end getErrorList()
 
 
/**
* Returns the lines where warnings should occur.
*
* The key of the array should represent the line number and the value
* should represent the number of warnings that should occur on that line.
*
* @param string $testFile The name of the file being tested.
*
* @return array(int => int)
*/
public function getWarningList($testFile='TodoUnitTest.inc')
{
switch ($testFile) {
case 'TodoUnitTest.inc':
return array(
3 => 1,
7 => 1,
10 => 1,
13 => 1,
16 => 1,
18 => 1,
21 => 1,
);
break;
case 'TodoUnitTest.js':
return array(
3 => 1,
7 => 1,
10 => 1,
13 => 1,
16 => 1,
18 => 1,
21 => 1,
);
break;
default:
return array();
break;
}//end switch
 
}//end getWarningList()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Commenting/TodoUnitTest.inc
New file
0,0 → 1,22
<?php
/**
* TODO: Write this comment
*
*/
 
// TODO: remove this.
error_log('test');
 
// TODO remove this.
Debug::bam('test');
 
// todo - remove this.
 
// Extract info from the array.
// TODO: can this be done faster?
 
// Extract info from the array (todo: make it faster)
// To do this, use a function!
// notodo! NOTODO! NOtodo!
//TODO.
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Tests/Commenting/TodoUnitTest.js
New file
0,0 → 1,22
<?php
/**
* TODO: Write this comment
*
*/
 
// TODO: remove this.
alert('test');
 
// TODO remove this.
alert('test');
 
// todo - remove this.
 
// Extract info from the array.
// TODO: can this be done faster?
 
// Extract info from the array (todo: make it faster)
// To do this, use a function!
// notodo! NOTODO! NOtodo!
//TODO.
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/GenericCodingStandard.php
New file
0,0 → 1,39
<?php
/**
* Generic Coding Standard.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: GenericCodingStandard.php,v 1.5 2008/02/01 03:19:54 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_Standards_CodingStandard', true) === false) {
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_CodingStandard not found');
}
 
/**
* Generic Coding Standard.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Standards_Generic_GenericCodingStandard extends PHP_CodeSniffer_Standards_CodingStandard
{
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Docs/PHP/DisallowShortOpenTagStandard.xml
New file
0,0 → 1,7
<documentation title="PHP Code Tags">
<standard>
<![CDATA[
Always use <?php ?> to delimit PHP code, not the <? ?> shorthand. This is the most portable way to include PHP code on differing operating systems and setups.
]]>
</standard>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Docs/PHP/LowerCaseConstantStandard.xml
New file
0,0 → 1,23
<documentation title="PHP Constants">
<standard>
<![CDATA[
The <em>true</em>, <em>false</em> and <em>null</em> constants must always be lowercase.
]]>
</standard>
<code_comparison>
<code title="Valid: lowercase constants">
<![CDATA[
if ($var === <em>false</em> || $var === <em>null</em>) {
$var = <em>true</em>;
}
]]>
</code>
<code title="Invalid: uppercase constants">
<![CDATA[
if ($var === <em>FALSE</em> || $var === <em>NULL</em>) {
$var = <em>TRUE</em>;
}
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Docs/PHP/UpperCaseConstantStandard.xml
New file
0,0 → 1,23
<documentation title="PHP Constants">
<standard>
<![CDATA[
The <em>true</em>, <em>false</em> and <em>null</em> constants must always be uppercase.
]]>
</standard>
<code_comparison>
<code title="Valid: uppercase constants">
<![CDATA[
if ($var === <em>FALSE</em> || $var === <em>NULL</em>) {
$var = <em>TRUE</em>;
}
]]>
</code>
<code title="Invalid: lowercase constants">
<![CDATA[
if ($var === <em>false</em> || $var === <em>null</em>) {
$var = <em>true</em>;
}
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Docs/Functions/OpeningFunctionBraceBsdAllmanStandard.xml
New file
0,0 → 1,24
<documentation title="Opening Brace in Function Declarations">
<standard>
<![CDATA[
Function declarations follow the "BSD/Allman style". The function brace is on the line following the function declaration and is indented to the same column as the start of the function declaration.
]]>
</standard>
<code_comparison>
<code title="Valid: brace on next line">
<![CDATA[
function fooFunction($arg1, $arg2 = '')
<em>{</em>
...
}
]]>
</code>
<code title="Invalid: brace on same line">
<![CDATA[
function fooFunction($arg1, $arg2 = '') <em>{</em>
...
}
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Docs/Functions/OpeningFunctionBraceKernighanRitchieStandard.xml
New file
0,0 → 1,24
<documentation title="Opening Brace in Function Declarations">
<standard>
<![CDATA[
Function declarations follow the "Kernighan/Ritchie style". The function brace is on the same line as the function declaration. One space is required between the closing parenthesis and the brace.
]]>
</standard>
<code_comparison>
<code title="Valid: brace on same line">
<![CDATA[
function fooFunction($arg1, $arg2 = '')<em> {</em>
...
}
]]>
</code>
<code title="Invalid: brace on next line">
<![CDATA[
function fooFunction($arg1, $arg2 = '')
<em>{</em>
...
}
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Docs/Formatting/MultipleStatementAlignmentStandard.xml
New file
0,0 → 1,56
<documentation title="Aligning Blocks of Assignments">
<standard>
<![CDATA[
There should be one space on either side of an equals sign used to assign a value to a variable. In the case of a block of related assignments, more space may be inserted to promote readability.
]]>
</standard>
<code_comparison>
<code title="Equals signs aligned">
<![CDATA[
$shortVar <em>=</em> (1 + 2);
$veryLongVarName <em>=</em> 'string';
$var <em>=</em> foo($bar, $baz, $quux);
]]>
</code>
<code title="Not aligned; harder to read">
<![CDATA[
$shortVar <em>=</em> (1 + 2);
$veryLongVarName <em>=</em> 'string';
$var <em>=</em> foo($bar, $baz, $quux);
]]>
</code>
</code_comparison>
<standard>
<![CDATA[
When using plus-equals, minus-equals etc. still ensure the equals signs are aligned to one space after the longest variable name.
]]>
</standard>
<code_comparison>
<code title="Equals signs aligned; only one space after longest var name">
<![CDATA[
$shortVar <em>+= </em>1;
$veryLongVarName<em> = </em>1;
]]>
</code>
<code title="Two spaces after longest var name">
<![CDATA[
$shortVar <em> += </em>1;
$veryLongVarName<em> = </em>1;
]]>
</code>
</code_comparison>
<code_comparison>
<code title="Equals signs aligned">
<![CDATA[
$shortVar <em> = </em>1;
$veryLongVarName<em> -= </em>1;
]]>
</code>
<code title="Equals signs not aligned">
<![CDATA[
$shortVar <em> = </em>1;
$veryLongVarName<em> -= </em>1;
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Docs/NamingConventions/UpperCaseConstantNameStandard.xml
New file
0,0 → 1,29
<documentation title="Constant Names">
<standard>
<![CDATA[
Constants should always be all-uppercase, with underscores to separate words.
]]>
</standard>
<code_comparison>
<code title="Valid: all uppercase">
<![CDATA[
define('<em>FOO_CONSTANT</em>', 'foo');
 
class FooClass
{
const <em>FOO_CONSTANT</em> = 'foo';
}
]]>
</code>
<code title="Invalid: mixed case">
<![CDATA[
define('<em>Foo_Constant</em>', 'foo');
 
class FooClass
{
const <em>foo_constant</em> = 'foo';
}
]]>
</code>
</code_comparison>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Docs/Files/LineLengthStandard.xml
New file
0,0 → 1,7
<documentation title="Line Length">
<standard>
<![CDATA[
It is recommended to keep lines at approximately 80 characters long for better code readability.
]]>
</standard>
</documentation>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Commenting/TodoSniff.php
New file
0,0 → 1,88
<?php
/**
* Generic_Sniffs_Commenting_TodoSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: TodoSniff.php,v 1.3 2008/12/02 02:38:34 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Commenting_TodoSniff.
*
* Warns about TODO comments.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Commenting_TodoSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
);
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return PHP_CodeSniffer_Tokens::$commentTokens;
 
}//end register()
 
 
/**
* Processes this sniff, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
$content = $tokens[$stackPtr]['content'];
$matches = Array();
if (preg_match('|[^a-z]+todo[^a-z]+(.*)|i', $content, $matches) !== 0) {
// Clear whitespace and some common characters not required at
// the end of a to-do message to make the warning more informative.
$todoMessage = trim($matches[1]);
$todoMessage = trim($todoMessage, '[]().');
$error = 'Comment refers to a TODO task';
if ($todoMessage !== '') {
$error .= " \"$todoMessage\"";
}
 
$phpcsFile->addWarning($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Files/LineEndingsSniff.php
New file
0,0 → 1,99
<?php
/**
* Generic_Sniffs_Files_LineEndingsSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: LineEndingsSniff.php,v 1.4 2008/10/28 04:42:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Files_LineEndingsSniff.
*
* Checks that end of line characters are correct.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Files_LineEndingsSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
'CSS',
);
 
/**
* The valid EOL character.
*
* @var string
*/
protected $eolChar = "\n";
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_OPEN_TAG);
 
}//end register()
 
 
/**
* Processes this sniff, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
// We are only interested if this is the first open tag.
if ($stackPtr !== 0) {
if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
return;
}
}
 
if ($phpcsFile->eolChar !== $this->eolChar) {
$expected = $this->eolChar;
$expected = str_replace("\n", '\n', $expected);
$expected = str_replace("\r", '\r', $expected);
$found = $phpcsFile->eolChar;
$found = str_replace("\n", '\n', $found);
$found = str_replace("\r", '\r', $found);
$error = "End of line character is invalid; expected \"$expected\" but found \"$found\"";
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Files/LineLengthSniff.php
New file
0,0 → 1,134
<?php
/**
* Generic_Sniffs_Files_LineLengthSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: LineLengthSniff.php,v 1.16 2008/06/27 01:58:38 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Files_LineLengthSniff.
*
* Checks all lines in the file, and throws warnings if they are over 80
* characters in length and errors if they are over 100. Both these
* figures can be changed by extending this sniff in your own standard.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Files_LineLengthSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* The limit that the length of a line should not exceed.
*
* @var int
*/
protected $lineLimit = 80;
 
/**
* The limit that the length of a line must not exceed.
*
* Set to zero (0) to disable.
*
* @var int
*/
protected $absoluteLineLimit = 100;
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_OPEN_TAG);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
// Make sure this is the first open tag.
$previousOpenTag = $phpcsFile->findPrevious(array(T_OPEN_TAG), ($stackPtr - 1));
if ($previousOpenTag !== false) {
return;
}
 
$tokenCount = 0;
$currentLineContent = '';
$currentLine = 1;
 
for (; $tokenCount < $phpcsFile->numTokens; $tokenCount++) {
if ($tokens[$tokenCount]['line'] === $currentLine) {
$currentLineContent .= $tokens[$tokenCount]['content'];
} else {
$currentLineContent = trim($currentLineContent, $phpcsFile->eolChar);
$this->checkLineLength($phpcsFile, ($tokenCount - 1), $currentLineContent);
$currentLineContent = $tokens[$tokenCount]['content'];
$currentLine++;
}
}
 
$this->checkLineLength($phpcsFile, ($tokenCount - 1), $currentLineContent);
 
}//end process()
 
 
/**
* Checks if a line is too long.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The token at the end of the line.
* @param string $lineContent The content of the line.
*
* @return void
*/
protected function checkLineLength(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $lineContent)
{
// If the content is a CVS or SVN id in a version tag, or it is
// a license tag with a name and URL, there is nothing the
// developer can do to shorten the line, so don't throw errors.
if (preg_match('|@version[^\$]+\$Id|', $lineContent) === 0 && preg_match('|@license|', $lineContent) === 0) {
$lineLength = strlen($lineContent);
if ($this->absoluteLineLimit > 0 && $lineLength > $this->absoluteLineLimit) {
$error = 'Line exceeds maximum limit of '.$this->absoluteLineLimit." characters; contains $lineLength characters";
$phpcsFile->addError($error, $stackPtr);
} else if ($lineLength > $this->lineLimit) {
$warning = 'Line exceeds '.$this->lineLimit." characters; contains $lineLength characters";
$phpcsFile->addWarning($warning, $stackPtr);
}
}
 
}//end checkLineLength()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php
New file
0,0 → 1,120
<?php
/**
* Generic_Sniffs_ControlStructures_InlineControlStructureSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: InlineControlStructureSniff.php,v 1.1 2008/05/01 00:49:31 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_ControlStructures_InlineControlStructureSniff.
*
* Verifies that inline control statements are not present.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_ControlStructures_InlineControlStructureSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
);
 
/**
* If true, an error will be thrown; otherwise a warning.
*
* @var bool
*/
protected $error = true;
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_IF,
T_ELSE,
T_FOREACH,
T_WHILE,
T_DO,
T_SWITCH,
T_FOR,
);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
// Ignore the ELSE in ELSE IF. We'll process the IF part later.
if (($tokens[$stackPtr]['code'] === T_ELSE) && ($tokens[($stackPtr + 2)]['code'] === T_IF)) {
return;
}
 
if ($tokens[$stackPtr]['code'] === T_WHILE) {
// This could be from a DO WHILE, which doesn't have an opening brace.
$lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) {
$brace = $tokens[$lastContent];
if (isset($brace['scope_condition']) === true) {
$condition = $tokens[$brace['scope_condition']];
if ($condition['code'] === T_DO) {
return;
}
}
}
}
 
// This is a control structure without an opening brace,
// so it is an inline statement.
if ($this->error === true) {
$phpcsFile->addError('Inline control structures are not allowed', $stackPtr);
} else {
$phpcsFile->addWarning('Inline control structures are discouraged', $stackPtr);
}
 
return;
}//end if
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php
New file
0,0 → 1,124
<?php
/**
* Checks the cyclomatic complexity (McCabe) for functions.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: CyclomaticComplexitySniff.php,v 1.1 2007/07/30 04:55:35 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Checks the cyclomatic complexity (McCabe) for functions.
*
* The cyclomatic complexity (also called McCabe code metrics)
* indicates the complexity within a function by counting
* the different paths the function includes.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Johann-Peter Hartmann <hartmann@mayflower.de>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2007 Mayflower GmbH
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Metrics_CyclomaticComplexitySniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A complexity higher than this value will throw a warning.
*
* @var int
*/
protected $complexity = 10;
 
/**
* A complexity higer than this value will throw an error.
*
* @var int
*/
protected $absoluteComplexity = 20;
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_FUNCTION);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$this->currentFile = $phpcsFile;
 
$tokens = $phpcsFile->getTokens();
 
// Ignore abstract methods.
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
return;
}
 
// Detect start and end of this function definition.
$start = $tokens[$stackPtr]['scope_opener'];
$end = $tokens[$stackPtr]['scope_closer'];
 
// Predicate nodes for PHP.
$find = array(
'T_CASE',
'T_DEFAULT',
'T_CATCH',
'T_IF',
'T_FOR',
'T_FOREACH',
'T_WHILE',
'T_DO',
'T_ELSEIF',
);
 
$complexity = 1;
 
// Iterate from start to end and count predicate nodes.
for ($i = ($start + 1); $i < $end; $i++) {
if (in_array($tokens[$i]['type'], $find) === true) {
$complexity++;
}
}
 
if ($complexity > $this->absoluteComplexity) {
$error = "Function's cyclomatic complexity ($complexity) exceeds allowed maximum of ".$this->absoluteComplexity;
$phpcsFile->addError($error, $stackPtr);
} else if ($complexity > $this->complexity) {
$warning = "Function's cyclomatic complexity ($complexity) exceeds ".$this->complexity.'; consider refactoring the function';
$phpcsFile->addWarning($warning, $stackPtr);
}
 
return;
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Metrics/NestingLevelSniff.php
New file
0,0 → 1,107
<?php
/**
* Checks the nesting level for methods.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: NestingLevelSniff.php,v 1.1 2007/07/30 04:55:35 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Checks the nesting level for methods.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Johann-Peter Hartmann <hartmann@mayflower.de>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2007 Mayflower GmbH
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Metrics_NestingLevelSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A nesting level than this value will throw a warning.
*
* @var int
*/
protected $nestingLevel = 5;
 
/**
* A nesting level than this value will throw an error.
*
* @var int
*/
protected $absoluteNestingLevel = 10;
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_FUNCTION);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
// Ignore abstract methods.
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
return;
}
 
// Detect start and end of this function definition.
$start = $tokens[$stackPtr]['scope_opener'];
$end = $tokens[$stackPtr]['scope_closer'];
 
$nestingLevel = 0;
 
// Find the maximum nesting level of any token in the function.
for ($i = ($start + 1); $i < $end; $i++) {
$level = $tokens[$i]['level'];
if ($nestingLevel < $level) {
$nestingLevel = $level;
}
}
 
// We subtract the nesting level of the function itself.
$nestingLevel = ($nestingLevel - $tokens[$stackPtr]['level'] - 1);
 
if ($nestingLevel > $this->absoluteNestingLevel) {
$error = "Function's nesting level ($nestingLevel) exceeds allowed maximum of ".$this->absoluteNestingLevel;
$phpcsFile->addError($error, $stackPtr);
} else if ($nestingLevel > $this->nestingLevel) {
$warning = "Function's nesting level ($nestingLevel) exceeds ".$this->nestingLevel.'; consider refactoring the function';
$phpcsFile->addWarning($warning, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/VersionControl/SubversionPropertiesSniff.php
New file
0,0 → 1,169
<?php
/**
* Generic_Sniffs_VersionControl_SubversionPropertiesSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Jack Bates <ms419@freezone.co.uk>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: SubversionPropertiesSniff.php,v 1.1 2009/01/05 01:07:47 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_VersionControl_SubversionPropertiesSniff.
*
* Tests that the correct Subversion properties are set.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Jack Bates <ms419@freezone.co.uk>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_VersionControl_SubversionPropertiesSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* The Subversion properties that should be set.
*
* @var array
*/
protected $properties = array(
'svn:keywords' => 'Author Id Revision',
'svn:eol-style' => 'native',
);
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_OPEN_TAG,
);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
// Make sure this is the first PHP open tag so we don't process the
// same file twice.
$prevOpenTag = $phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1));
if ($prevOpenTag !== false) {
return;
}
 
$path = $phpcsFile->getFileName();
$properties = $this->properties($path);
 
foreach (($properties + $this->properties) as $key => $value) {
if (isset($properties[$key]) === true
&& isset($this->properties[$key]) === false
) {
$error = 'Unexpected Subversion property "'.$key.'" = "'.$properties[$key].'"';
$phpcsFile->addError($error, $stackPtr);
continue;
}
 
if (isset($properties[$key]) === false
&& isset($this->properties[$key]) === true
) {
$error = 'Missing Subversion property "'.$key.'" = "'.$this->properties[$key].'"';
$phpcsFile->addError($error, $stackPtr);
continue;
}
 
if ($properties[$key] !== $this->properties[$key]) {
$error = 'Subversion property "'.$key.'" = "'.$properties[$key].'" does not match "'.$this->properties[$key].'"';
$phpcsFile->addError($error, $stackPtr);
}
}
 
}//end process()
 
 
/**
* Returns the Subversion properties which are actually set on a path.
*
* @param string $path The path to return Subversion properties on.
*
* @return array
* @throws PHP_CodeSniffer_Exception If Subversion properties file could
* not be opened.
*/
protected function properties($path)
{
$properties = array();
 
$paths = array();
$paths[] = dirname($path).'/.svn/props/'.basename($path).'.svn-work';
$paths[] = dirname($path).'/.svn/prop-base/'.basename($path).'.svn-base';
 
foreach ($paths as $path) {
if (true === file_exists($path)) {
if (false === $handle = fopen($path, 'r')) {
$error = 'Error opening file; could not get Subversion properties';
throw new PHP_CodeSniffer_Exception($error);
}
 
while (!feof($handle)) {
 
// Read a key length line. Might be END, though.
$buffer = fgets($handle);
 
// Check for the end of the hash.
if ("END\n" === $buffer) {
break;
}
 
// Now read that much into a buffer.
$key = fread($handle, substr($buffer, 2));
 
// Suck up extra newline after key data.
fgetc($handle);
 
// Read a value length line.
$buffer = fgets($handle);
 
// Now read that much into a buffer.
$value = fread($handle, substr($buffer, 2));
 
// Suck up extra newline after value data.
fgetc($handle);
 
$properties[$key] = $value;
}//end while
 
fclose($handle);
}//end if
}//end foreach
 
return $properties;
 
}//end properties()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/PHP/DisallowShortOpenTagSniff.php
New file
0,0 → 1,91
<?php
/**
* Generic_Sniffs_PHP_DisallowShortOpenTagSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: DisallowShortOpenTagSniff.php,v 1.8 2008/12/03 04:42:41 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_PHP_DisallowShortOpenTagSniff.
*
* Makes sure that shorthand PHP open tags are not used.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_PHP_DisallowShortOpenTagSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_OPEN_TAG,
T_OPEN_TAG_WITH_ECHO,
);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
// If short open tags are off, then any short open tags will be converted
// to inline_html tags so we can just ignore them.
// If its on, then we want to ban the use of them.
$option = ini_get('short_open_tag');
 
// Ini_get returns a string "0" if short open tags is off.
if ($option === '0') {
return;
}
 
$tokens = $phpcsFile->getTokens();
$openTag = $tokens[$stackPtr];
 
if ($openTag['content'] === '<?') {
$error = 'Short PHP opening tag used. Found "'.$openTag['content'].'" Expected "<?php".';
$phpcsFile->addError($error, $stackPtr);
}
 
if ($openTag['code'] === T_OPEN_TAG_WITH_ECHO) {
$nextVar = $tokens[$phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true)];
$error = 'Short PHP opening tag used with echo. Found "';
$error .= $openTag['content'].' '.$nextVar['content'].' ..." but expected "<?php echo '.$nextVar['content'].' ...".';
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/PHP/LowerCaseConstantSniff.php
New file
0,0 → 1,84
<?php
/**
* Generic_Sniffs_PHP_LowerCaseConstantSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: LowerCaseConstantSniff.php,v 1.8 2008/02/18 00:01:06 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_PHP_LowerCaseConstantSniff.
*
* Checks that all uses of true, false and null are lowerrcase.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_PHP_LowerCaseConstantSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
);
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_TRUE,
T_FALSE,
T_NULL,
);
 
}//end register()
 
 
/**
* Processes this sniff, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
$keyword = $tokens[$stackPtr]['content'];
if (strtolower($keyword) !== $keyword) {
$error = 'TRUE, FALSE and NULL must be lowercase; expected "'.strtolower($keyword).'" but found "'.$keyword.'"';
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/PHP/NoSilencedErrorsSniff.php
New file
0,0 → 1,82
<?php
/**
* Generic_Sniffs_PHP_NoSilencedErrorsSniff
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Andy Brockhurst <abrock@yahoo-inc.com>
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: NoSilencedErrorsSniff.php,v 1.1 2008/12/03 04:42:07 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_PHP_NoSilencedErrorsSniff.
*
* Throws an error or warning when any code prefixed with an asperand is encountered.
*
* <code>
* if (@in_array($array, $needle))
* {
* doSomething();
* }
* </code>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Andy Brockhurst <abrock@yahoo-inc.com>
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_PHP_NoSilencedErrorsSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* If true, an error will be thrown; otherwise a warning.
*
* @var bool
*/
protected $error = false;
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_ASPERAND);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$error = 'Silencing errors is ';
if ($this->error === true) {
$error .= 'forbidden';
$phpcsFile->addError($error, $stackPtr);
} else {
$error .= 'discouraged';
$phpcsFile->addWarning($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/PHP/UpperCaseConstantSniff.php
New file
0,0 → 1,75
<?php
/**
* Generic_Sniffs_PHP_UpperCaseConstantSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: UpperCaseConstantSniff.php,v 1.8 2008/02/18 00:01:06 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_PHP_UpperCaseConstantSniff.
*
* Checks that all uses of TRUE, FALSE and NULL are uppercase.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_PHP_UpperCaseConstantSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_TRUE,
T_FALSE,
T_NULL,
);
 
}//end register()
 
 
/**
* Processes this sniff, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
$keyword = $tokens[$stackPtr]['content'];
if (strtoupper($keyword) !== $keyword) {
$error = 'TRUE, FALSE and NULL must be uppercase; expected "'.strtoupper($keyword).'" but found "'.$keyword.'"';
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/PHP/ForbiddenFunctionsSniff.php
New file
0,0 → 1,115
<?php
/**
* Generic_Sniffs_PHP_ForbiddenFunctionsSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ForbiddenFunctionsSniff.php,v 1.7 2008/08/19 06:35:37 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_PHP_ForbiddenFunctionsSniff.
*
* Discourages the use of alias functions that are kept in PHP for compatibility
* with older versions. Can be used to forbid the use of any function.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_PHP_ForbiddenFunctionsSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A list of forbidden functions with their alternatives.
*
* The value is NULL if no alternative exists. IE, the
* function should just not be used.
*
* @var array(string => string|null)
*/
protected $forbiddenFunctions = array(
'sizeof' => 'count',
'delete' => 'unset',
);
 
/**
* If true, an error will be thrown; otherwise a warning.
*
* @var bool
*/
protected $error = true;
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_STRING);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
$prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
if (in_array($tokens[$prevToken]['code'], array(T_DOUBLE_COLON, T_OBJECT_OPERATOR, T_FUNCTION)) === true) {
// Not a call to a PHP function.
return;
}
 
$function = strtolower($tokens[$stackPtr]['content']);
 
if (in_array($function, array_keys($this->forbiddenFunctions)) === false) {
return;
}
 
$error = "The use of function $function() is ";
if ($this->error === true) {
$error .= 'forbidden';
} else {
$error .= 'discouraged';
}
 
if ($this->forbiddenFunctions[$function] !== null) {
$error .= '; use '.$this->forbiddenFunctions[$function].'() instead';
}
 
if ($this->error === true) {
$phpcsFile->addError($error, $stackPtr);
} else {
$phpcsFile->addWarning($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php
New file
0,0 → 1,122
<?php
/**
* Generic_Sniffs_Methods_OpeningMethodBraceBsdAllmanSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: OpeningFunctionBraceBsdAllmanSniff.php,v 1.8 2008/05/05 03:59:12 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff.
*
* Checks that the opening brace of a function is on the line after the
* function declaration.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return void
*/
public function register()
{
return array(T_FUNCTION);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
return;
}
 
$openingBrace = $tokens[$stackPtr]['scope_opener'];
 
// The end of the function occurs at the end of the argument list. Its
// like this because some people like to break long function declarations
// over multiple lines.
$functionLine = $tokens[$tokens[$stackPtr]['parenthesis_closer']]['line'];
$braceLine = $tokens[$openingBrace]['line'];
 
$lineDifference = ($braceLine - $functionLine);
 
if ($lineDifference === 0) {
$error = 'Opening brace should be on a new line';
$phpcsFile->addError($error, $openingBrace);
return;
}
 
if ($lineDifference > 1) {
$ender = 'line';
if (($lineDifference - 1) !== 1) {
$ender .= 's';
}
 
$error = 'Opening brace should be on the line after the declaration; found '.($lineDifference - 1).' blank '.$ender;
$phpcsFile->addError($error, $openingBrace);
return;
}
 
// We need to actually find the first piece of content on this line,
// as if this is a method with tokens before it (public, static etc)
// or an if with an else before it, then we need to start the scope
// checking from there, rather than the current token.
$lineStart = $stackPtr;
while (($lineStart = $phpcsFile->findPrevious(array(T_WHITESPACE), ($lineStart - 1), null, false)) !== false) {
if (strpos($tokens[$lineStart]['content'], $phpcsFile->eolChar) !== false) {
break;
}
}
 
// We found a new line, now go forward and find the first non-whitespace
// token.
$lineStart = $phpcsFile->findNext(array(T_WHITESPACE), $lineStart, null, true);
 
// The opening brace is on the correct line, now it needs to be
// checked to be correctly indented.
$startColumn = $tokens[$lineStart]['column'];
$braceIndent = $tokens[$openingBrace]['column'];
 
if ($braceIndent !== $startColumn) {
$error = 'Opening brace indented incorrectly; expected '.($startColumn - 1).' spaces, found '.($braceIndent - 1);
$phpcsFile->addError($error, $openingBrace);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceKernighanRitchieSniff.php
New file
0,0 → 1,108
<?php
/**
* Generic_Sniffs_Functions_OpeningFunctionBraceKernighanRitchieSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: OpeningFunctionBraceKernighanRitchieSniff.php,v 1.5 2008/05/05 03:59:12 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Functions_OpeningFunctionBraceKernighanRitchieSniff.
*
* Checks that the opening brace of a function is on the same line
* as the function declaration.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Functions_OpeningFunctionBraceKernighanRitchieSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return void
*/
public function register()
{
return array(T_FUNCTION);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
return;
}
 
$openingBrace = $tokens[$stackPtr]['scope_opener'];
 
// The end of the function occurs at the end of the argument list. Its
// like this because some people like to break long function declarations
// over multiple lines.
$functionLine = $tokens[$tokens[$stackPtr]['parenthesis_closer']]['line'];
$braceLine = $tokens[$openingBrace]['line'];
 
$lineDifference = ($braceLine - $functionLine);
 
if ($lineDifference > 0) {
$error = 'Opening brace should be on the same line as the declaration';
$phpcsFile->addError($error, $openingBrace);
return;
}
 
// Checks that the closing parenthesis and the opening brace are
// separated by a whitespace character.
$closerColumn = $tokens[$tokens[$stackPtr]['parenthesis_closer']]['column'];
$braceColumn = $tokens[$openingBrace]['column'];
 
$columnDifference = ($braceColumn - $closerColumn);
 
if ($columnDifference !== 2) {
$error = 'Expected 1 space between the closing parenthesis and the opening brace; found '.($columnDifference - 1).'.';
$phpcsFile->addError($error, $openingBrace);
return;
}
 
// Check that a tab was not used instead of a space.
$spaceTokenPtr = ($tokens[$stackPtr]['parenthesis_closer'] + 1);
$spaceContent = $tokens[$spaceTokenPtr]['content'];
if ($spaceContent !== ' ') {
$error = 'Expected a single space character between closing parenthesis and opening brace; found "'.$spaceContent.'".';
$phpcsFile->addError($error, $openingBrace);
return;
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Strings/UnnecessaryStringConcatSniff.php
New file
0,0 → 1,112
<?php
/**
* Generic_Sniffs_Strings_UnnecessaryStringConcatSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: UnnecessaryStringConcatSniff.php,v 1.1 2008/12/05 04:39:00 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Strings_UnnecessaryStringConcatSniff.
*
* Checks that two strings are not concatenated together; suggests
* using one string instead.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Strings_UnnecessaryStringConcatSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
);
 
/**
* If true, an error will be thrown; otherwise a warning.
*
* @var bool
*/
protected $error = true;
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_STRING_CONCAT,
T_PLUS,
);
 
}//end register()
 
 
/**
* Processes this sniff, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
// Work out which type of file this is for.
$tokens = $phpcsFile->getTokens();
if ($tokens[$stackPtr]['code'] === T_STRING_CONCAT) {
if ($phpcsFile->tokenizerType === 'JS') {
return;
}
} else {
if ($phpcsFile->tokenizerType === 'PHP') {
return;
}
}
 
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
$next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
if ($prev === false || $next === false) {
return;
}
 
$stringTokens = PHP_CodeSniffer_Tokens::$stringTokens;
if (in_array($tokens[$prev]['code'], $stringTokens) === true
&& in_array($tokens[$next]['code'], $stringTokens) === true
) {
$error = 'String concat is not required here; use a single string instead';
if ($this->error === true) {
$phpcsFile->addError($error, $stackPtr);
} else {
$phpcsFile->addWarning($error, $stackPtr);
}
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Formatting/NoSpaceAfterCastSniff.php
New file
0,0 → 1,70
<?php
/**
* Generic_Sniffs_Formatting_NoSpaceAfterCastSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: NoSpaceAfterCastSniff.php,v 1.2 2007/07/23 01:47:52 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Formatting_NoSpaceAfterCastSniff.
*
* Ensures there is no space after cast tokens.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Formatting_NoSpaceAfterCastSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return PHP_CodeSniffer_Tokens::$castTokens;
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in
* the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) {
$error = 'A cast statement must not be followed by a space';
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Formatting/SpaceAfterCastSniff.php
New file
0,0 → 1,76
<?php
/**
* Generic_Sniffs_Formatting_SpaceAfterCastSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: SpaceAfterCastSniff.php,v 1.2 2007/07/23 01:47:52 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Formatting_SpaceAfterCastSniff.
*
* Ensures there is a single space after cast tokens.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Formatting_SpaceAfterCastSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return PHP_CodeSniffer_Tokens::$castTokens;
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in
* the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
$error = 'A cast statement must be followed by a single space';
$phpcsFile->addError($error, $stackPtr);
return;
}
 
if ($tokens[($stackPtr + 1)]['content'] !== ' ') {
$error = 'A cast statement must be followed by a single space';
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php
New file
0,0 → 1,287
<?php
/**
* Generic_Sniffs_Formatting_MultipleStatementAlignmentSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: MultipleStatementAlignmentSniff.php,v 1.23 2008/12/02 02:38:34 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Formatting_MultipleStatementAlignmentSniff.
*
* Checks alignment of assignments. If there are multiple adjacent assignments,
* it will check that the equals signs of each assignment are aligned. It will
* display a warning to advise that the signs should be aligned.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Formatting_MultipleStatementAlignmentSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
);
 
/**
* If true, an error will be thrown; otherwise a warning.
*
* @var bool
*/
protected $error = false;
 
/**
* The maximum amount of padding before the alignment is ignored.
*
* If the amount of padding required to align this assignment with the
* surrounding assignments exceeds this number, the assignment will be
* ignored and no errors or warnings will be thrown.
*
* @var int
*/
protected $maxPadding = 1000;
 
/**
* If true, multi-line assignments are not checked.
*
* @var int
*/
protected $ignoreMultiLine = false;
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return PHP_CodeSniffer_Tokens::$assignmentTokens;
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
// Ignore assignments used in a condition, like an IF or FOR.
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
foreach ($tokens[$stackPtr]['nested_parenthesis'] as $start => $end) {
if (isset($tokens[$start]['parenthesis_owner']) === true) {
return;
}
}
}
 
/*
By this stage, it is known that there is an assignment on this line.
We only want to process the block once we reach the last assignment,
so we need to determine if there are more to follow.
*/
 
// The assignment may span over multiple lines, so look for the
// end of the assignment so we can check assignment blocks correctly.
$lineEnd = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1));
 
$nextAssign = $phpcsFile->findNext(
PHP_CodeSniffer_Tokens::$assignmentTokens,
($lineEnd + 1)
);
 
if ($nextAssign !== false) {
$isAssign = true;
if ($tokens[$nextAssign]['line'] === ($tokens[$lineEnd]['line'] + 1)) {
// Assignment may be in the same block as this one. Just make sure
// it is not used in a condition, like an IF or FOR.
if (isset($tokens[$nextAssign]['nested_parenthesis']) === true) {
foreach ($tokens[$nextAssign]['nested_parenthesis'] as $start => $end) {
if (isset($tokens[$start]['parenthesis_owner']) === true) {
// Not an assignment.
$isAssign = false;
break;
}
}
}
 
if ($isAssign === true) {
return;
}
}
}
 
// Getting here means that this is the last in a block of statements.
$assignments = array();
$assignments[] = $stackPtr;
$prevAssignment = $stackPtr;
$lastLine = $tokens[$stackPtr]['line'];
 
while (($prevAssignment = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$assignmentTokens, ($prevAssignment - 1))) !== false) {
 
// The assignment's end token must be on the line directly
// above the current one to be in the same assignment block.
$lineEnd = $phpcsFile->findNext(T_SEMICOLON, ($prevAssignment + 1));
 
// And the end token must actually belong to this assignment.
$nextOpener = $phpcsFile->findNext(
PHP_CodeSniffer_Tokens::$scopeOpeners,
($prevAssignment + 1)
);
 
if ($nextOpener !== false && $nextOpener < $lineEnd) {
break;
}
 
if ($tokens[$lineEnd]['line'] !== ($lastLine - 1)) {
break;
}
 
// Make sure it is not assigned inside a condition (eg. IF, FOR).
if (isset($tokens[$prevAssignment]['nested_parenthesis']) === true) {
foreach ($tokens[$prevAssignment]['nested_parenthesis'] as $start => $end) {
if (isset($tokens[$start]['parenthesis_owner']) === true) {
break(2);
}
}
}
 
$assignments[] = $prevAssignment;
$lastLine = $tokens[$prevAssignment]['line'];
}//end while
 
$assignmentData = array();
$maxAssignmentLength = 0;
$maxVariableLength = 0;
 
foreach ($assignments as $assignment) {
$prev = $phpcsFile->findPrevious(
PHP_CodeSniffer_Tokens::$emptyTokens,
($assignment - 1),
null,
true
);
 
$endColumn = $tokens[($prev + 1)]['column'];
 
if ($maxVariableLength < $endColumn) {
$maxVariableLength = $endColumn;
}
 
if ($maxAssignmentLength < strlen($tokens[$assignment]['content'])) {
$maxAssignmentLength = strlen($tokens[$assignment]['content']);
}
 
$assignmentData[$assignment]
= array(
'variable_length' => $endColumn,
'assignment_length' => strlen($tokens[$assignment]['content']),
);
}//end foreach
 
foreach ($assignmentData as $assignment => $data) {
if ($data['assignment_length'] === $maxAssignmentLength) {
if ($data['variable_length'] === $maxVariableLength) {
// The assignment is the longest possible, so the column that
// everything has to align to is based on it.
$column = ($maxVariableLength + 1);
break;
} else {
// The assignment token is the longest out of all of the
// assignments, but the variable name is not, so the column
// the start at can go back more to cover the space
// between the variable name and the assigment operator.
$column = ($maxVariableLength - ($maxAssignmentLength - 1) + 1);
}
}
}
 
// Determine the actual position that each equals sign should be in.
foreach ($assignments as $assignment) {
// Actual column takes into account the length of the assignment operator.
$actualColumn = ($column + $maxAssignmentLength - strlen($tokens[$assignment]['content']));
if ($tokens[$assignment]['column'] !== $actualColumn) {
$prev = $phpcsFile->findPrevious(
PHP_CodeSniffer_Tokens::$emptyTokens,
($assignment - 1),
null,
true
);
 
$expected = ($actualColumn - $tokens[($prev + 1)]['column']);
 
if ($tokens[$assignment]['line'] !== $tokens[$prev]['line']) {
// Instead of working out how many spaces there are
// across new lines, the error message becomes more
// generic below.
$found = null;
} else {
$found = ($tokens[$assignment]['column'] - $tokens[($prev + 1)]['column']);
}
 
// If the expected number of spaces for alignment exceeds the
// maxPadding rule, we can ignore this assignment.
if ($expected > $this->maxPadding) {
continue;
}
 
// Skip multi-line assignments if required.
if ($found === null && $this->ignoreMultiLine === true) {
continue;
}
 
$expected .= ($expected === 1) ? ' space' : ' spaces';
if ($found === null) {
$found = 'a new line';
} else {
$found .= ($found === 1) ? ' space' : ' spaces';
}
 
if (count($assignments) === 1) {
$error = "Equals sign not aligned correctly; expected $expected but found $found";
} else {
$error = "Equals sign not aligned with surrounding assignments; expected $expected but found $found";
}
 
if ($this->error === true) {
$phpcsFile->addError($error, $assignment);
} else {
$phpcsFile->addWarning($error, $assignment);
}
}//end if
}//end foreach
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Formatting/DisallowMultipleStatementsSniff.php
New file
0,0 → 1,84
<?php
/**
* Generic_Sniffs_Formatting_DisallowMultipleStatementsSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: DisallowMultipleStatementsSniff.php,v 1.1 2008/06/24 06:37:54 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Formatting_DisallowMultipleStatementsSniff.
*
* Ensures each statement is on a line by itself.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Formatting_DisallowMultipleStatementsSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_SEMICOLON);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in
* the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
$prev = $phpcsFile->findPrevious(T_SEMICOLON, ($stackPtr - 1));
if ($prev === false) {
return;
}
 
// Ignore multiple statements in a FOR condition.
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
foreach ($tokens[$stackPtr]['nested_parenthesis'] as $bracket) {
$owner = $tokens[$bracket]['parenthesis_owner'];
if ($tokens[$owner]['code'] === T_FOR) {
return;
}
}
}
 
if ($tokens[$prev]['line'] === $tokens[$stackPtr]['line']) {
$error = 'Each PHP statement must be on a line by itself';
$phpcsFile->addError($error, $stackPtr);
return;
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php
New file
0,0 → 1,87
<?php
/**
* Generic_Sniffs_WhiteSpace_DisallowTabIndentSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: DisallowTabIndentSniff.php,v 1.3 2008/10/28 04:43:57 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_WhiteSpace_DisallowTabIndentSniff.
*
* Throws errors if tabs are used for indentation.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_WhiteSpace_DisallowTabIndentSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
'CSS',
);
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_WHITESPACE);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
* @param int $stackPtr The position of the current token in
* the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
// Make sure this is whitespace used for indentation.
$line = $tokens[$stackPtr]['line'];
if ($stackPtr > 0 && $tokens[($stackPtr - 1)]['line'] === $line) {
return;
}
 
if (strpos($tokens[$stackPtr]['content'], "\t") !== false) {
$error = 'Spaces must be used to indent lines; tabs are not allowed';
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php
New file
0,0 → 1,311
<?php
/**
* Generic_Sniffs_Whitespace_ScopeIndentSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ScopeIndentSniff.php,v 1.12 2008/12/02 02:38:34 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_Whitespace_ScopeIndentSniff.
*
* Checks that control structures are structured correctly, and their content
* is indented correctly. This sniff will throw errors if tabs are used
* for indentation rather than spaces.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_WhiteSpace_ScopeIndentSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* The number of spaces code should be indented.
*
* @var int
*/
protected $indent = 4;
 
/**
* Does the indent need to be exactly right.
*
* If TRUE, indent needs to be exactly $ident spaces. If FALSE,
* indent needs to be at least $ident spaces (but can be more).
*
* @var bool
*/
protected $exact = false;
 
/**
* Any scope openers that should not cause an indent.
*
* @var array(int)
*/
protected $nonIndentingScopes = array();
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return PHP_CodeSniffer_Tokens::$scopeOpeners;
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
// If this is an inline condition (ie. there is no scope opener), then
// return, as this is not a new scope.
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
return;
}
 
if ($tokens[$stackPtr]['code'] === T_ELSE) {
$next = $phpcsFile->findNext(
PHP_CodeSniffer_Tokens::$emptyTokens,
($stackPtr + 1),
null,
true
);
 
// We will handle the T_IF token in another call to process.
if ($tokens[$next]['code'] === T_IF) {
return;
}
}
 
// Find the first token on this line.
$firstToken = $stackPtr;
for ($i = $stackPtr; $i >= 0; $i--) {
// Record the first code token on the line.
if (in_array($tokens[$i]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
$firstToken = $i;
}
 
// It's the start of the line, so we've found our first php token.
if ($tokens[$i]['column'] === 1) {
break;
}
}
 
// Based on the conditions that surround this token, determine the
// indent that we expect this current content to be.
$expectedIndent = $this->calculateExpectedIndent($tokens, $firstToken);
 
if ($tokens[$firstToken]['column'] !== $expectedIndent) {
$error = 'Line indented incorrectly; expected ';
$error .= ($expectedIndent - 1).' spaces, found ';
$error .= ($tokens[$firstToken]['column'] - 1);
$phpcsFile->addError($error, $stackPtr);
}
 
$scopeOpener = $tokens[$stackPtr]['scope_opener'];
$scopeCloser = $tokens[$stackPtr]['scope_closer'];
 
// Some scopes are expected not to have indents.
if (in_array($tokens[$firstToken]['code'], $this->nonIndentingScopes) === false) {
$indent = ($expectedIndent + $this->indent);
} else {
$indent = $expectedIndent;
}
 
$newline = false;
$commentOpen = false;
$inHereDoc = false;
 
// Only loop over the content beween the opening and closing brace, not
// the braces themselves.
for ($i = ($scopeOpener + 1); $i < $scopeCloser; $i++) {
 
// If this token is another scope, skip it as it will be handled by
// another call to this sniff.
if (in_array($tokens[$i]['code'], PHP_CodeSniffer_Tokens::$scopeOpeners) === true) {
if (isset($tokens[$i]['scope_opener']) === true) {
$i = $tokens[$i]['scope_closer'];
} else {
// If this token does not have a scope_opener indice, then
// it's probably an inline scope, so let's skip to the next
// semicolon. Inline scopes include inline if's, abstract
// methods etc.
$nextToken = $phpcsFile->findNext(T_SEMICOLON, $i, $scopeCloser);
if ($nextToken !== false) {
$i = $nextToken;
}
}
 
continue;
}
 
// If this is a HEREDOC then we need to ignore it as the
// whitespace before the contents within the HEREDOC are
// considered part of the content.
if ($tokens[$i]['code'] === T_START_HEREDOC) {
$inHereDoc = true;
continue;
} else if ($inHereDoc === true) {
if ($tokens[$i]['code'] === T_END_HEREDOC) {
$inHereDoc = false;
}
 
continue;
}
 
if ($tokens[$i]['column'] === 1) {
// We started a newline.
$newline = true;
}
 
if ($newline === true && $tokens[$i]['code'] !== T_WHITESPACE) {
// If we started a newline and we find a token that is not
// whitespace, then this must be the first token on the line that
// must be indented.
$newline = false;
$firstToken = $i;
 
$column = $tokens[$firstToken]['column'];
 
// Special case for non-PHP code.
if ($tokens[$firstToken]['code'] === T_INLINE_HTML) {
$trimmedContentLength
= strlen(ltrim($tokens[$firstToken]['content']));
if ($trimmedContentLength === 0) {
continue;
}
 
$contentLength = strlen($tokens[$firstToken]['content']);
$column = ($contentLength - $trimmedContentLength + 1);
}
 
// Check to see if this constant string spans multiple lines.
// If so, then make sure that the strings on lines other than the
// first line are indented appropriately, based on their whitespace.
if (in_array($tokens[$firstToken]['code'], PHP_CodeSniffer_Tokens::$stringTokens) === true) {
if (in_array($tokens[($firstToken - 1)]['code'], PHP_CodeSniffer_Tokens::$stringTokens) === true) {
// If we find a string that directly follows another string
// then its just a string that spans multiple lines, so we
// don't need to check for indenting.
continue;
}
}
 
// This is a special condition for T_DOC_COMMENT and C-style
// comments, which contain whitespace between each line.
$comments = array(
T_COMMENT,
T_DOC_COMMENT
);
 
if (in_array($tokens[$firstToken]['code'], $comments) === true) {
$content = trim($tokens[$firstToken]['content']);
if (preg_match('|^/\*|', $content) !== 0) {
// Check to see if the end of the comment is on the same line
// as the start of the comment. If it is, then we don't
// have to worry about opening a comment.
if (preg_match('|\*/$|', $content) === 0) {
// We don't have to calculate the column for the
// start of the comment as there is a whitespace
// token before it.
$commentOpen = true;
}
} else if ($commentOpen === true) {
if ($content === '') {
// We are in a comment, but this line has nothing on it
// so let's skip it.
continue;
}
 
$contentLength = strlen($tokens[$firstToken]['content']);
$trimmedContentLength
= strlen(ltrim($tokens[$firstToken]['content']));
 
$column = ($contentLength - $trimmedContentLength + 1);
if (preg_match('|\*/$|', $content) !== 0) {
$commentOpen = false;
}
}//end if
}//end if
 
// The token at the start of the line, needs to have its' column
// greater than the relative indent we set above. If it is less,
// an error should be shown.
if ($column !== $indent) {
if ($this->exact === true || $column < $indent) {
$error = 'Line indented incorrectly; expected ';
if ($this->exact === false) {
$error .= 'at least ';
}
 
$error .= ($indent - 1).' spaces, found ';
$error .= ($column - 1);
$phpcsFile->addError($error, $firstToken);
}
}
}//end if
}//end for
 
}//end process()
 
 
/**
* Calculates the expected indent of a token.
*
* @param array $tokens The stack of tokens for this file.
* @param int $stackPtr The position of the token to get indent for.
*
* @return int
*/
protected function calculateExpectedIndent(array $tokens, $stackPtr)
{
$conditionStack = array();
 
// Empty conditions array (top level structure).
if (empty($tokens[$stackPtr]['conditions']) === true) {
return 1;
}
 
$tokenConditions = $tokens[$stackPtr]['conditions'];
foreach ($tokenConditions as $id => $condition) {
// If it's an indenting scope ie. it's not in our array of
// scopes that don't indent, add it to our condition stack.
if (in_array($condition, $this->nonIndentingScopes) === false) {
$conditionStack[$id] = $condition;
}
}
 
return ((count($conditionStack) * $this->indent) + 1);
 
}//end calculateExpectedIndent()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/Classes/DuplicateClassNameSniff.php
New file
0,0 → 1,74
<?php
/**
* Reports errors if the same class or interface name is used in multiple files.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: DuplicateClassNameSniff.php,v 1.1 2008/07/25 04:24:10 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Reports errors if the same class or interface name is used in multiple files.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_Classes_DuplicateClassNameSniff implements PHP_CodeSniffer_MultiFileSniff
{
 
 
/**
* Called once per script run to allow for processing of this sniff.
*
* @param array(PHP_CodeSniffer_File) $files The PHP_CodeSniffer files processed
* during the script run.
*
* @return void
*/
public function process(array $files)
{
$foundClasses = array();
 
foreach ($files as $phpcsFile) {
$tokens = $phpcsFile->getTokens();
 
$stackPtr = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE), 0);
while ($stackPtr !== false) {
$nameToken = $phpcsFile->findNext(T_STRING, $stackPtr);
$name = $tokens[$nameToken]['content'];
$compareName = strtolower($name);
if (isset($foundClasses[$compareName]) === true) {
$type = strtolower($tokens[$stackPtr]['content']);
$file = $foundClasses[$compareName]['file'];
$line = $foundClasses[$compareName]['line'];
$error = "Duplicate $type name \"$name\" found; first defined in $file on line $line";
$phpcsFile->addWarning($error, $stackPtr);
} else {
$foundClasses[$compareName] = array(
'file' => $phpcsFile->getFilename(),
'line' => $tokens[$stackPtr]['line'],
);
}
 
$stackPtr = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE), ($stackPtr + 1));
}//end while
 
}//end foreach
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/ForLoopShouldBeWhileLoopSniff.php
New file
0,0 → 1,101
<?php
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: ForLoopShouldBeWhileLoopSniff.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Detects for-loops that can be simplified to a while-loop.
*
* This rule is based on the PMD rule catalog. Detects for-loops that can be
* simplified as a while-loop.
*
* <code>
* class Foo
* {
* public function bar($x)
* {
* for (;true;) true; // No Init or Update part, may as well be: while (true)
* }
* }
* </code>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_CodeAnalysis_ForLoopShouldBeWhileLoopSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return array(integer)
*/
public function register()
{
return array(T_FOR);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];
 
// Skip invalid statement.
if (isset($token['parenthesis_opener']) === false) {
return;
}
 
$next = ++$token['parenthesis_opener'];
$end = --$token['parenthesis_closer'];
 
$parts = array(0, 0, 0);
$index = 0;
 
for (; $next <= $end; ++$next) {
$code = $tokens[$next]['code'];
if ($code === T_SEMICOLON) {
++$index;
} else if (in_array($code, PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
++$parts[$index];
}
}
 
if ($parts[0] === 0 && $parts[2] === 0 && $parts[1] > 0) {
$error = 'This FOR loop can be simplified to a WHILE loop';
$phpcsFile->addWarning($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php
New file
0,0 → 1,107
<?php
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: UnconditionalIfStatementSniff.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Detects unconditional if- and elseif-statements.
*
* This rule is based on the PMD rule catalog. The Unconditional If Statment
* sniff detects statement conditions that are only set to one of the constant
* values <b>true</b> or <b>false</b>
*
* <code>
* class Foo
* {
* public function close()
* {
* if (true)
* {
* // ...
* }
* }
* }
* </code>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_CodeAnalysis_UnconditionalIfStatementSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return array(integer)
*/
public function register()
{
return array(
T_IF,
T_ELSEIF,
);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];
 
// Skip for-loop without body.
if (isset($token['parenthesis_opener']) === false) {
return;
}
 
$next = ++$token['parenthesis_opener'];
$end = --$token['parenthesis_closer'];
 
$goodCondition = false;
for (; $next <= $end; ++$next) {
$code = $tokens[$next]['code'];
 
if (in_array($code, PHP_CodeSniffer_Tokens::$emptyTokens) === true) {
continue;
} else if ($code !== T_TRUE && $code !== T_FALSE) {
$goodCondition = true;
}
}
 
if ($goodCondition === false) {
$error = 'Avoid IF statements that are always true or false';
$phpcsFile->addWarning($error, $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnusedFunctionParameterSniff.php
New file
0,0 → 1,141
<?php
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: UnusedFunctionParameterSniff.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Checks the for unused function parameters.
*
* This sniff checks that all function parameters are used in the function body.
* One exception is made for empty function bodies or function bodies that only
* contain comments. This could be usefull for the classes that implement an
* interface that defines multiple methods but the implementation only needs some
* of them.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_CodeAnalysis_UnusedFunctionParameterSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_FUNCTION);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];
 
// Skip broken function declarations.
if (isset($token['scope_opener']) === false || isset($token['parenthesis_opener']) === false) {
return;
}
 
$params = array();
foreach ($phpcsFile->getMethodParameters($stackPtr) as $param) {
$params[$param['name']] = $stackPtr;
}
 
$next = ++$token['scope_opener'];
$end = --$token['scope_closer'];
 
$emptyBody = true;
 
for (; $next <= $end; ++$next) {
$token = $tokens[$next];
$code = $token['code'];
 
// Ingorable tokens.
if (in_array($code, PHP_CodeSniffer_Tokens::$emptyTokens) === true) {
continue;
} else if ($code === T_THROW && $emptyBody === true) {
// Throw statement and an empty body indicate an interface method.
return;
} else if ($code === T_RETURN && $emptyBody === true) {
// Return statement and an empty body indicate an interface method.
$tmp = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true);
if ($tmp === false) {
return;
}
 
// There is a return.
if ($tokens[$tmp] === T_SEMICOLON) {
return;
}
 
$tmp = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($tmp + 1), null, true);
 
// There is a return <token>.
if ($tmp !== false && $tokens[$tmp] === T_SEMICOLON) {
return;
}
}//end if
 
$emptyBody = false;
 
if ($code === T_VARIABLE && isset($params[$token['content']]) === true) {
unset($params[$token['content']]);
} else if ($code === T_DOUBLE_QUOTED_STRING) {
// Tokenize double quote string.
$strTokens = token_get_all(sprintf('<?php %s;?>', $token['content']));
 
foreach ($strTokens as $tok) {
if (is_array($tok) === false || $tok[0] !== T_VARIABLE ) {
continue;
}
 
if (isset($params[$tok[1]]) === true) {
unset($params[$tok[1]]);
}
}
}//end if
}//end for
 
if ($emptyBody === false && count($params) > 0) {
foreach ($params as $paramName => $position) {
$error = 'The method parameter '.$paramName.' is never used';
$phpcsFile->addWarning($error, $position);
}
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php
New file
0,0 → 1,181
<?php
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: UselessOverridingMethodSniff.php,v 1.2 2008/10/01 06:08:49 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Detects unnecessary overriden methods that simply call their parent.
*
* This rule is based on the PMD rule catalog. The Useless Overriding Method
* sniff detects the use of methods that only call their parent classes's method
* with the same name and arguments. These methods are not required.
*
* <code>
* class FooBar {
* public function __construct($a, $b) {
* parent::__construct($a, $b);
* }
* }
* </code>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_CodeAnalysis_UselessOverridingMethodSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return array(integer)
*/
public function register()
{
return array(T_FUNCTION);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];
 
// Skip function without body.
if (isset($token['scope_opener']) === false) {
return;
}
 
// Get function name.
$methodName = $phpcsFile->getDeclarationName($stackPtr);
 
// Get all parameters from method signature.
$signature = array();
foreach ($phpcsFile->getMethodParameters($stackPtr) as $param) {
$signature[] = $param['name'];
}
 
$next = ++$token['scope_opener'];
$end = --$token['scope_closer'];
 
for (; $next <= $end; ++$next) {
$code = $tokens[$next]['code'];
 
if (in_array($code, PHP_CodeSniffer_Tokens::$emptyTokens) === true) {
continue;
} else if ($code === T_RETURN) {
continue;
}
 
break;
}
 
// Any token except 'parent' indicates correct code.
if ($tokens[$next]['code'] !== T_PARENT) {
return;
}
 
// Find next non empty token index, should be double colon.
$next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true);
 
// Skip for invalid code.
if ($next === false || $tokens[$next]['code'] !== T_DOUBLE_COLON) {
return;
}
 
// Find next non empty token index, should be the function name.
$next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true);
 
// Skip for invalid code or other method.
if ($next === false || $tokens[$next]['content'] !== $methodName) {
return;
}
 
// Find next non empty token index, should be the open parenthesis.
$next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true);
 
// Skip for invalid code.
if ($next === false || $tokens[$next]['code'] !== T_OPEN_PARENTHESIS) {
return;
}
 
$validParameterTypes = array(
T_VARIABLE,
T_LNUMBER,
T_CONSTANT_ENCAPSED_STRING,
);
 
$parameters = array('');
$parenthesisCount = 1;
$count = count($tokens);
for (++$next; $next < $count; ++$next) {
$code = $tokens[$next]['code'];
 
if ($code === T_OPEN_PARENTHESIS) {
++$parenthesisCount;
} else if ($code === T_CLOSE_PARENTHESIS) {
--$parenthesisCount;
} else if ($parenthesisCount === 1 && $code === T_COMMA) {
$parameters[] = '';
} else if (in_array($code, PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
$parameters[(count($parameters) - 1)] .= $tokens[$next]['content'];
}
 
if ($parenthesisCount === 0) {
break;
}
}//end for
 
$next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true);
if ($next === false || $tokens[$next]['code'] !== T_SEMICOLON) {
return;
}
 
// Check rest of the scope.
for (++$next; $next <= $end; ++$next) {
$code = $tokens[$next]['code'];
// Skip for any other content.
if (in_array($code, PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
return;
}
}
 
$parameters = array_map('trim', $parameters);
$parameters = array_filter($parameters);
 
if (count($parameters) === count($signature) && $parameters === $signature) {
$phpcsFile->addWarning('Useless method overriding detected', $stackPtr);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/ForLoopWithTestFunctionCallSniff.php
New file
0,0 → 1,114
<?php
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: ForLoopWithTestFunctionCallSniff.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Detects for-loops that use a function call in the test expression.
*
* This rule is based on the PMD rule catalog. Detects for-loops that use a
* function call in the test expression.
*
* <code>
* class Foo
* {
* public function bar($x)
* {
* $a = array(1, 2, 3, 4);
* for ($i = 0; $i < count($a); $i++) {
* $a[$i] *= $i;
* }
* }
* }
* </code>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_CodeAnalysis_ForLoopWithTestFunctionCallSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return array(integer)
*/
public function register()
{
return array(T_FOR);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];
 
// Skip invalid statement.
if (isset($token['parenthesis_opener']) === false) {
return;
}
 
$next = ++$token['parenthesis_opener'];
$end = --$token['parenthesis_closer'];
 
$position = 0;
 
for (; $next <= $end; ++$next) {
$code = $tokens[$next]['code'];
if ($code === T_SEMICOLON) {
++$position;
}
 
if ($position < 1) {
continue;
} else if ($position > 1) {
break;
} else if ($code !== T_VARIABLE && $code !== T_STRING) {
continue;
}
 
// Find next non empty token, if it is a open curly brace we have a
// function call.
$index = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true);
 
if ($tokens[$index]['code'] === T_OPEN_PARENTHESIS) {
$error = 'Avoid function calls in a FOR loop test part';
$phpcsFile->addWarning($error, $stackPtr);
break;
}
}//end for
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/JumbledIncrementerSniff.php
New file
0,0 → 1,148
<?php
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: JumbledIncrementerSniff.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Detects incrementer jumbling in for loops.
*
* This rule is based on the PMD rule catalog. The jumbling incrementer sniff
* detects the usage of one and the same incrementer into an outer and an inner
* loop. Even it is intended this is confusing code.
*
* <code>
* class Foo
* {
* public function bar($x)
* {
* for ($i = 0; $i < 10; $i++)
* {
* for ($k = 0; $k < 20; $i++)
* {
* echo 'Hello';
* }
* }
* }
* }
* </code>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_CodeAnalysis_JumbledIncrementerSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return array(integer)
*/
public function register()
{
return array(T_FOR);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];
 
// Skip for-loop without body.
if (isset($token['scope_opener']) === false) {
return;
}
 
// Find incrementors for outer loop.
$outer = $this->findIncrementers($tokens, $token);
 
// Skip if empty.
if (count($outer) === 0) {
return;
}
 
// Find nested for loops.
$start = ++$token['scope_opener'];
$end = --$token['scope_closer'];
 
for (; $start <= $end; ++$start) {
if ($tokens[$start]['code'] !== T_FOR) {
continue;
}
 
$inner = $this->findIncrementers($tokens, $tokens[$start]);
$diff = array_intersect($outer, $inner);
 
if (count($diff) !== 0) {
$error = sprintf('Loop incrementor (%s) jumbling with inner loop', join(', ', $diff));
$phpcsFile->addWarning($error, $stackPtr);
}
}
 
}//end process()
 
 
/**
* Get all used variables in the incrementer part of a for statement.
*
* @param array(integer=>array) $tokens Array with all code sniffer tokens.
* @param array(string=>mixed) $token Current for loop token
*
* @return array(string) List of all found incrementer variables.
*/
protected function findIncrementers(array $tokens, array $token)
{
// Skip invalid statement.
if (isset($token['parenthesis_opener']) === false) {
return array();
}
 
$start = ++$token['parenthesis_opener'];
$end = --$token['parenthesis_closer'];
 
$incrementers = array();
$semicolons = 0;
for ($next = $start; $next <= $end; ++$next) {
$code = $tokens[$next]['code'];
if ($code === T_SEMICOLON) {
++$semicolons;
} else if ($semicolons === 2 && $code === T_VARIABLE) {
$incrementers[] = $tokens[$next]['content'];
}
}
 
return $incrementers;
 
}//end findIncrementers()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/EmptyStatementSniff.php
New file
0,0 → 1,129
<?php
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: EmptyStatementSniff.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* This sniff class detected empty statement.
*
* This sniff implements the common algorithm for empty statement body detection.
* A body is considered as empty if it is completely empty or it only contains
* whitespace characters and|or comments.
*
* <code>
* stmt {
* // foo
* }
* stmt (conditions) {
* // foo
* }
* </code>
*
* Statements covered by this sniff are <b>catch</b>, <b>do</b>, <b>else</b>,
* <b>elsif</b>, <b>for</b>, <b>foreach<b>, <b>if</b>, <b>switch</b>, <b>try</b>
* and <b>while</b>.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_CodeAnalysis_EmptyStatementSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* List of block tokens that this sniff covers.
*
* The key of this hash identifies the required token while the boolean
* value says mark an error or mark a warning.
*
* @type array<boolean>
* @var array(integer=>boolean) $_tokens
*/
private $_tokens = array(
T_CATCH => true,
T_DO => false,
T_ELSE => false,
T_ELSEIF => false,
T_FOR => false,
T_FOREACH => false,
T_IF => false,
T_SWITCH => false,
T_TRY => false,
T_WHILE => false,
);
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return array(integer)
*/
public function register()
{
return array_keys($this->_tokens);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];
 
// Skip for-statements without body.
if (isset($token['scope_opener']) === false) {
return;
}
 
$next = ++$token['scope_opener'];
$end = --$token['scope_closer'];
 
$emptyBody = true;
for (; $next <= $end; ++$next) {
if (in_array($tokens[$next]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
$emptyBody = false;
break;
}
}
 
if ($emptyBody === true) {
// Get token identifier.
$name = $phpcsFile->getTokensAsString($stackPtr, 1);
$error = sprintf('Empty %s statement detected', strtoupper($name));
if ($this->_tokens[$token['code']] === true) {
$phpcsFile->addError($error, $stackPtr);
} else {
$phpcsFile->addWarning($error, $stackPtr);
}
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnnecessaryFinalModifierSniff.php
New file
0,0 → 1,99
<?php
/**
* This file is part of the CodeAnalysis addon for PHP_CodeSniffer.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version CVS: $Id: UnnecessaryFinalModifierSniff.php,v 1.1 2008/02/06 02:38:36 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Detects unnecessary final modifiers inside of final classes.
*
* This rule is based on the PMD rule catalog. The Unnecessary Final Modifier
* sniff detects the use of the final modifier inside of a final class which
* is unnecessary.
*
* <code>
* final class Foo
* {
* public final function bar()
* {
* }
* }
* </code>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Manuel Pichler <mapi@manuel-pichler.de>
* @copyright 2007-2008 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_CodeAnalysis_UnnecessaryFinalModifierSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* @return array(integer)
*/
public function register()
{
return array(T_CLASS);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$token = $tokens[$stackPtr];
 
// Skip for-statements without body.
if (isset($token['scope_opener']) === false) {
return;
}
 
// Fetch previous token.
$prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
 
// Skip for non final class.
if ($prev === false || $tokens[$prev]['code'] !== T_FINAL) {
return;
}
 
$next = ++$token['scope_opener'];
$end = --$token['scope_closer'];
 
for (; $next <= $end; ++$next) {
if ($tokens[$next]['code'] === T_FINAL) {
$error = 'Unnecessary FINAL modifier in FINAL class';
$phpcsFile->addWarning($error, $next);
}
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php
New file
0,0 → 1,151
<?php
/**
* Generic_Sniffs_NamingConventions_UpperCaseConstantNameSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: UpperCaseConstantNameSniff.php,v 1.10 2008/05/07 23:13:49 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Generic_Sniffs_NamingConventions_UpperCaseConstantNameSniff.
*
* Ensures that constant names are all uppercase.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_NamingConventions_UpperCaseConstantNameSniff implements PHP_CodeSniffer_Sniff
{
 
 
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_STRING);
 
}//end register()
 
 
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$constName = $tokens[$stackPtr]['content'];
 
// If this token is in a heredoc, ignore it.
if ($phpcsFile->hasCondition($stackPtr, T_START_HEREDOC) === true) {
return;
}
 
// If the next non-whitespace token after this token
// is not an opening parenthesis then it is not a function call.
$openBracket = $phpcsFile->findNext(array(T_WHITESPACE), ($stackPtr + 1), null, true);
if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
$functionKeyword = $phpcsFile->findPrevious(array(T_WHITESPACE, T_COMMA, T_COMMENT, T_STRING), ($stackPtr - 1), null, true);
 
$declarations = array(
T_FUNCTION,
T_CLASS,
T_INTERFACE,
T_IMPLEMENTS,
T_EXTENDS,
T_INSTANCEOF,
T_NEW,
);
if (in_array($tokens[$functionKeyword]['code'], $declarations) === true) {
// This is just a declaration; no constants here.
return;
}
 
if ($tokens[$functionKeyword]['code'] === T_CONST) {
// This is a class constant.
if (strtoupper($constName) !== $constName) {
$error = 'Class constants must be uppercase; expected '.strtoupper($constName)." but found $constName";
$phpcsFile->addError($error, $stackPtr);
}
 
return;
}
 
// Is this a class name?
$nextPtr = $phpcsFile->findNext(array(T_WHITESPACE), ($stackPtr + 1), null, true);
if ($tokens[$nextPtr]['code'] === T_DOUBLE_COLON) {
return;
}
 
// Is this a type hint?
if ($tokens[$nextPtr]['code'] === T_VARIABLE) {
return;
} else if ($phpcsFile->isReference($nextPtr) === true) {
return;
}
 
// Is this a member var name?
$prevPtr = $phpcsFile->findPrevious(array(T_WHITESPACE), ($stackPtr - 1), null, true);
if ($tokens[$prevPtr]['code'] === T_OBJECT_OPERATOR) {
return;
}
 
// Is this an instance of declare()
$prevPtr = $phpcsFile->findPrevious(array(T_WHITESPACE, T_OPEN_PARENTHESIS), ($stackPtr - 1), null, true);
if ($tokens[$prevPtr]['code'] === T_DECLARE) {
return;
}
 
// This is a real constant.
if (strtoupper($constName) !== $constName) {
$error = 'Constants must be uppercase; expected '.strtoupper($constName)." but found $constName";
$phpcsFile->addError($error, $stackPtr);
}
 
} else if (strtolower($constName) === 'define' || strtolower($constName) === 'constant') {
 
/*
This may be a "define" or "constant" function call.
*/
 
// The next non-whitespace token must be the constant name.
$constPtr = $phpcsFile->findNext(array(T_WHITESPACE), ($openBracket + 1), null, true);
if ($tokens[$constPtr]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
return;
}
 
$constName = $tokens[$constPtr]['content'];
if (strtoupper($constName) !== $constName) {
$error = 'Constants must be uppercase; expected '.strtoupper($constName)." but found $constName";
$phpcsFile->addError($error, $stackPtr);
}
}//end if
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php
New file
0,0 → 1,102
<?php
/**
* Generic_Sniffs_NamingConventions_ConstructorNameSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Leif Wickland <lwickland@rightnow.com>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ConstructorNameSniff.php,v 1.2 2009/02/24 04:43:44 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) {
$error = 'Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* Generic_Sniffs_NamingConventions_ConstructorNameSniff.
*
* Favor PHP 5 constructor syntax, which uses "function __construct()".
* Avoid PHP 4 constructor syntax, which uses "function ClassName()".
*
* @category PHP
* @package PHP_CodeSniffer
* @author Leif Wickland <lwickland@rightnow.com>
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Generic_Sniffs_NamingConventions_ConstructorNameSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff
{
 
 
/**
* Constructs the test with the tokens it wishes to listen for.
*
* @return void
*/
public function __construct()
{
parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION), true);
 
}//end __construct()
 
 
/**
* Processes this test when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The current file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
* @param int $currScope A pointer to the start of the scope.
*
* @return void
*/
protected function processTokenWithinScope(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr,
$currScope
) {
$className = $phpcsFile->getDeclarationName($currScope);
$methodName = $phpcsFile->getDeclarationName($stackPtr);
 
if (strcasecmp($methodName, $className) === 0) {
$error = 'PHP4 style constructors are not allowed; use "__construct()" instead';
$phpcsFile->addError($error, $stackPtr);
} else if (strcasecmp($methodName, '__construct') !== 0) {
// Not a constructor.
return;
}
 
$tokens = $phpcsFile->getTokens();
 
$parentClassName = $phpcsFile->findExtendedClassName($currScope);
if ($parentClassName === false) {
return;
}
 
$endFunctionIndex = $tokens[$stackPtr]['scope_closer'];
$startIndex = $stackPtr;
while ($doubleColonIndex = $phpcsFile->findNext(array(T_DOUBLE_COLON), $startIndex, $endFunctionIndex)) {
if ($tokens[($doubleColonIndex + 1)]['code'] === T_STRING
&& $tokens[($doubleColonIndex + 1)]['content'] === $parentClassName
) {
$error = 'PHP4 style calls to parent constructors are not allowed; use "parent::__construct()" instead';
$phpcsFile->addError($error, ($doubleColonIndex + 1));
}
 
$startIndex = ($doubleColonIndex + 1);
}
 
}//end processTokenWithinScope()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/AbstractPatternSniff.php
New file
0,0 → 1,867
<?php
/**
* Processes pattern strings and checks that the code conforms to the pattern.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: AbstractPatternSniff.php,v 1.26 2008/12/11 06:08:10 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_Standards_IncorrectPatternException', true) === false) {
$error = 'Class PHP_CodeSniffer_Standards_IncorrectPatternException not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* Processes pattern strings and checks that the code conforms to the pattern.
*
* This test essentially checks that code is correctly formatted with whitespace.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
abstract class PHP_CodeSniffer_Standards_AbstractPatternSniff implements PHP_CodeSniffer_Sniff
{
 
/**
* The parsed patterns array.
*
* @var array
*/
private $_parsedPatterns = array();
 
/**
* Tokens that wish this sniff wishes to process outside of the patterns.
*
* @var array(int)
* @see registerSupplementary()
* @see processSupplementary()
*/
private $_supplementaryTokens = array();
 
/**
* If true, comments will be ignored if they are found in the code.
*
* @var boolean
*/
private $_ignoreComments = false;
 
/**
* Positions in the stack where errors have occured.
*
* @var array()
*/
private $_errorPos = array();
 
 
/**
* Constructs a PHP_CodeSniffer_Standards_AbstractPatternSniff.
*
* @param boolean $ignoreComments If true, comments will be ignored.
*/
public function __construct($ignoreComments=false)
{
$this->_ignoreComments = $ignoreComments;
$this->_supplementaryTokens = $this->registerSupplementary();
 
}//end __construct()
 
 
/**
* Registers the tokens to listen to.
*
* Classes extending <i>AbstractPatternTest</i> should implement the
* <i>getPatterns()</i> method to register the patterns they wish to test.
*
* @return array(int)
* @see process()
*/
public final function register()
{
$listenTypes = array();
$patterns = $this->getPatterns();
 
foreach ($patterns as $pattern) {
 
$parsedPattern = $this->_parse($pattern);
 
// Find a token position in the pattern that we can use for a listener
// token.
$pos = $this->_getListenerTokenPos($parsedPattern);
$tokenType = $parsedPattern[$pos]['token'];
$listenTypes[] = $tokenType;
 
$patternArray = array(
'listen_pos' => $pos,
'pattern' => $parsedPattern,
'pattern_code' => $pattern,
);
 
if (isset($this->_parsedPatterns[$tokenType]) === false) {
$this->_parsedPatterns[$tokenType] = array();
}
 
$this->_parsedPatterns[$tokenType][] = $patternArray;
 
}//end foreach
 
return array_unique(array_merge($listenTypes, $this->_supplementaryTokens));
 
}//end register()
 
 
/**
* Returns the token types that the specified pattern is checking for.
*
* Returned array is in the format:
* <code>
* array(
* T_WHITESPACE => 0, // 0 is the position where the T_WHITESPACE token
* // should occur in the pattern.
* );
* </code>
*
* @param array $pattern The parsed pattern to find the acquire the token
* types from.
*
* @return array(int => int)
*/
private function _getPatternTokenTypes($pattern)
{
$tokenTypes = array();
foreach ($pattern as $pos => $patternInfo) {
if ($patternInfo['type'] === 'token') {
if (isset($tokenTypes[$patternInfo['token']]) === false) {
$tokenTypes[$patternInfo['token']] = $pos;
}
}
}
 
return $tokenTypes;
 
}//end _getPatternTokenTypes()
 
 
/**
* Returns the position in the pattern that this test should register as
* a listener for the pattern.
*
* @param array $pattern The pattern to acquire the listener for.
*
* @return int The postition in the pattern that this test should register
* as the listener.
* @throws PHP_CodeSniffer_Exception If we could not determine a token
* to listen for.
*/
private function _getListenerTokenPos($pattern)
{
$tokenTypes = $this->_getPatternTokenTypes($pattern);
$tokenCodes = array_keys($tokenTypes);
$token = PHP_CodeSniffer_Tokens::getHighestWeightedToken($tokenCodes);
 
// If we could not get a token.
if ($token === false) {
$error = 'Could not determine a token to listen for';
throw new PHP_CodeSniffer_Exception($error);
}
 
return $tokenTypes[$token];
 
}//end _getListenerTokenPos()
 
 
/**
* Processes the test.
*
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where the
* token occured.
* @param int $stackPtr The postion in the tokens stack
* where the listening token type was
* found.
*
* @return void
* @see register()
*/
public final function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
 
if (in_array($tokens[$stackPtr]['code'], $this->_supplementaryTokens) === true) {
$this->processSupplementary($phpcsFile, $stackPtr);
}
 
$type = $tokens[$stackPtr]['code'];
 
// If the type is not set, then it must have been a token registered
// with registerSupplementary().
if (isset($this->_parsedPatterns[$type]) === false) {
return;
}
 
$allErrors = array();
 
// Loop over each pattern that is listening to the current token type
// that we are processing.
foreach ($this->_parsedPatterns[$type] as $patternInfo) {
 
// If processPattern returns false, then the pattern that we are
// checking the code with must not be design to check that code.
$errors = $this->processPattern($patternInfo, $phpcsFile, $stackPtr);
if ($errors === false) {
// The pattern didn't match.
continue;
} else if (empty($errors) === true) {
// The pattern matched, but there were no errors.
break;
}
 
foreach ($errors as $stackPtr => $error) {
if (isset($this->_errorPos[$stackPtr]) === false) {
$this->_errorPos[$stackPtr] = true;
$allErrors[$stackPtr] = $error;
}
}
}
 
foreach ($allErrors as $stackPtr => $error) {
$phpcsFile->addError($error, $stackPtr);
}
 
}//end process()
 
 
/**
* Processes the pattern and verifies the code at $stackPtr.
*
* @param array $patternInfo Information about the pattern used
* for checking, which includes are
* parsed token representation of the
* pattern.
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where the
* token occured.
* @param int $stackPtr The postion in the tokens stack where
* the listening token type was found.
*
* @return array(errors)
*/
protected function processPattern(
$patternInfo,
PHP_CodeSniffer_File $phpcsFile,
$stackPtr
) {
$tokens = $phpcsFile->getTokens();
$pattern = $patternInfo['pattern'];
$patternCode = $patternInfo['pattern_code'];
$errors = array();
$found = '';
 
$ignoreTokens = array(T_WHITESPACE);
 
if ($this->_ignoreComments === true) {
$ignoreTokens
= array_merge($ignoreTokens, PHP_CodeSniffer_Tokens::$commentTokens);
}
 
$origStackPtr = $stackPtr;
$hasError = false;
 
if ($patternInfo['listen_pos'] > 0) {
$stackPtr--;
 
for ($i = ($patternInfo['listen_pos'] - 1); $i >= 0; $i--) {
 
if ($pattern[$i]['type'] === 'token') {
 
if ($pattern[$i]['token'] === T_WHITESPACE) {
 
if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
$found = $tokens[$stackPtr]['content'].$found;
}
 
// Only check the size of the whitespace if this is not
// not the first token. We don't care about the size of
// leading whitespace, just that there is some.
if ($i !== 0) {
if ($tokens[$stackPtr]['content'] !== $pattern[$i]['value']) {
$hasError = true;
}
}
 
} else {
 
// Check to see if this important token is the same as the
// previous important token in the pattern. If it is not,
// then the pattern cannot be for this piece of code.
$prev = $phpcsFile->findPrevious(
$ignoreTokens,
$stackPtr,
null,
true
);
 
if ($prev === false
|| $tokens[$prev]['code'] !== $pattern[$i]['token']
) {
return false;
}
 
// If we skipped past some whitespace tokens, then add them
// to the found string.
if (($stackPtr - $prev) > 1) {
for ($j = ($stackPtr - 1); $j > $prev; $j--) {
$found = $tokens[$j]['content'].$found;
}
}
 
$found = $tokens[$prev]['content'].$found;
 
if (isset($pattern[($i - 1)]) === true
&& $pattern[($i - 1)]['type'] === 'skip'
) {
$stackPtr = $prev;
} else {
$stackPtr = ($prev - 1);
}
 
}//end if
} else if ($pattern[$i]['type'] === 'skip') {
// Skip to next piece of relevant code.
if ($pattern[$i]['to'] === 'parenthesis_closer') {
$to = 'parenthesis_opener';
} else {
$to = 'scope_opener';
}
 
// Find the previous opener.
$next = $phpcsFile->findPrevious(
$ignoreTokens,
$stackPtr,
null,
true
);
 
if ($next === false || isset($tokens[$next][$to]) === false) {
// If there was not opener, then we must be
// using the wrong pattern.
return false;
}
 
if ($to === 'parenthesis_opener') {
$found = '{'.$found;
} else {
$found = '('.$found;
}
 
$found = '...'.$found;
 
// Skip to the opening token.
$stackPtr = ($tokens[$next][$to] - 1);
} else if ($pattern[$i]['type'] === 'string') {
$found = 'abc';
} else if ($pattern[$i]['type'] === 'newline') {
$found = 'EOL';
}//end if
}//end for
}//end if
 
$stackPtr = $origStackPtr;
$lastAddedStackPtr = null;
$patternLen = count($pattern);
 
for ($i = $patternInfo['listen_pos']; $i < $patternLen; $i++) {
if ($pattern[$i]['type'] === 'token') {
if ($pattern[$i]['token'] === T_WHITESPACE) {
if ($this->_ignoreComments === true) {
// If we are ignoring comments, check to see if this current
// token is a comment. If so skip it.
if (in_array($tokens[$stackPtr]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true) {
continue;
}
 
// If the next token is a comment, the we need to skip the
// current token as we should allow a space before a
// comment for readability.
if (in_array($tokens[($stackPtr + 1)]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true) {
continue;
}
}
 
$tokenContent = '';
if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
if (isset($pattern[($i + 1)]) === false) {
// This is the last token in the pattern, so just compare
// the next token of content.
$tokenContent = $tokens[$stackPtr]['content'];
} else {
// Get all the whitespace to the next token.
$next = $phpcsFile->findNext(
PHP_CodeSniffer_Tokens::$emptyTokens,
$stackPtr,
null,
true
);
 
$tokenContent = $phpcsFile->getTokensAsString(
$stackPtr,
($next - $stackPtr)
);
 
$lastAddedStackPtr = $stackPtr;
$stackPtr = $next;
}
 
if ($stackPtr !== $lastAddedStackPtr) {
$found .= $tokenContent;
}
} else {
if ($stackPtr !== $lastAddedStackPtr) {
$found .= $tokens[$stackPtr]['content'];
$lastAddedStackPtr = $stackPtr;
}
}//end if
 
if (isset($pattern[($i + 1)]) === true
&& $pattern[($i + 1)]['type'] === 'skip'
) {
// The next token is a skip token, so we just need to make
// sure the whitespace we found has *at least* the
// whitespace required.
if (strpos($tokenContent, $pattern[$i]['value']) !== 0) {
$hasError = true;
}
} else {
if ($tokenContent !== $pattern[$i]['value']) {
$hasError = true;
}
}
 
} else {
// Check to see if this important token is the same as the
// next important token in the pattern. If it is not, then
// the pattern cannot be for this piece of code.
$next = $phpcsFile->findNext(
$ignoreTokens,
$stackPtr,
null,
true
);
 
if ($next === false
|| $tokens[$next]['code'] !== $pattern[$i]['token']
) {
return false;
}
 
// If we skipped past some whitespace tokens, then add them
// to the found string.
if (($next - $stackPtr) > 0) {
$hasComment = false;
for ($j = $stackPtr; $j < $next; $j++) {
$found .= $tokens[$j]['content'];
if (in_array($tokens[$j]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true) {
$hasComment = true;
}
}
 
// If we are not ignoring comments, this additional
// whitespace or comment is not allowed. If we are
// ignoring comments, there needs to be at least one
// comment for this to be allowed.
if ($this->_ignoreComments === false
|| ($this->_ignoreComments === true
&& $hasComment === false)
) {
$hasError = true;
}
 
// Even when ignoring comments, we are not allowed to include
// newlines without the pattern specifying them, so
// everything should be on the same line.
if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
$hasError = true;
}
}//end if
 
if ($next !== $lastAddedStackPtr) {
$found .= $tokens[$next]['content'];
$lastAddedStackPtr = $next;
}
 
if (isset($pattern[($i + 1)]) === true
&& $pattern[($i + 1)]['type'] === 'skip'
) {
$stackPtr = $next;
} else {
$stackPtr = ($next + 1);
}
}//end if
 
} else if ($pattern[$i]['type'] === 'skip') {
if ($pattern[$i]['to'] === 'unknown') {
$next = $phpcsFile->findNext(
$pattern[($i + 1)]['token'],
$stackPtr
);
 
if ($next === false) {
// Couldn't find the next token, sowe we must
// be using the wrong pattern.
return false;
}
 
$found .= '...';
$stackPtr = $next;
} else {
// Find the previous opener.
$next = $phpcsFile->findPrevious(
PHP_CodeSniffer_Tokens::$blockOpeners,
$stackPtr
);
 
if ($next === false
|| isset($tokens[$next][$pattern[$i]['to']]) === false
) {
// If there was not opener, then we must
// be using the wrong pattern.
return false;
}
 
$found .= '...';
if ($pattern[$i]['to'] === 'parenthesis_closer') {
$found .= ')';
} else {
$found .= '}';
}
 
// Skip to the closing token.
$stackPtr = ($tokens[$next][$pattern[$i]['to']] + 1);
}
} else if ($pattern[$i]['type'] === 'string') {
if ($tokens[$stackPtr]['code'] !== T_STRING) {
$hasError = true;
}
 
if ($stackPtr !== $lastAddedStackPtr) {
$found .= 'abc';
$lastAddedStackPtr = $stackPtr;
}
 
$stackPtr++;
} else if ($pattern[$i]['type'] === 'newline') {
// Find the next token that contains a newline character.
$newline = 0;
for ($j = $stackPtr; $j < $phpcsFile->numTokens; $j++) {
if (strpos($tokens[$j]['content'], $phpcsFile->eolChar) !== false) {
$newline = $j;
break;
}
}
 
if ($newline === 0) {
// We didn't find a newline character in the rest of the file.
$next = ($phpcsFile->numTokens - 1);
$hasError = true;
} else {
if ($this->_ignoreComments === false) {
// The newline character cannot be part of a comment.
if (in_array($tokens[$newline]['code'], PHP_CodeSniffer_Tokens::$commentTokens) === true) {
$hasError = true;
}
}
 
if ($newline === $stackPtr) {
$next = ($stackPtr + 1);
} else {
// Check that there were no significant tokens that we
// skipped over to find our newline character.
$next = $phpcsFile->findNext(
$ignoreTokens,
$stackPtr,
null,
true
);
 
if ($next < $newline) {
// We skipped a non-ignored token.
$hasError = true;
} else {
$next = ($newline + 1);
}
}
}//end if
 
if ($stackPtr !== $lastAddedStackPtr) {
$found .= $phpcsFile->getTokensAsString(
$stackPtr,
($next - $stackPtr)
);
 
$diff = ($next - $stackPtr);
$lastAddedStackPtr = ($next - 1);
}
 
$stackPtr = $next;
}//end if
}//end for
 
if ($hasError === true) {
$error = $this->prepareError($found, $patternCode);
$errors[$origStackPtr] = $error;
}
 
return $errors;
 
}//end processPattern()
 
 
/**
* Prepares an error for the specified patternCode.
*
* @param string $found The actual found string in the code.
* @param string $patternCode The expected pattern code.
*
* @return string The error message.
*/
protected function prepareError($found, $patternCode)
{
$found = str_replace("\r\n", '\n', $found);
$found = str_replace("\n", '\n', $found);
$found = str_replace("\r", '\n', $found);
$found = str_replace('EOL', '\n', $found);
$expected = str_replace('EOL', '\n', $patternCode);
 
$error = "Expected \"$expected\"; found \"$found\"";
 
return $error;
 
}//end prepareError()
 
 
/**
* Returns the patterns that should be checked.
*
* @return array(string)
*/
protected abstract function getPatterns();
 
 
/**
* Registers any supplementary tokens that this test might wish to process.
*
* A sniff may wish to register supplementary tests when it wishes to group
* an arbitary validation that cannot be performed using a pattern, with
* other pattern tests.
*
* @return array(int)
* @see processSupplementary()
*/
protected function registerSupplementary()
{
return array();
 
}//end registerSupplementary()
 
 
/**
* Processes any tokens registered with registerSupplementary().
*
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where to
* process the skip.
* @param int $stackPtr The position in the tokens stack to
* process.
*
* @return void
* @see registerSupplementary()
*/
protected function processSupplementary(
PHP_CodeSniffer_File $phpcsFile,
$stackPtr
) {
return;
 
}//end processSupplementary()
 
 
/**
* Parses a pattern string into an array of pattern steps.
*
* @param string $pattern The pattern to parse.
*
* @return array The parsed pattern array.
* @see _createSkipPattern()
* @see _createTokenPattern()
*/
private function _parse($pattern)
{
$patterns = array();
$length = strlen($pattern);
$lastToken = 0;
$firstToken = 0;
 
for ($i = 0; $i < $length; $i++) {
 
$specialPattern = false;
$isLastChar = ($i === ($length - 1));
$oldFirstToken = $firstToken;
 
if (substr($pattern, $i, 3) === '...') {
// It's a skip pattern. The skip pattern requires the
// content of the token in the "from" position and the token
// to skip to.
$specialPattern = $this->_createSkipPattern($pattern, ($i - 1));
$lastToken = ($i - $firstToken);
$firstToken = ($i + 3);
$i = ($i + 3);
 
if ($specialPattern['to'] !== 'unknown') {
$firstToken++;
}
} else if (substr($pattern, $i, 3) === 'abc') {
$specialPattern = array('type' => 'string');
$lastToken = ($i - $firstToken);
$firstToken = ($i + 3);
$i = ($i + 2);
} else if (substr($pattern, $i, 3) === 'EOL') {
$specialPattern = array('type' => 'newline');
$lastToken = ($i - $firstToken);
$firstToken = ($i + 3);
$i = ($i + 2);
}
 
if ($specialPattern !== false || $isLastChar === true) {
 
// If we are at the end of the string, don't worry about a limit.
if ($isLastChar === true) {
// Get the string from the end of the last skip pattern, if any,
// to the end of the pattern string.
$str = substr($pattern, $oldFirstToken);
} else {
// Get the string from the end of the last special pattern,
// if any, to the start of this special pattern.
$str = substr($pattern, $oldFirstToken, $lastToken);
}
 
$tokenPatterns = $this->_createTokenPattern($str);
 
// Make sure we don't skip the last token.
if ($isLastChar === false && $i === ($length - 1)) {
$i--;
}
 
foreach ($tokenPatterns as $tokenPattern) {
$patterns[] = $tokenPattern;
}
}//end if
 
// Add the skip pattern *after* we have processed
// all the tokens from the end of the last skip pattern
// to the start of this skip pattern.
if ($specialPattern !== false) {
$patterns[] = $specialPattern;
}
 
}//end for
 
return $patterns;
 
}//end _parse()
 
 
/**
* Creates a skip pattern.
*
* @param string $pattern The pattern being parsed.
* @param string $from The token content that the skip pattern starts from.
*
* @return array The pattern step.
* @see _createTokenPattern()
* @see _parse()
*/
private function _createSkipPattern($pattern, $from)
{
$skip = array('type' => 'skip');
 
$nestedParenthesis = 0;
for ($start = $from; $start >= 0; $start--) {
switch ($pattern[$start]) {
case '(':
if ($nestedParenthesis === 0) {
$skip['to'] = 'parenthesis_closer';
}
 
$nestedParenthesis--;
break;
case '{':
$skip['to'] = 'scope_closer';
break;
case ')':
$nestedParenthesis++;
break;
}
 
if (isset($skip['to']) === true) {
break;
}
}
 
if (isset($skip['to']) === false) {
$skip['to'] = 'unknown';
}
 
return $skip;
 
}//end _createSkipPattern()
 
 
/**
* Creates a token pattern.
*
* @param string $str The tokens string that the pattern should match.
*
* @return array The pattern step.
* @see _createSkipPattern()
* @see _parse()
*/
private function _createTokenPattern($str)
{
// Don't add a space after the closing php tag as it will add a new
// whitespace token.
$tokens = token_get_all('<?php '.$str.'?>');
 
// Remove the <?php tag from the front and the end php tag from the back.
$tokens = array_slice($tokens, 1, (count($tokens) - 2));
 
foreach ($tokens as &$token) {
$token = PHP_CodeSniffer::standardiseToken($token);
}
 
$patterns = array();
foreach ($tokens as $patternInfo) {
$patterns[] = array(
'type' => 'token',
'token' => $patternInfo['code'],
'value' => $patternInfo['content'],
);
}
 
return $patterns;
 
}//end _createTokenPattern()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Standards/PHPCS/PHPCSCodingStandard.php
New file
0,0 → 1,85
<?php
/**
* PHP_CodeSniffer Coding Standard.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: PHPCSCodingStandard.php,v 1.10 2008/12/12 04:06:01 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_Standards_CodingStandard', true) === false) {
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_CodingStandard not found');
}
 
/**
* PHP_CodeSniffer Coding Standard.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Standards_PHPCS_PHPCSCodingStandard extends PHP_CodeSniffer_Standards_CodingStandard
{
 
 
/**
* Return a list of external sniffs to include with this standard.
*
* The PHP_CodeSniffer standard combines the PEAR and Squiz standards
* but removes some sniffs from the Squiz standard that clash with
* those in the PEAR standard.
*
* @return array
*/
public function getIncludedSniffs()
{
return array(
'PEAR',
'Squiz',
);
 
}//end getIncludedSniffs()
 
 
/**
* Return a list of external sniffs to exclude from this standard.
*
* The PHP_CodeSniffer standard combines the PEAR and Squiz standards
* but removes some sniffs from the Squiz standard that clash with
* those in the PEAR standard.
*
* @return array
*/
public function getExcludedSniffs()
{
return array(
'Squiz/Sniffs/Classes/ClassFileNameSniff.php',
'Squiz/Sniffs/Classes/ValidClassNameSniff.php',
'Squiz/Sniffs/Commenting/ClassCommentSniff.php',
'Squiz/Sniffs/Commenting/FileCommentSniff.php',
'Squiz/Sniffs/Commenting/FunctionCommentSniff.php',
'Squiz/Sniffs/Commenting/VariableCommentSniff.php',
'Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php',
'Squiz/Sniffs/Files/FileExtensionSniff.php',
'Squiz/Sniffs/Files/LineLengthSniff.php',
'Squiz/Sniffs/NamingConventions/ConstantCaseSniff.php',
'Squiz/Sniffs/WhiteSpace/ScopeIndentSniff.php',
);
 
}//end getExcludedSniffs()
 
 
}//end class
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Exception.php
New file
0,0 → 1,36
<?php
/**
* An exception thrown by PHP_CodeSniffer when it encounters an unrecoverable error.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: Exception.php,v 1.3 2006/12/11 23:43:39 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
require_once 'PEAR/Exception.php';
 
/**
* An exception thrown by PHP_CodeSniffer when it encounters an unrecoverable error.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Exception extends PEAR_Exception
{
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/File.php
New file
0,0 → 1,2287
<?php
/**
* A PHP_CodeSniffer_File object represents a PHP source file and the tokens
* associated with it.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: File.php,v 1.82 2009/02/24 04:43:06 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* A PHP_CodeSniffer_File object represents a PHP source file and the tokens
* associated with it.
*
* It provides a means for traversing the token stack, along with
* other token related operations. If a PHP_CodeSniffer_Sniff finds and error or
* warning within a PHP_CodeSniffer_File, you can raise an error using the
* addError() or addWarning() methods.
*
* <b>Token Information</b>
*
* Each token within the stack contains information about itself:
*
* <code>
* array(
* 'code' => 301, // the token type code (see token_get_all())
* 'content' => 'if', // the token content
* 'type' => 'T_IF', // the token name
* 'line' => 56, // the line number when the token is located
* 'column' => 12, // the column in the line where this token
* // starts (starts from 1)
* 'level' => 2 // the depth a token is within the scopes open
* 'conditions' => array( // a list of scope condition token
* // positions => codes that
* 2 => 50, // openened the scopes that this token exists
* 9 => 353, // in (see conditional tokens section below)
* ),
* );
* </code>
*
* <b>Conditional Tokens</b>
*
* In addition to the standard token fields, conditions contain information to
* determine where their scope begins and ends:
*
* <code>
* array(
* 'scope_condition' => 38, // the token position of the condition
* 'scope_opener' => 41, // the token position that started the scope
* 'scope_closer' => 70, // the token position that ended the scope
* );
* </code>
*
* The condition, the scope opener and the scope closer each contain this
* information.
*
* <b>Parenthesis Tokens</b>
*
* Each parenthesis token (T_OPEN_PARENTHESIS and T_CLOSE_PARENTHESIS) has a
* reference to their opening and closing parenthesis, one being itself, the
* other being its oposite.
*
* <code>
* array(
* 'parenthesis_opener' => 34,
* 'parenthesis_closer' => 40,
* );
* </code>
*
* Some tokens can "own" a set of parethesis. For example a T_FUNCTION token
* has parenthesis around its argument list. These tokens also have the
* parenthesis_opener and and parenthesis_closer indicies. Not all parethesis
* have owners, for example parenthesis used for arithmetic operations and
* function calls. The parenthesis tokens that have an owner have the following
* auxilery array indicies.
*
* <code>
* array(
* 'parenthesis_opener' => 34,
* 'parenthesis_closer' => 40,
* 'parenthesis_owner' => 33,
* );
* </code>
*
* Each token within a set of parenthesis also has an array indicy
* 'nested_parenthesis' which is an array of the
* left parenthesis => right parenthesis token positions.
*
* <code>
* 'nested_parentheisis' => array(
* 12 => 15
* 11 => 14
* );
* </code>
*
* <b>Extended Tokens</b>
*
* PHP_CodeSniffer extends and augments some of the tokens created by
* <i>token_get_all()</i>. A full list of these tokens can be seen in the
* <i>Tokens.php</i> file.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_File
{
 
/**
* The absolute path to the file associated with this object.
*
* @var string
*/
private $_file = '';
 
/**
* The EOL character this file uses.
*
* @var string
*/
public $eolChar = '';
 
/**
* The tokenizer being used for this file.
*
* @var object
*/
public $tokenizer = null;
 
/**
* The tokenizer being used for this file.
*
* @var string
*/
public $tokenizerType = 'PHP';
 
/**
* The number of tokens in this file.
*
* Stored here to save calling count() everywhere.
*
* @var int
*/
public $numTokens = 0;
 
/**
* The tokens stack map.
*
* Note that the tokens in this array differ in format to the tokens
* produced by token_get_all(). Tokens are initially produced with
* token_get_all(), then augmented so that it's easier to process them.
*
* @var array()
* @see Tokens.php
*/
private $_tokens = array();
 
/**
* The errors raised from PHP_CodeSniffer_Sniffs.
*
* @var array()
* @see getErrors()
*/
private $_errors = array();
 
/**
* The warnings raised form PHP_CodeSniffer_Sniffs.
*
* @var array()
* @see getWarnings()
*/
private $_warnings = array();
 
/**
* The total number of errors raised.
*
* @var int
*/
private $_errorCount = 0;
 
/**
* The total number of warnings raised.
*
* @var int
*/
private $_warningCount = 0;
 
/**
* An array of sniffs listening to this file's processing.
*
* @var array(PHP_CodeSniffer_Sniff)
*/
private $_listeners = array();
 
/**
* The class name of the sniff currently processing the file.
*
* @var string
*/
private $_activeListener = '';
 
/**
* A constant to represent an error in PHP_CodeSniffer.
*
* @var int
*/
const ERROR = 0;
 
/**
* A constant to represent a warning in PHP_CodeSniffer.
*
* @var int
*/
const WARNING = 1;
 
/**
* An array of extensions mapping to the tokenizer to use.
*
* This value gets set by PHP_CodeSniffer when the object is created.
*
* @var array
*/
protected $tokenizers = array();
 
 
/**
* Constructs a PHP_CodeSniffer_File.
*
* @param string $file The absolute path to the file
* to process.
* @param array(string) $listeners The initial listeners listening
* to processing of this file.
* @param array $tokenizers An array of extensions mapping
* to the tokenizer to use.
*
* @throws PHP_CodeSniffer_Exception If the register() method does
* not return an array.
*/
public function __construct($file, array $listeners, array $tokenizers)
{
$this->_file = trim($file);
$this->_listeners = $listeners;
$this->tokenizers = $tokenizers;
 
}//end __construct()
 
 
/**
* Sets the name of the currently active sniff.
*
* @param string $activeListener The class name of the current sniff.
*
* @return void
*/
public function setActiveListener($activeListener)
{
$this->_activeListener = $activeListener;
 
}//end setActiveListener()
 
 
/**
* Adds a listener to the token stack that listens to the specific tokens.
*
* When PHP_CodeSniffer encounters on the the tokens specified in $tokens, it
* invokes the process method of the sniff.
*
* @param PHP_CodeSniffer_Sniff $listener The listener to add to the
* listener stack.
* @param array(int) $tokens The token types the listener wishes to
* listen to.
*
* @return void
*/
public function addTokenListener(PHP_CodeSniffer_Sniff $listener, array $tokens)
{
foreach ($tokens as $token) {
if (isset($this->_listeners[$token]) === false) {
$this->_listeners[$token] = array();
}
 
if (in_array($listener, $this->_listeners[$token], true) === false) {
$this->_listeners[$token][] = $listener;
}
}
 
}//end addTokenListener()
 
 
/**
* Removes a listener from listening from the specified tokens.
*
* @param PHP_CodeSniffer_Sniff $listener The listener to remove from the
* listener stack.
* @param array(int) $tokens The token types the listener wishes to
* stop listen to.
*
* @return void
*/
public function removeTokenListener(
PHP_CodeSniffer_Sniff $listener,
array $tokens
) {
foreach ($tokens as $token) {
if (isset($this->_listeners[$token]) === false) {
continue;
}
 
if (in_array($listener, $this->_listeners[$token]) === true) {
foreach ($this->_listeners[$token] as $pos => $value) {
if ($value === $listener) {
unset($this->_listeners[$token][$pos]);
}
}
}
}
 
}//end removeTokenListener()
 
 
/**
* Returns the token stack for this file.
*
* @return array()
*/
public function getTokens()
{
return $this->_tokens;
 
}//end getTokens()
 
 
/**
* Starts the stack traversal and tells listeners when tokens are found.
*
* @param string $contents The contents to parse. If NULL, the content
* is taken from the file system.
*
* @return void
*/
public function start($contents=null)
{
$this->_parse($contents);
 
if (PHP_CODESNIFFER_VERBOSITY > 2) {
echo "\t*** START TOKEN PROCESSING ***".PHP_EOL;
}
 
// Foreach of the listeners that have registed to listen for this
// token, get them to process it.
foreach ($this->_tokens as $stackPtr => $token) {
if (PHP_CODESNIFFER_VERBOSITY > 2) {
$type = $token['type'];
$content = str_replace($this->eolChar, '\n', $token['content']);
echo "\t\tProcess token $stackPtr: $type => $content".PHP_EOL;
}
 
$tokenType = $token['code'];
if (isset($this->_listeners[$tokenType]) === true) {
foreach ($this->_listeners[$tokenType] as $listener) {
// Make sure this sniff supports the tokenizer
// we are currently using.
$vars = get_class_vars(get_class($listener));
if (isset($vars['supportedTokenizers']) === true) {
if (in_array($this->tokenizerType, $vars['supportedTokenizers']) === false) {
continue;
}
} else {
// The default supported tokenizer is PHP.
if ($this->tokenizerType !== 'PHP') {
continue;
}
}
 
$this->setActiveListener(get_class($listener));
 
if (PHP_CODESNIFFER_VERBOSITY > 2) {
$startTime = microtime(true);
echo "\t\t\tProcessing ".$this->_activeListener.'... ';
}
 
$listener->process($this, $stackPtr);
$this->_activeListener = '';
 
if (PHP_CODESNIFFER_VERBOSITY > 2) {
$timeTaken = round((microtime(true) - $startTime), 4);
echo "DONE in $timeTaken seconds".PHP_EOL;
}
}//end foreach
}//end if
}//end foreach
 
if (PHP_CODESNIFFER_VERBOSITY > 2) {
echo "\t*** END TOKEN PROCESSING ***".PHP_EOL;
}
 
}//end start()
 
 
/**
* Remove vars stored in this sniff that are no longer required.
*
* @return void
*/
public function cleanUp()
{
$this->_tokens = null;
$this->_listeners = null;
 
}//end cleanUp()
 
 
/**
* Tokenizes the file and preapres it for the test run.
*
* @param string $contents The contents to parse. If NULL, the content
* is taken from the file system.
*
* @return void
*/
private function _parse($contents=null)
{
$this->eolChar = self::detectLineEndings($this->_file, $contents);
 
// Determine the tokenizer from the file extension.
$fileParts = explode('.', $this->_file);
$extension = array_pop($fileParts);
if (isset($this->tokenizers[$extension]) === true) {
$tokenizerClass = 'PHP_CodeSniffer_Tokenizers_'.$this->tokenizers[$extension];
$this->tokenizerType = $this->tokenizers[$extension];
} else {
// Revert to default.
$tokenizerClass = 'PHP_CodeSniffer_Tokenizers_'.$this->tokenizerType;
}
 
$tokenizer = new $tokenizerClass();
$this->tokenizer = $tokenizer;
 
if ($contents === null) {
$contents = file_get_contents($this->_file);
}
 
$this->_tokens = self::tokenizeString($contents, $tokenizer, $this->eolChar);
$this->numTokens = count($this->_tokens);
 
if (PHP_CODESNIFFER_VERBOSITY > 0) {
if ($this->numTokens === 0) {
$numLines = 0;
} else {
$numLines = $this->_tokens[($this->numTokens - 1)]['line'];
}
 
echo "[$this->numTokens tokens in $numLines lines]... ";
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo PHP_EOL;
}
}
 
}//end _parse()
 
 
/**
* Opens a file and detects the EOL character being used.
*
* @param string $file The full path to the file.
* @param string $contents The contents to parse. If NULL, the content
* is taken from the file system.
*
* @return string
* @throws PHP_CodeSniffer_Exception If $file could not be opened.
*/
public static function detectLineEndings($file, $contents=null)
{
if ($contents === null) {
// Determine the newline character being used in this file.
// Will be either \r, \r\n or \n.
$handle = fopen($file, 'r');
if ($handle === false) {
$error = 'Error opening file; could not auto-detect line endings';
throw new PHP_CodeSniffer_Exception($error);
}
 
$firstLine = fgets($handle);
fclose($handle);
 
$eolChar = substr($firstLine, -1);
if ($eolChar === "\n") {
$secondLastChar = substr($firstLine, -2, 1);
if ($secondLastChar === "\r") {
$eolChar = "\r\n";
}
}
} else {
if (preg_match("/\r\n?|\n/", $contents, $matches) !== 1) {
$error = 'Could not auto-detect line endings from content';
throw new PHP_CodeSniffer_Exception($error);
}
 
$eolChar = $matches[0];
}//end if
 
return $eolChar;
 
}//end detectLineEndings()
 
 
/**
* Adds an error to the error stack.
*
* @param string $error The error message.
* @param int $stackPtr The stack position where the error occured.
*
* @return void
*/
public function addError($error, $stackPtr)
{
// Work out which sniff generated the error.
$parts = explode('_', $this->_activeListener);
$sniff = $parts[0].'.'.$parts[2].'.'.$parts[3];
 
if ($stackPtr === null) {
$lineNum = 1;
$column = 1;
} else {
$lineNum = $this->_tokens[$stackPtr]['line'];
$column = $this->_tokens[$stackPtr]['column'];
}
 
if (isset($this->_errors[$lineNum]) === false) {
$this->errors[$lineNum] = array();
}
 
if (isset($this->_errors[$lineNum][$column]) === false) {
$this->errors[$lineNum][$column] = array();
}
 
$this->_errors[$lineNum][$column][] = array(
'message' => $error,
'source' => $sniff,
);
$this->_errorCount++;
 
}//end addError()
 
 
/**
* Adds an warning to the warning stack.
*
* @param string $warning The error message.
* @param int $stackPtr The stack position where the error occured.
*
* @return void
*/
public function addWarning($warning, $stackPtr)
{
// Work out which sniff generated the warning.
$parts = explode('_', $this->_activeListener);
$sniff = $parts[0].'.'.$parts[2].'.'.$parts[3];
 
if ($stackPtr === null) {
$lineNum = 1;
$column = 1;
} else {
$lineNum = $this->_tokens[$stackPtr]['line'];
$column = $this->_tokens[$stackPtr]['column'];
}
 
if (isset($this->_warnings[$lineNum]) === false) {
$this->_warnings[$lineNum] = array();
}
 
if (isset($this->_warnings[$lineNum][$column]) === false) {
$this->_warnings[$lineNum][$column] = array();
}
 
$this->_warnings[$lineNum][$column][] = array(
'message' => $warning,
'source' => $sniff,
);
$this->_warningCount++;
 
}//end addWarning()
 
 
/**
* Returns the number of errors raised.
*
* @return int
*/
public function getErrorCount()
{
return $this->_errorCount;
 
}//end getErrorCount()
 
 
/**
* Returns the number of warnings raised.
*
* @return int
*/
public function getWarningCount()
{
return $this->_warningCount;
 
}//end getWarningCount()
 
 
/**
* Returns the errors raised from processing this file.
*
* @return array
*/
public function getErrors()
{
return $this->_errors;
 
}//end getErrors()
 
 
/**
* Returns the warnings raised from processing this file.
*
* @return array
*/
public function getWarnings()
{
return $this->_warnings;
 
}//end getWarnings()
 
 
/**
* Returns the absolute filename of this file.
*
* @return string
*/
public function getFilename()
{
return $this->_file;
 
}//end getFilename()
 
 
/**
* Creates an array of tokens when given some PHP code.
*
* Starts by using token_get_all() but does a lot of extra processing
* to insert information about the context of the token.
*
* @param string $string The string to tokenize.
* @param object $tokenizer A tokenizer class to use to tokenize the string.
* @param string $eolChar The EOL character to use for splitting strings.
*
* @return array
*/
public static function tokenizeString($string, $tokenizer, $eolChar='\n')
{
$tokens = $tokenizer->tokenizeString($string, $eolChar);
 
self::_createLineMap($tokens, $tokenizer, $eolChar);
self::_createBracketMap($tokens, $tokenizer, $eolChar);
self::_createParenthesisMap($tokens, $tokenizer, $eolChar);
self::_createParenthesisNestingMap($tokens, $tokenizer, $eolChar);
self::_createScopeMap($tokens, $tokenizer, $eolChar);
 
// If we know the width of each tab, convert tabs
// into spaces so sniffs can use one method of checking.
if (PHP_CODESNIFFER_TAB_WIDTH > 0) {
self::_convertTabs($tokens, $tokenizer, $eolChar);
}
 
// Column map requires the line map to be complete.
self::_createColumnMap($tokens, $tokenizer, $eolChar);
self::_createLevelMap($tokens, $tokenizer, $eolChar);
 
// Allow the tokenizer to do additional processing if required.
$tokenizer->processAdditional($tokens, $eolChar);
 
return $tokens;
 
}//end tokenizeString()
 
 
/**
* Creates a map of tokens => line numbers for each token.
*
* @param array &$tokens The array of tokens to process.
* @param object $tokenizer The tokenizer being used to process this file.
* @param string $eolChar The EOL character to use for splitting strings.
*
* @return void
*/
private static function _createLineMap(&$tokens, $tokenizer, $eolChar)
{
$lineNumber = 1;
$count = count($tokens);
 
for ($i = 0; $i < $count; $i++) {
$tokens[$i]['line'] = $lineNumber;
if ($tokens[$i]['content'] === '') {
continue;
}
 
$lineNumber += substr_count($tokens[$i]['content'], $eolChar);
}
 
}//end _createLineMap()
 
 
/**
* Converts tabs into spaces.
*
* Each tab can represent between 1 and $width spaces, so
* this cannot be a straight string replace.
*
* @param array &$tokens The array of tokens to process.
* @param object $tokenizer The tokenizer being used to process this file.
* @param string $eolChar The EOL character to use for splitting strings.
*
* @return void
*/
private static function _convertTabs(&$tokens, $tokenizer, $eolChar)
{
$currColumn = 1;
$count = count($tokens);
 
for ($i = 0; $i < $count; $i++) {
$tokenContent = $tokens[$i]['content'];
 
if (strpos($tokenContent, "\t") === false) {
// There are no tabs in this content.
$currColumn += (strlen($tokenContent) - 1);
} else {
// We need to determine the length of each tab.
$tabs = preg_split(
"|(\t)|",
$tokenContent,
-1,
PREG_SPLIT_DELIM_CAPTURE
);
 
$tabNum = 0;
$adjustedTab = false;
$tabsToSpaces = array();
$newContent = '';
 
foreach ($tabs as $content) {
if ($content === '') {
continue;
}
 
if (strpos($content, "\t") === false) {
// This piece of content is not a tab.
$currColumn += strlen($content);
$newContent .= $content;
} else {
$lastCurrColumn = $currColumn;
$tabNum++;
 
// Move the pointer to the next tab stop.
if (($currColumn % PHP_CODESNIFFER_TAB_WIDTH) === 0) {
// This is the first tab, and we are already at a
// tab stop, so this tab counts as a single space.
$currColumn++;
$adjustedTab = true;
} else {
$currColumn++;
while (($currColumn % PHP_CODESNIFFER_TAB_WIDTH) != 0) {
$currColumn++;
}
 
$currColumn++;
}
 
$length = ($currColumn - $lastCurrColumn);
$newContent .= str_repeat(' ', $length);
}//end if
}//end foreach
 
if ($tabNum === 1 && $adjustedTab === true) {
$currColumn--;
}
 
$tokens[$i]['content'] = $newContent;
}//end if
 
if (isset($tokens[($i + 1)]['line']) === true
&& $tokens[($i + 1)]['line'] !== $tokens[$i]['line']
) {
$currColumn = 1;
} else {
$currColumn++;
}
}//end for
 
}//end _convertTabs()
 
 
/**
* Creates a column map.
*
* The column map indicates where the token started on the line where it
* exists.
*
* @param array &$tokens The array of tokens to process.
* @param object $tokenizer The tokenizer being used to process this file.
* @param string $eolChar The EOL character to use for splitting strings.
*
* @return void
*/
private static function _createColumnMap(&$tokens, $tokenizer, $eolChar)
{
$currColumn = 1;
$count = count($tokens);
 
for ($i = 0; $i < $count; $i++) {
$tokens[$i]['column'] = $currColumn;
if (isset($tokens[($i + 1)]['line']) === true
&& $tokens[($i + 1)]['line'] !== $tokens[$i]['line']
) {
$currColumn = 1;
} else {
$currColumn += strlen($tokens[$i]['content']);
}
}
 
}//end _createColumnMap()
 
 
/**
* Creates a map for opening and closing of square brackets.
*
* Each bracket token (T_OPEN_SQUARE_BRACKET and T_CLOSE_SQUARE_BRACKET)
* has a reference to their opening and closing bracket
* (bracket_opener and bracket_closer).
*
* @param array &$tokens The array of tokens to process.
* @param object $tokenizer The tokenizer being used to process this file.
* @param string $eolChar The EOL character to use for splitting strings.
*
* @return void
*/
private static function _createBracketMap(&$tokens, $tokenizer, $eolChar)
{
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t*** START BRACKET MAP ***".PHP_EOL;
}
 
$squareOpeners = array();
$curlyOpeners = array();
$numTokens = count($tokens);
 
for ($i = 0; $i < $numTokens; $i++) {
switch ($tokens[$i]['code']) {
case T_OPEN_SQUARE_BRACKET:
$squareOpeners[] = $i;
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", count($squareOpeners));
echo str_repeat("\t", count($curlyOpeners));
echo "=> Found square bracket opener at $i".PHP_EOL;
}
 
break;
case T_OPEN_CURLY_BRACKET:
if (isset($tokens[$i]['scope_closer']) === false) {
$curlyOpeners[] = $i;
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", count($squareOpeners));
echo str_repeat("\t", count($curlyOpeners));
echo "=> Found curly bracket opener at $i".PHP_EOL;
}
}
break;
case T_CLOSE_SQUARE_BRACKET:
if (empty($squareOpeners) === false) {
$opener = array_pop($squareOpeners);
$tokens[$i]['bracket_opener'] = $opener;
$tokens[$i]['bracket_closer'] = $i;
$tokens[$opener]['bracket_opener'] = $opener;
$tokens[$opener]['bracket_closer'] = $i;
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", count($squareOpeners));
echo str_repeat("\t", count($curlyOpeners));
echo "\t=> Found square bracket closer at $i for $opener".PHP_EOL;
}
}
break;
case T_CLOSE_CURLY_BRACKET:
if (empty($curlyOpeners) === false
&& isset($tokens[$i]['scope_opener']) === false
) {
$opener = array_pop($curlyOpeners);
$tokens[$i]['bracket_opener'] = $opener;
$tokens[$i]['bracket_closer'] = $i;
$tokens[$opener]['bracket_opener'] = $opener;
$tokens[$opener]['bracket_closer'] = $i;
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", count($squareOpeners));
echo str_repeat("\t", count($curlyOpeners));
echo "\t=> Found curly bracket closer at $i for $opener".PHP_EOL;
}
}
break;
default:
continue;
}//end switch
}//end for
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t*** END BRACKET MAP ***".PHP_EOL;
}
 
}//end _createBracketMap()
 
 
/**
* Creates a map for opening and closing of parenthesis.
*
* Each parenthesis token (T_OPEN_PARENTHESIS and T_CLOSE_PARENTHESIS) has a
* reference to their opening and closing parenthesis (parenthesis_opener
* and parenthesis_closer).
*
* @param array &$tokens The array of tokens to process.
* @param object $tokenizer The tokenizer being used to process this file.
* @param string $eolChar The EOL character to use for splitting strings.
*
* @return void
*/
private static function _createParenthesisMap(&$tokens, $tokenizer, $eolChar)
{
$openers = array();
$numTokens = count($tokens);
$openOwner = null;
 
for ($i = 0; $i < $numTokens; $i++) {
if (in_array($tokens[$i]['code'], PHP_CodeSniffer_Tokens::$parenthesisOpeners) === true) {
$tokens[$i]['parenthesis_opener'] = null;
$tokens[$i]['parenthesis_closer'] = null;
$tokens[$i]['parenthesis_owner'] = $i;
$openOwner = $i;
} else if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS) {
$openers[] = $i;
$tokens[$i]['parenthesis_opener'] = $i;
if ($openOwner !== null) {
$tokens[$openOwner]['parenthesis_opener'] = $i;
$tokens[$i]['parenthesis_owner'] = $openOwner;
$openOwner = null;
}
} else if ($tokens[$i]['code'] === T_CLOSE_PARENTHESIS) {
// Did we set an owner for this set of parenthesis?
$numOpeners = count($openers);
if ($numOpeners !== 0) {
$opener = array_pop($openers);
if (isset($tokens[$opener]['parenthesis_owner']) === true) {
$owner = $tokens[$opener]['parenthesis_owner'];
 
$tokens[$owner]['parenthesis_closer'] = $i;
$tokens[$i]['parenthesis_owner'] = $owner;
}
 
$tokens[$i]['parenthesis_opener'] = $opener;
$tokens[$i]['parenthesis_closer'] = $i;
$tokens[$opener]['parenthesis_closer'] = $i;
}
}//end if
}//end for
 
}//end _createParenthesisMap()
 
 
/**
* Creates a map for the parenthesis tokens that surround other tokens.
*
* @param array &$tokens The array of tokens to process.
* @param object $tokenizer The tokenizer being used to process this file.
* @param string $eolChar The EOL character to use for splitting strings.
*
* @return void
*/
private static function _createParenthesisNestingMap(
&$tokens,
$tokenizer,
$eolChar
) {
$numTokens = count($tokens);
$map = array();
for ($i = 0; $i < $numTokens; $i++) {
if (isset($tokens[$i]['parenthesis_opener']) === true
&& $i === $tokens[$i]['parenthesis_opener']
) {
if (empty($map) === false) {
$tokens[$i]['nested_parenthesis'] = $map;
}
 
if (isset($tokens[$i]['parenthesis_closer']) === true) {
$map[$tokens[$i]['parenthesis_opener']]
= $tokens[$i]['parenthesis_closer'];
}
} else if (isset($tokens[$i]['parenthesis_closer']) === true
&& $i === $tokens[$i]['parenthesis_closer']
) {
array_pop($map);
if (empty($map) === false) {
$tokens[$i]['nested_parenthesis'] = $map;
}
} else {
if (empty($map) === false) {
$tokens[$i]['nested_parenthesis'] = $map;
}
}
}//end for
 
}//end _createParenthesisNestingMap()
 
 
/**
* Creates a scope map of tokens that open scopes.
*
* @param array &$tokens The array of tokens to process.
* @param object $tokenizer The tokenizer being used to process this file.
* @param string $eolChar The EOL character to use for splitting strings.
*
* @return void
* @see _recurseScopeMap()
*/
private static function _createScopeMap(&$tokens, $tokenizer, $eolChar)
{
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t*** START SCOPE MAP ***".PHP_EOL;
}
 
$numTokens = count($tokens);
for ($i = 0; $i < $numTokens; $i++) {
// Check to see if the current token starts a new scope.
if (isset($tokenizer->scopeOpeners[$tokens[$i]['code']]) === true) {
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$i]['type'];
$content = str_replace($eolChar, '\n', $tokens[$i]['content']);
echo "\tStart scope map at $i: $type => $content".PHP_EOL;
}
 
$i = self::_recurseScopeMap(
$tokens,
$numTokens,
$tokenizer,
$eolChar,
$i
);
}
}//end for
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t*** END SCOPE MAP ***".PHP_EOL;
}
 
}//end _createScopeMap()
 
 
/**
* Recurses though the scope openers to build a scope map.
*
* @param array &$tokens The array of tokens to process.
* @param int $numTokens The size of the tokens array.
* @param object $tokenizer The tokenizer being used to process this file.
* @param string $eolChar The EOL character to use for splitting strings.
* @param int $stackPtr The position in the stack of the token that
* opened the scope (eg. an IF token or FOR token).
* @param int $depth How many scope levels down we are.
* @param int &$ignore How many curly braces we are ignoring.
*
* @return int The position in the stack that closed the scope.
*/
private static function _recurseScopeMap(
&$tokens,
$numTokens,
$tokenizer,
$eolChar,
$stackPtr,
$depth=1,
&$ignore=0
) {
$opener = null;
$currType = $tokens[$stackPtr]['code'];
$startLine = $tokens[$stackPtr]['line'];
 
// If the start token for this scope opener is the same as
// the scope token, we have already found our opener.
if ($currType === $tokenizer->scopeOpeners[$currType]['start']) {
$opener = $stackPtr;
}
 
for ($i = ($stackPtr + 1); $i < $numTokens; $i++) {
$tokenType = $tokens[$i]['code'];
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$i]['type'];
$content = str_replace($eolChar, '\n', $tokens[$i]['content']);
echo str_repeat("\t", $depth);
echo "Process token $i [";
if ($opener !== null) {
echo "opener:$opener;";
}
 
if ($ignore > 0) {
echo "ignore=$ignore;";
}
 
echo "]: $type => $content".PHP_EOL;
}
 
// Is this an opening condition ?
if (isset($tokenizer->scopeOpeners[$tokenType]) === true) {
if ($opener === null) {
// Found another opening condition but still haven't
// found our opener, so we are never going to find one.
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$stackPtr]['type'];
echo str_repeat("\t", $depth);
echo "=> Couldn't find scope opener for $stackPtr ($type), bailing".PHP_EOL;
}
 
return $stackPtr;
}
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", $depth);
echo '* token is an opening condition *'.PHP_EOL;
}
 
$isShared
= ($tokenizer->scopeOpeners[$tokenType]['shared'] === true);
 
if (isset($tokens[$i]['scope_condition']) === true) {
// We've been here before.
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", $depth);
echo '* already processed, skipping *'.PHP_EOL;
}
 
if ($isShared === false
&& isset($tokens[$i]['scope_closer']) === true
) {
$i = $tokens[$i]['scope_closer'];
}
 
continue;
} else if ($currType === $tokenType
&& $isShared === false
&& $opener === null
) {
// We haven't yet found our opener, but we have found another
// scope opener which is the same type as us, and we don't
// share openers, so we will never find one.
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", $depth);
echo '* it was another token\'s opener, bailing *'.PHP_EOL;
}
 
return $stackPtr;
} else {
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", $depth);
echo '* searching for opener *'.PHP_EOL;
}
 
if ($tokenizer->scopeOpeners[$tokenType]['end'] === T_CLOSE_CURLY_BRACKET) {
$oldIgnore = $ignore;
$ignore = 0;
}
 
$i = self::_recurseScopeMap(
$tokens,
$numTokens,
$tokenizer,
$eolChar,
$i,
($depth + 1),
$ignore
);
 
if ($tokenizer->scopeOpeners[$tokenType]['end'] === T_CLOSE_CURLY_BRACKET) {
$ignore = $oldIgnore;
}
}//end if
}//end if start scope
 
if ($tokenType === $tokenizer->scopeOpeners[$currType]['start']
&& $opener === null
) {
if ($tokenType === T_OPEN_CURLY_BRACKET) {
// Make sure this is actually an opener and not a
// string offset (e.g., $var{0}).
for ($x = ($i - 1); $x > 0; $x--) {
if (in_array($tokens[$x]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === true) {
continue;
} else {
// If the first non-whitespace/comment token is a
// variable or object operator then this is an opener
// for a string offset and not a scope.
if ($tokens[$x]['code'] === T_VARIABLE
|| $tokens[$x]['code'] === T_OBJECT_OPERATOR
) {
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", $depth);
echo '* ignoring curly brace *'.PHP_EOL;
}
 
$ignore++;
}//end if
 
break;
}//end if
}//end for
}//end if
 
if ($ignore === 0) {
// We found the opening scope token for $currType.
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$stackPtr]['type'];
echo str_repeat("\t", $depth);
echo "=> Found scope opener for $stackPtr ($type)".PHP_EOL;
}
 
$opener = $i;
}
} else if ($tokenType === $tokenizer->scopeOpeners[$currType]['end']
&& $opener !== null
) {
if ($ignore > 0 && $tokenType === T_CLOSE_CURLY_BRACKET) {
// The last opening bracket must have been for a string
// offset or alike, so let's ignore it.
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", $depth);
echo '* finished ignoring curly brace *'.PHP_EOL;
}
 
$ignore--;
} else {
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$stackPtr]['type'];
echo str_repeat("\t", $depth);
echo "=> Found scope closer for $stackPtr ($type)".PHP_EOL;
}
 
foreach (array($stackPtr, $opener, $i) as $token) {
$tokens[$token]['scope_condition'] = $stackPtr;
$tokens[$token]['scope_opener'] = $opener;
$tokens[$token]['scope_closer'] = $i;
}
 
if ($tokenizer->scopeOpeners[$tokens[$stackPtr]['code']]['shared'] === true) {
return $opener;
} else {
return $i;
}
}//end if
} else if ($tokenType === T_OPEN_PARENTHESIS) {
if (isset($tokens[$i]['parenthesis_owner']) === true) {
$owner = $tokens[$i]['parenthesis_owner'];
if (in_array($tokens[$owner]['code'], PHP_CodeSniffer_Tokens::$scopeOpeners) === true
&& isset($tokens[$i]['parenthesis_closer']) === true
) {
// If we get into here, then we opened a parenthesis for
// a scope (eg. an if or else if). We can just skip to
// the closing parenthesis.
$i = $tokens[$i]['parenthesis_closer'];
 
// Update the start of the line so that when we check to see
// if the closing parenthesis is more than 3 lines away from
// the statement, we check from the closing parenthesis.
$startLine
= $tokens[$tokens[$i]['parenthesis_closer']]['line'];
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", $depth);
echo '* skipping parenthesis *'.PHP_EOL;
}
}
}
} else if ($tokenType === T_OPEN_CURLY_BRACKET && $opener !== null) {
// We opened something that we don't have a scope opener for.
// Examples of this are curly brackets for string offsets etc.
// We want to ignore this so that we don't have an invalid scope
// map.
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", $depth);
echo '* ignoring curly brace *'.PHP_EOL;
}
 
$ignore++;
} else if ($opener === null
&& isset($tokenizer->scopeOpeners[$currType]) === true
) {
// If we still haven't found the opener after 3 lines,
// we're not going to find it, unless we know it requires
// an opener, in which case we better keep looking.
if ($tokens[$i]['line'] >= ($startLine + 3)) {
if ($tokenizer->scopeOpeners[$currType]['strict'] === true) {
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$stackPtr]['type'];
$lines = ($tokens[$i]['line'] - $startLine);
echo str_repeat("\t", $depth);
echo "=> Still looking for $stackPtr ($type) scope opener after $lines lines".PHP_EOL;
}
} else {
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$stackPtr]['type'];
echo str_repeat("\t", $depth);
echo "=> Couldn't find scope opener for $stackPtr ($type), bailing".PHP_EOL;
}
 
return $stackPtr;
}
}
} else if ($opener !== null
&& $tokenType !== T_BREAK
&& in_array($tokenType, $tokenizer->endScopeTokens) === true
) {
if (isset($tokens[$i]['scope_condition']) === false) {
if ($ignore > 0) {
// We found the end token for the opener we were ignoring.
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", $depth);
echo '* finished ignoring curly brace *'.PHP_EOL;
}
 
$ignore--;
} else {
// We found a token that closes the scope but it doesn't
// have a condition, so it belongs to another token and
// our token doesn't have a closer, so pretend this is
// the closer.
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$stackPtr]['type'];
echo str_repeat("\t", $depth);
echo "=> Found (unexpected) scope closer for $stackPtr ($type)".PHP_EOL;
}
 
foreach (array($stackPtr, $opener) as $token) {
$tokens[$token]['scope_condition'] = $stackPtr;
$tokens[$token]['scope_opener'] = $opener;
$tokens[$token]['scope_closer'] = $i;
}
 
return ($i - 1);
}//end if
}//end if
}//end if
}//end for
 
return $stackPtr;
 
}//end _recurseScopeMap()
 
 
/**
* Constructs the level map.
*
* The level map adds a 'level' indice to each token which indicates the
* depth that a token within a set of scope blocks. It also adds a
* 'condition' indice which is an array of the scope conditions that opened
* each of the scopes - position 0 being the first scope opener.
*
* @param array &$tokens The array of tokens to process.
* @param object $tokenizer The tokenizer being used to process this file.
* @param string $eolChar The EOL character to use for splitting strings.
*
* @return void
*/
private static function _createLevelMap(&$tokens, $tokenizer, $eolChar)
{
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t*** START LEVEL MAP ***".PHP_EOL;
}
 
$numTokens = count($tokens);
$level = 0;
$conditions = array();
$lastOpener = null;
$openers = array();
 
for ($i = 0; $i < $numTokens; $i++) {
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$i]['type'];
$line = $tokens[$i]['line'];
$content = str_replace($eolChar, '\n', $tokens[$i]['content']);
echo str_repeat("\t", ($level + 1));
echo "Process token $i on line $line [lvl:$level;";
if (empty($conditions) !== true) {
$condString = 'conds;';
foreach ($conditions as $condition) {
$condString .= token_name($condition).',';
}
 
echo rtrim($condString, ',').';';
}
 
echo "]: $type => $content".PHP_EOL;
}
 
$tokens[$i]['level'] = $level;
$tokens[$i]['conditions'] = $conditions;
 
if (isset($tokens[$i]['scope_condition']) === true) {
// Check to see if this token opened the scope.
if ($tokens[$i]['scope_opener'] === $i) {
$stackPtr = $tokens[$i]['scope_condition'];
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$stackPtr]['type'];
echo str_repeat("\t", ($level + 1));
echo "=> Found scope opener for $stackPtr ($type)".PHP_EOL;
}
 
$stackPtr = $tokens[$i]['scope_condition'];
 
// If we find a scope opener that has a shared closer,
// then we need to go back over the condition map that we
// just created and fix ourselves as we just added some
// conditions where there was none. This happens for T_CASE
// statements that are using the same break statement.
if ($lastOpener !== null && $tokens[$lastOpener]['scope_closer'] === $tokens[$i]['scope_closer']) {
// This opener shares its closer with the previous opener,
// but we still need to check if the two openers share their
// closer with each other directly (like CASE and DEFAULT)
// or if they are just sharing because one doesn't have a
// closer (like CASE with no BREAK using a SWITCHes closer).
$thisType = $tokens[$tokens[$i]['scope_condition']]['code'];
$opener = $tokens[$lastOpener]['scope_condition'];
 
$isShared = in_array(
$tokens[$opener]['code'],
$tokenizer->scopeOpeners[$thisType]['with']
);
 
$sameEnd = ($tokenizer->scopeOpeners[$thisType]['end'] === $tokenizer->scopeOpeners[$tokens[$opener]['code']]['end']);
if ($isShared === true && $sameEnd === true) {
$badToken = $opener;
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$badToken]['type'];
echo str_repeat("\t", ($level + 1));
echo "* shared closer, cleaning up $badToken ($type) *".PHP_EOL;
}
 
for ($x = $tokens[$i]['scope_condition']; $x <= $i; $x++) {
$oldConditions = $tokens[$x]['conditions'];
$oldLevel = $tokens[$x]['level'];
$tokens[$x]['level']--;
unset($tokens[$x]['conditions'][$badToken]);
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$x]['type'];
$oldConds = '';
foreach ($oldConditions as $condition) {
$oldConds .= token_name($condition).',';
}
 
$oldConds = rtrim($oldConds, ',');
 
$newConds = '';
foreach ($tokens[$x]['conditions'] as $condition) {
$newConds .= token_name($condition).',';
}
 
$newConds = rtrim($newConds, ',');
 
$newLevel = $tokens[$x]['level'];
echo str_repeat("\t", ($level + 1));
echo "* cleaned $x ($type) *".PHP_EOL;
echo str_repeat("\t", ($level + 2));
echo "=> level changed from $oldLevel to $newLevel".PHP_EOL;
echo str_repeat("\t", ($level + 2));
echo "=> conditions changed from $oldConds to $newConds".PHP_EOL;
}//end if
}//end for
 
unset($conditions[$badToken]);
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$badToken]['type'];
echo str_repeat("\t", ($level + 1));
echo "* token $badToken ($type) removed from conditions array *".PHP_EOL;
}
 
unset ($openers[$lastOpener]);
 
$level--;
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", ($level + 2));
echo '* level decreased *'.PHP_EOL;
}
}//end if
}//end if
 
$level++;
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", ($level + 1));
echo '* level increased *'.PHP_EOL;
}
 
$conditions[$stackPtr] = $tokens[$stackPtr]['code'];
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$stackPtr]['type'];
echo str_repeat("\t", ($level + 1));
echo "* token $stackPtr ($type) added to conditions array *".PHP_EOL;
}
 
$lastOpener = $tokens[$i]['scope_opener'];
if ($lastOpener !== null) {
$openers[$lastOpener] = $lastOpener;
}
} else if ($tokens[$i]['scope_closer'] === $i) {
foreach (array_reverse($openers) as $opener) {
if ($tokens[$opener]['scope_closer'] === $i) {
$oldOpener = array_pop($openers);
if (empty($openers) === false) {
$lastOpener = array_pop($openers);
$openers[$lastOpener] = $lastOpener;
} else {
$lastOpener = null;
}
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$oldOpener]['type'];
echo str_repeat("\t", ($level + 1));
echo "=> Found scope closer for $oldOpener ($type)".PHP_EOL;
}
 
$oldCondition = array_pop($conditions);
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", ($level + 1));
echo '* token '.token_name($oldCondition).' removed from conditions array *'.PHP_EOL;
}
 
// Make sure this closer actually belongs to us.
// Either the condition also has to think this is the
// closer, or it has to allow sharing with us.
$condition
= $tokens[$tokens[$i]['scope_condition']]['code'];
if ($condition !== $oldCondition) {
if (in_array($condition, $tokenizer->scopeOpeners[$oldCondition]['with']) === false) {
$badToken = $tokens[$oldOpener]['scope_condition'];
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = token_name($oldCondition);
echo str_repeat("\t", ($level + 1));
echo "* scope closer was bad, cleaning up $badToken ($type) *".PHP_EOL;
}
 
for ($x = ($oldOpener + 1); $x <= $i; $x++) {
$oldConditions = $tokens[$x]['conditions'];
$oldLevel = $tokens[$x]['level'];
$tokens[$x]['level']--;
unset($tokens[$x]['conditions'][$badToken]);
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$x]['type'];
$oldConds = '';
foreach ($oldConditions as $condition) {
$oldConds .= token_name($condition).',';
}
 
$oldConds = rtrim($oldConds, ',');
 
$newConds = '';
foreach ($tokens[$x]['conditions'] as $condition) {
$newConds .= token_name($condition).',';
}
 
$newConds = rtrim($newConds, ',');
 
$newLevel = $tokens[$x]['level'];
echo str_repeat("\t", ($level + 1));
echo "* cleaned $x ($type) *".PHP_EOL;
echo str_repeat("\t", ($level + 2));
echo "=> level changed from $oldLevel to $newLevel".PHP_EOL;
echo str_repeat("\t", ($level + 2));
echo "=> conditions changed from $oldConds to $newConds".PHP_EOL;
}//end if
}//end for
}//end if
}//end if
 
$level--;
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", ($level + 2));
echo '* level decreased *'.PHP_EOL;
}
 
$tokens[$i]['level'] = $level;
$tokens[$i]['conditions'] = $conditions;
}//end if
}//end foreach
}//end if
}//end if
}//end for
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t*** END LEVEL MAP ***".PHP_EOL;
}
 
}//end _createLevelMap()
 
 
/**
* Returns the declaration names for T_CLASS, T_INTERFACE and T_FUNCTION tokens.
*
* @param int $stackPtr The position of the declaration token which
* declared the class, interface or function.
*
* @return string The name of the class, interface or function.
* @throws PHP_CodeSniffer_Exception If the specified token is not of type
* T_FUNCTION, T_CLASS or T_INTERFACE.
*/
public function getDeclarationName($stackPtr)
{
$tokenCode = $this->_tokens[$stackPtr]['code'];
if ($tokenCode !== T_FUNCTION
&& $tokenCode !== T_CLASS
&& $tokenCode !== T_INTERFACE
) {
throw new PHP_CodeSniffer_Exception('Token type is not T_FUNCTION, T_CLASS OR T_INTERFACE');
}
 
$token = $this->findNext(T_STRING, $stackPtr);
return $this->_tokens[$token]['content'];
 
}//end getDeclarationName()
 
 
/**
* Returns the method parameters for the specified T_FUNCTION token.
*
* Each parameter is in the following format:
*
* <code>
* 0 => array(
* 'name' => '$var', // The variable name.
* 'pass_by_reference' => false, // Passed by reference.
* 'type_hint' => string, // Type hint for array or custom type
* )
* </code>
*
* Parameters with default values have and additional array indice of
* 'default' with the value of the default as a string.
*
* @param int $stackPtr The position in the stack of the T_FUNCTION token
* to acquire the parameters for.
*
* @return array()
* @throws PHP_CodeSniffer_Exception If the specified $stackPtr is not of
* type T_FUNCTION.
*/
public function getMethodParameters($stackPtr)
{
if ($this->_tokens[$stackPtr]['code'] !== T_FUNCTION) {
throw new PHP_CodeSniffer_Exception('$stackPtr must be of type T_FUNCTION');
}
 
$opener = $this->_tokens[$stackPtr]['parenthesis_opener'];
$closer = $this->_tokens[$stackPtr]['parenthesis_closer'];
 
$vars = array();
$currVar = null;
$defaultStart = null;
$paramCount = 0;
$passByReference = false;
$typeHint = '';
 
for ($i = ($opener + 1); $i <= $closer; $i++) {
// Check to see if this token has a parenthesis opener. If it does
// its likely to be an array, which might have arguments in it, which
// we cause problems in our parsing below, so lets just skip to the
// end of it.
if (isset($this->_tokens[$i]['parenthesis_opener']) === true) {
// Don't do this if its the close parenthesis for the method.
if ($i !== $this->_tokens[$i]['parenthesis_closer']) {
$i = ($this->_tokens[$i]['parenthesis_closer'] + 1);
}
}
 
switch ($this->_tokens[$i]['code']) {
case T_BITWISE_AND:
$passByReference = true;
break;
case T_VARIABLE:
$currVar = $i;
break;
case T_ARRAY_HINT:
$typeHint = $this->_tokens[$i]['content'];
break;
case T_STRING:
// This is a string, so it may be a type hint, but it could
// also be a constant used as a default value.
$prevComma = $this->findPrevious(T_COMMA, $i, $opener);
if ($prevComma !== false) {
$nextEquals = $this->findNext(T_EQUAL, $prevComma, $i);
if ($nextEquals !== false) {
break;
}
}
 
$typeHint = $this->_tokens[$i]['content'];
break;
case T_CLOSE_PARENTHESIS:
case T_COMMA:
// If it's null, then there must be no parameters for this
// method.
if ($currVar === null) {
continue;
}
 
$vars[$paramCount] = array();
$vars[$paramCount]['name'] = $this->_tokens[$currVar]['content'];
 
if ($defaultStart !== null) {
$vars[$paramCount]['default']
= $this->getTokensAsString(
$defaultStart,
($i - $defaultStart)
);
}
 
$vars[$paramCount]['pass_by_reference'] = $passByReference;
$vars[$paramCount]['type_hint'] = $typeHint;
 
// Reset the vars, as we are about to process the next parameter.
$defaultStart = null;
$passByReference = false;
$typeHint = '';
 
$paramCount++;
break;
case T_EQUAL:
$defaultStart = ($i + 1);
break;
}//end switch
}//end for
 
return $vars;
 
}//end getMethodParameters()
 
 
/**
* Returns the visibility and implementation properies of a method.
*
* The format of the array is:
* <code>
* array(
* 'scope' => 'public', // public private or protected
* 'scope_specified' => true, // true is scope keyword was found.
* 'is_abstract' => false, // true if the abstract keyword was found.
* 'is_final' => false, // true if the final keyword was found.
* 'is_static' => false, // true if the static keyword was found.
* );
* </code>
*
* @param int $stackPtr The position in the stack of the T_FUNCTION token to
* acquire the properties for.
*
* @return array
* @throws PHP_CodeSniffer_Exception If the specified position is not a
* T_FUNCTION token.
*/
public function getMethodProperties($stackPtr)
{
if ($this->_tokens[$stackPtr]['code'] !== T_FUNCTION) {
throw new PHP_CodeSniffer_Exception('$stackPtr must be of type T_FUNCTION');
}
 
$valid = array(
T_PUBLIC,
T_PRIVATE,
T_PROTECTED,
T_STATIC,
T_FINAL,
T_ABSTRACT,
T_WHITESPACE,
T_COMMENT,
T_DOC_COMMENT,
);
 
$scope = 'public';
$scopeSpecified = false;
$isAbstract = false;
$isFinal = false;
$isStatic = false;
 
for ($i = ($stackPtr - 1); $i > 0; $i--) {
if (in_array($this->_tokens[$i]['code'], $valid) === false) {
break;
}
 
switch ($this->_tokens[$i]['code']) {
case T_PUBLIC:
$scope = 'public';
$scopeSpecified = true;
break;
case T_PRIVATE:
$scope = 'private';
$scopeSpecified = true;
break;
case T_PROTECTED:
$scope = 'protected';
$scopeSpecified = true;
break;
case T_ABSTRACT:
$isAbstract = true;
break;
case T_FINAL:
$isFinal = true;
break;
case T_STATIC:
$isStatic = true;
break;
}//end switch
}//end for
 
return array(
'scope' => $scope,
'scope_specified' => $scopeSpecified,
'is_abstract' => $isAbstract,
'is_final' => $isFinal,
'is_static' => $isStatic,
);
 
}//end getMethodProperties()
 
 
/**
* Returns the visibility and implementation properies of the class member
* variable found at the specified position in the stack.
*
* The format of the array is:
*
* <code>
* array(
* 'scope' => 'public', // public private or protected
* 'is_static' => false, // true if the static keyword was found.
* );
* </code>
*
* @param int $stackPtr The position in the stack of the T_VARIABLE token to
* acquire the properties for.
*
* @return array
* @throws PHP_CodeSniffer_Exception If the specified position is not a
* T_VARIABLE token, or if the position is not
* a class member variable.
*/
public function getMemberProperties($stackPtr)
{
if ($this->_tokens[$stackPtr]['code'] !== T_VARIABLE) {
throw new PHP_CodeSniffer_Exception('$stackPtr must be of type T_VARIABLE');
}
 
end($this->_tokens[$stackPtr]['conditions']);
$ptr = key($this->_tokens[$stackPtr]['conditions']);
if (isset($this->_tokens[$ptr]) === false
|| $this->_tokens[$ptr]['code'] !== T_CLASS
) {
if (isset($this->_tokens[$ptr]) === true
&& $this->_tokens[$ptr]['code'] === T_INTERFACE
) {
$error = 'Possible parse error: interfaces may not include member vars';
$this->addWarning($error, $stackPtr);
return array();
} else {
throw new PHP_CodeSniffer_Exception('$stackPtr is not a class member var');
}
}
 
$valid = array(
T_PUBLIC,
T_PRIVATE,
T_PROTECTED,
T_STATIC,
T_WHITESPACE,
T_COMMENT,
T_DOC_COMMENT,
);
 
$scope = 'public';
$scopeSpecified = false;
$isStatic = false;
 
for ($i = ($stackPtr - 1); $i > 0; $i--) {
if (in_array($this->_tokens[$i]['code'], $valid) === false) {
break;
}
 
switch ($this->_tokens[$i]['code']) {
case T_PUBLIC:
$scope = 'public';
$scopeSpecified = true;
break;
case T_PRIVATE:
$scope = 'private';
$scopeSpecified = true;
break;
case T_PROTECTED:
$scope = 'protected';
$scopeSpecified = true;
break;
case T_STATIC:
$isStatic = true;
break;
}
}//end for
 
return array(
'scope' => $scope,
'scope_specified' => $scopeSpecified,
'is_static' => $isStatic,
);
 
}//end getMemberProperties()
 
 
/**
* Determine if the passed token is a reference operator.
*
* Returns true if the specified token position represents a reference.
* Returns false if the token represents a bitwise operator.
*
* @param int $stackPtr The position of the T_BITWISE_AND token.
*
* @return boolean
*/
public function isReference($stackPtr)
{
if ($this->_tokens[$stackPtr]['code'] !== T_BITWISE_AND) {
return false;
}
 
$tokenBefore = $this->findPrevious(
PHP_CodeSniffer_Tokens::$emptyTokens,
($stackPtr - 1),
null,
true
);
 
if ($this->_tokens[$tokenBefore]['code'] === T_FUNCTION) {
// Function returns a reference.
return true;
}
 
if ($this->_tokens[$tokenBefore]['code'] === T_DOUBLE_ARROW) {
// Inside a foreach loop, this is a reference.
return true;
}
 
if ($this->_tokens[$tokenBefore]['code'] === T_AS) {
// Inside a foreach loop, this is a reference.
return true;
}
 
if (in_array($this->_tokens[$tokenBefore]['code'], PHP_CodeSniffer_Tokens::$assignmentTokens) === true) {
// This is directly after an assignment. It's a reference. Even if
// it is part of an operation, the other tests will handle it.
return true;
}
 
if (isset($this->_tokens[$stackPtr]['nested_parenthesis']) === true) {
$brackets = $this->_tokens[$stackPtr]['nested_parenthesis'];
$lastBracket = array_pop($brackets);
if (isset($this->_tokens[$lastBracket]['parenthesis_owner']) === true) {
$owner = $this->_tokens[$this->_tokens[$lastBracket]['parenthesis_owner']];
if ($owner['code'] === T_FUNCTION) {
// Inside a function declaration, this is a reference.
return true;
}
}
}
 
return false;
 
}//end isReference()
 
 
/**
* Returns the content of the tokens from the specified start position in
* the token stack for the specified legnth.
*
* @param int $start The position to start from in the token stack.
* @param int $length The length of tokens to traverse from the start pos.
*
* @return string The token contents.
*/
public function getTokensAsString($start, $length)
{
$str = '';
$end = ($start + $length);
for ($i = $start; $i < $end; $i++) {
$str .= $this->_tokens[$i]['content'];
}
 
return $str;
 
}//end getTokensAsString()
 
 
/**
* Returns the position of the next specified token(s).
*
* If a value is specified, the next token of the specified type(s)
* containing the specified value will be returned.
*
* Returns false if no token can be found.
*
* @param int|array $types The type(s) of tokens to search for.
* @param int $start The position to start searching from in the
* token stack.
* @param int $end The end position to fail if no token is found.
* if not specified or null, end will default to
* the start of the token stack.
* @param bool $exclude If true, find the next token that are NOT of
* the types specified in $types.
* @param string $value The value that the token(s) must be equal to.
* If value is ommited, tokens with any value will
* be returned.
* @param bool $local If true, tokens outside the current statement
* will not be cheked. IE. checking will stop
* at the next semi-colon found.
*
* @return int | bool
* @see findNext()
*/
public function findPrevious(
$types,
$start,
$end=null,
$exclude=false,
$value=null,
$local=false
) {
$types = (array) $types;
 
if ($end === null) {
$end = 0;
}
 
for ($i = $start; $i >= $end; $i--) {
$found = (bool) $exclude;
foreach ($types as $type) {
if ($this->_tokens[$i]['code'] === $type) {
$found = !$exclude;
break;
}
}
 
if ($found === true) {
if ($value === null) {
return $i;
} else if ($this->_tokens[$i]['content'] === $value) {
return $i;
}
}
 
if ($local === true && $this->_tokens[$i]['code'] === T_SEMICOLON) {
break;
}
}//end for
 
return false;
 
}//end findPrevious()
 
 
/**
* Returns the position of the next specified token(s).
*
* If a value is specified, the next token of the specified type(s)
* containing the specified value will be returned.
*
* Returns false if no token can be found.
*
* @param int|array $types The type(s) of tokens to search for.
* @param int $start The position to start searching from in the
* token stack.
* @param int $end The end position to fail if no token is found.
* if not specified or null, end will default to
* the end of the token stack.
* @param bool $exclude If true, find the next token that is NOT of
* a type specified in $types.
* @param string $value The value that the token(s) must be equal to.
* If value is ommited, tokens with any value will
* be returned.
* @param bool $local If true, tokens outside the current statement
* will not be cheked. IE. checking will stop
* at the next semi-colon found.
*
* @return int | bool
* @see findPrevious()
*/
public function findNext(
$types,
$start,
$end=null,
$exclude=false,
$value=null,
$local=false
) {
$types = (array) $types;
 
if ($end === null || $end > $this->numTokens) {
$end = $this->numTokens;
}
 
for ($i = $start; $i < $end; $i++) {
$found = (bool) $exclude;
foreach ($types as $type) {
if ($this->_tokens[$i]['code'] === $type) {
$found = !$exclude;
break;
}
}
 
if ($found === true) {
if ($value === null) {
return $i;
} else if ($this->_tokens[$i]['content'] === $value) {
return $i;
}
}
 
if ($local === true && $this->_tokens[$i]['code'] === T_SEMICOLON) {
break;
}
}//end for
 
return false;
 
}//end findNext()
 
 
/**
* Returns the position of the first token on a line, matching given type.
*
* Returns false if no token can be found.
*
* @param int|array $types The type(s) of tokens to search for.
* @param int $start The position to start searching from in the
* token stack. The first token matching on
* this line before this token will be returned.
* @param bool $exclude If true, find the token that is NOT of
* the types specified in $types.
* @param string $value The value that the token must be equal to.
* If value is ommited, tokens with any value will
* be returned.
*
* @return int | bool
*/
public function findFirstOnLine($types, $start, $exclude=false, $value=null)
{
if (is_array($types) === false) {
$types = array($types);
}
 
$foundToken = false;
 
for ($i = $start; $i >= 0; $i--) {
if ($this->_tokens[$i]['line'] < $this->_tokens[$start]['line']) {
break;
}
 
$found = $exclude;
foreach ($types as $type) {
if ($exclude === false) {
if ($this->_tokens[$i]['code'] === $type) {
$found = true;
break;
}
} else {
if ($this->_tokens[$i]['code'] === $type) {
$found = false;
break;
}
}
}
 
if ($found === true) {
if ($value === null) {
$foundToken = $i;
} else if ($this->_tokens[$i]['content'] === $value) {
$foundToken = $i;
}
}
}//end for
 
return $foundToken;
 
}//end findFirstOnLine()
 
 
/**
* Determine if the passed token has a condition of one of the passed types.
*
* @param int $stackPtr The position of the token we are checking.
* @param int|array $types The type(s) of tokens to search for.
*
* @return boolean
*/
public function hasCondition($stackPtr, $types)
{
// Check for the existence of the token.
if (isset($this->_tokens[$stackPtr]) === false) {
return false;
}
 
// Make sure the token has conditions.
if (isset($this->_tokens[$stackPtr]['conditions']) === false) {
return false;
}
 
$types = (array) $types;
$conditions = $this->_tokens[$stackPtr]['conditions'];
 
foreach ($types as $type) {
if (in_array($type, $conditions) === true) {
// We found a token with the required type.
return true;
}
}
 
return false;
 
}//end hasCondition()
 
 
/**
* Returns the name of the class that the specified class extends.
*
* Returns FALSE on error or if there is no extended class name.
*
* @param int $stackPtr The stack position of the class.
*
* @return string
*/
public function findExtendedClassName($stackPtr)
{
// Check for the existence of the token.
if (isset($this->_tokens[$stackPtr]) === false) {
return false;
}
 
if ($this->_tokens[$stackPtr]['code'] !== T_CLASS) {
return false;
}
 
if (isset($this->_tokens[$stackPtr]['scope_closer']) === false) {
return false;
}
 
$classCloserIndex = $this->_tokens[$stackPtr]['scope_closer'];
$extendsIndex = $this->findNext(T_EXTENDS, $stackPtr, $classCloserIndex);
if (false === $extendsIndex) {
return false;
}
 
$stringIndex = $this->findNext(T_STRING, $extendsIndex, $classCloserIndex);
if (false === $stringIndex) {
return false;
}
 
return $this->_tokens[$stringIndex]['content'];
 
}//end findExtendedClassName()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/MultiFileSniff.php
New file
0,0 → 1,48
<?php
/**
* Represents a PHP_CodeSniffer sniff for sniffing coding standards.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: MultiFileSniff.php,v 1.1 2008/07/25 04:24:10 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Represents a PHP_CodeSniffer multi-file sniff for sniffing coding standards.
*
* A multi-file sniff is called after all files have been checked using the
* regular sniffs. The process() method is passed an array of PHP_CodeSniffer_File
* objects, one for each file checked during the script run.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
interface PHP_CodeSniffer_MultiFileSniff
{
 
 
/**
* Called once per script run to allow for processing of this sniff.
*
* @param array(PHP_CodeSniffer_File) $files The PHP_CodeSniffer files processed
* during the script run.
*
* @return void
*/
public function process(array $files);
 
 
}//end interface
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Tokens.php
New file
0,0 → 1,424
<?php
/**
* The Tokens class contains weightings for tokens based on their
* probability of occurance in a file.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: Tokens.php,v 1.25 2008/12/03 04:42:07 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
define('T_NONE', 0);
define('T_OPEN_CURLY_BRACKET', 1000);
define('T_CLOSE_CURLY_BRACKET', 1001);
define('T_OPEN_SQUARE_BRACKET', 1002);
define('T_CLOSE_SQUARE_BRACKET', 1003);
define('T_OPEN_PARENTHESIS', 1004);
define('T_CLOSE_PARENTHESIS', 1005);
define('T_COLON', 1006);
define('T_STRING_CONCAT', 1007);
define('T_INLINE_THEN', 1008);
define('T_NULL', 1009);
define('T_FALSE', 1010);
define('T_TRUE', 1011);
define('T_SEMICOLON', 1012);
define('T_EQUAL', 1013);
define('T_MULTIPLY', 1015);
define('T_DIVIDE', 1016);
define('T_PLUS', 1017);
define('T_MINUS', 1018);
define('T_MODULUS', 1019);
define('T_POWER', 1020);
define('T_BITWISE_AND', 1021);
define('T_BITWISE_OR', 1022);
define('T_ARRAY_HINT', 1023);
define('T_GREATER_THAN', 1024);
define('T_LESS_THAN', 1025);
define('T_BOOLEAN_NOT', 1026);
define('T_SELF', 1027);
define('T_PARENT', 1028);
define('T_DOUBLE_QUOTED_STRING', 1029);
define('T_COMMA', 1030);
define('T_HEREDOC', 1031);
define('T_PROTOTYPE', 1032);
define('T_THIS', 1033);
define('T_REGULAR_EXPRESSION', 1034);
define('T_PROPERTY', 1035);
define('T_LABEL', 1036);
define('T_OBJECT', 1037);
define('T_COLOUR', 1038);
define('T_HASH', 1039);
define('T_URL', 1040);
define('T_STYLE', 1041);
define('T_ASPERAND', 1042);
 
/**
* The Tokens class contains weightings for tokens based on their
* probability of occurance in a file.
*
* The less the chance of a high occurance of an abitrary token, the higher
* the weighting.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
final class PHP_CodeSniffer_Tokens
{
 
/**
* The token weightings.
*
* @var array(int => int)
*/
public static $weightings = array(
T_CLASS => 1000,
T_FUNCTION => 100,
 
/*
Conditions.
*/
 
T_WHILE => 50,
T_FOR => 50,
T_FOREACH => 50,
T_IF => 50,
T_ELSE => 50,
T_ELSEIF => 50,
T_WHILE => 50,
T_DO => 50,
T_TRY => 50,
T_CATCH => 50,
T_SWITCH => 50,
 
T_SELF => 25,
T_PARENT => 25,
 
/*
Operators and arithmetic.
*/
 
T_BITWISE_AND => 8,
T_BITWISE_OR => 8,
 
T_MULTIPLY => 5,
T_DIVIDE => 5,
T_PLUS => 5,
T_MINUS => 5,
T_MODULUS => 5,
T_POWER => 5,
 
T_EQUAL => 5,
T_AND_EQUAL => 5,
T_CONCAT_EQUAL => 5,
T_DIV_EQUAL => 5,
T_MINUS_EQUAL => 5,
T_MOD_EQUAL => 5,
T_MUL_EQUAL => 5,
T_OR_EQUAL => 5,
T_PLUS_EQUAL => 5,
T_XOR_EQUAL => 5,
 
T_BOOLEAN_AND => 5,
T_BOOLEAN_OR => 5,
 
/*
Equality.
*/
 
T_IS_EQUAL => 5,
T_IS_NOT_EQUAL => 5,
T_IS_IDENTICAL => 5,
T_IS_NOT_IDENTICAL => 5,
T_IS_SMALLER_OR_EQUAL => 5,
T_IS_GREATER_OR_EQUAL => 5,
);
 
/**
* Tokens that represent assignments.
*
* @var array(int)
*/
public static $assignmentTokens = array(
T_EQUAL,
T_AND_EQUAL,
T_CONCAT_EQUAL,
T_DIV_EQUAL,
T_MINUS_EQUAL,
T_MOD_EQUAL,
T_MUL_EQUAL,
T_PLUS_EQUAL,
T_XOR_EQUAL,
);
 
/**
* Tokens that represent equality comparisons.
*
* @var array(int)
*/
public static $equalityTokens = array(
T_IS_EQUAL,
T_IS_NOT_EQUAL,
T_IS_IDENTICAL,
T_IS_NOT_IDENTICAL,
T_IS_SMALLER_OR_EQUAL,
T_IS_GREATER_OR_EQUAL,
);
 
/**
* Tokens that represent comparison operator.
*
* @var array(int)
*/
public static $comparisonTokens = array(
T_IS_EQUAL,
T_IS_IDENTICAL,
T_IS_NOT_EQUAL,
T_IS_NOT_IDENTICAL,
T_LESS_THAN,
T_GREATER_THAN,
T_IS_SMALLER_OR_EQUAL,
T_IS_GREATER_OR_EQUAL,
);
 
/**
* Tokens that represent arithmetic operators.
*
* @var array(int)
*/
public static $arithmeticTokens = array(
T_PLUS,
T_MINUS,
T_MULTIPLY,
T_DIVIDE,
T_MODULUS,
);
 
/**
* Tokens that represent casting.
*
* @var array(int)
*/
public static $castTokens = array(
T_INT_CAST,
T_STRING_CAST,
T_DOUBLE_CAST,
T_ARRAY_CAST,
T_BOOL_CAST,
T_OBJECT_CAST,
T_UNSET_CAST,
);
 
/**
* Token types that open parethesis.
*
* @var array(int)
*/
public static $parenthesisOpeners = array(
T_ARRAY,
T_FUNCTION,
T_WHILE,
T_FOR,
T_FOREACH,
T_SWITCH,
T_IF,
T_ELSEIF,
T_CATCH,
);
 
/**
* Tokens that are allowed to open scopes.
*
* @var array(int)
*/
public static $scopeOpeners = array(
T_CLASS,
T_INTERFACE,
T_FUNCTION,
T_IF,
T_SWITCH,
T_CASE,
T_DEFAULT,
T_WHILE,
T_ELSE,
T_ELSEIF,
T_FOR,
T_FOREACH,
T_DO,
T_TRY,
T_CATCH,
);
 
/**
* Tokens that represent scope modifiers.
*
* @var array(int)
*/
public static $scopeModifiers = array(
T_PRIVATE,
T_PUBLIC,
T_PROTECTED,
);
 
/**
* Tokens that perform operations.
*
* @var array(int)
*/
public static $operators = array(
T_MINUS,
T_PLUS,
T_MULTIPLY,
T_DIVIDE,
T_MODULUS,
T_POWER,
T_BITWISE_AND,
T_BITWISE_OR,
);
 
/**
* Tokens that perform boolean operations.
*
* @var array(int)
*/
public static $booleanOperators = array(
T_BOOLEAN_AND,
T_BOOLEAN_OR,
T_LOGICAL_AND,
T_LOGICAL_OR,
);
 
/**
* Tokens that perform operations.
*
* @var array(int)
*/
public static $blockOpeners = array(
T_OPEN_CURLY_BRACKET,
T_OPEN_SQUARE_BRACKET,
T_OPEN_PARENTHESIS,
);
 
/**
* Tokens that don't represent code.
*
* @var array(int)
*/
public static $emptyTokens = array(
T_WHITESPACE,
T_COMMENT,
T_DOC_COMMENT,
);
 
/**
* Tokens that are comments.
*
* @var array(int)
*/
public static $commentTokens = array(
T_COMMENT,
T_DOC_COMMENT,
);
 
/**
* Tokens that represent strings.
*
* Note that T_STRINGS are NOT represented in this list.
*
* @var array(int)
*/
public static $stringTokens = array(
T_CONSTANT_ENCAPSED_STRING,
T_DOUBLE_QUOTED_STRING,
);
 
/**
* Tokens that include files.
*
* @var array(int)
*/
public static $includeTokens = array(
T_REQUIRE_ONCE,
T_REQUIRE,
T_INCLUDE_ONCE,
T_INCLUDE,
);
 
/**
* Tokens that make up a heredoc string.
*
* @var array(int)
*/
public static $heredocTokens = array(
T_START_HEREDOC,
T_END_HEREDOC,
T_HEREDOC,
);
 
 
/**
* A PHP_CodeSniffer_Tokens class cannot be constructed.
*
* Only static calls are allowed.
*/
private function __construct()
{
 
}//end __construct()
 
 
/**
* Returns the highest weighted token type.
*
* Tokens are weighted by their approximate frequency of appearance in code
* - the less frequently they appear in the code, the higher the weighting.
* For example T_CLASS tokens apprear very infrequently in a file, and
* therefore have a high weighting.
*
* Returns false if there are no weightings for any of the specified tokens.
*
* @param array(int) $tokens The token types to get the highest weighted
* type for.
*
* @return int The highest weighted token.
*/
public static function getHighestWeightedToken(array $tokens)
{
$highest = -1;
$highestType = false;
 
$weights = self::$weightings;
 
foreach ($tokens as $token) {
if (isset($weights[$token]) === true) {
$weight = $weights[$token];
} else {
$weight = 0;
}
 
if ($weight > $highest) {
$highest = $weight;
$highestType = $token;
}
}
 
return $highestType;
 
}//end getHighestWeightedToken()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Sniff.php
New file
0,0 → 1,94
<?php
/**
* Represents a PHP_CodeSniffer sniff for sniffing coding standards.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: Sniff.php,v 1.4 2007/11/30 01:18:40 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Represents a PHP_CodeSniffer sniff for sniffing coding standards.
*
* A sniff registers what token types it wishes to listen for, then, when
* PHP_CodeSniffer encounters that token, the sniff is invoked and passed
* information about where the token was found in the stack, and the
* PHP_CodeSniffer file in which the token was found.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
interface PHP_CodeSniffer_Sniff
{
 
 
/**
* Registers the tokens that this sniff wants to listen for.
*
* An example return value for a sniff that wants to listen for whitespace
* and any comments would be:
*
* <code>
* return array(
* T_WHITESPACE,
* T_DOC_COMMENT,
* T_COMMENT,
* );
* </code>
*
* @return array(int)
* @see Tokens.php
*/
public function register();
 
 
/**
* Called when one of the token types that this sniff is listening for
* is found.
*
* The stackPtr variable indicates where in the stack the token was found.
* A sniff can acquire information this token, along with all the other
* tokens within the stack by first acquiring the token stack:
*
* <code>
* $tokens = $phpcsFile->getTokens();
* echo 'Encountered a '.$tokens[$stackPtr]['type'].' token';
* echo 'token information: ';
* print_r($tokens[$stackPtr]);
* </code>
*
* If the sniff discovers an anomilty in the code, they can raise an error
* by calling addError() on the PHP_CodeSniffer_File object, specifying an error
* message and the position of the offending token:
*
* <code>
* $phpcsFile->addError('Encountered an error', $stackPtr);
* </code>
*
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where the
* token was found.
* @param int $stackPtr The position in the PHP_CodeSniffer
* file's token stack where the token
* was found.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr);
 
 
}//end interface
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/CLI.php
New file
0,0 → 1,563
<?php
/**
* A class to process command line phpcs scripts.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: CLI.php,v 1.9 2008/12/21 23:54:14 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (is_file(dirname(__FILE__).'/../CodeSniffer.php') === true) {
include_once dirname(__FILE__).'/../CodeSniffer.php';
} else {
include_once 'PHP/CodeSniffer.php';
}
 
/**
* A class to process command line phpcs scripts.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_CLI
{
 
 
/**
* Exits if the minimum requirements of PHP_CodSniffer are not met.
*
* @return array
*/
public function checkRequirements()
{
// Check the PHP version.
if (version_compare(PHP_VERSION, '5.1.2') === -1) {
echo 'ERROR: PHP_CodeSniffer requires PHP version 5.1.2 or greater.'.PHP_EOL;
exit(2);
}
 
if (extension_loaded('tokenizer') === false) {
echo 'ERROR: PHP_CodeSniffer requires the tokenizer extension to be enabled.'.PHP_EOL;
exit(2);
}
 
}//end checkRequirements()
 
 
/**
* Get a list of default values for all possible command line arguments.
*
* @return array
*/
public function getDefaults()
{
// The default values for config settings.
$defaults['files'] = array();
$defaults['standard'] = null;
$defaults['verbosity'] = 0;
$defaults['local'] = false;
$defaults['showSources'] = false;
$defaults['extensions'] = array();
$defaults['sniffs'] = array();
$defaults['ignored'] = array();
$defaults['reportFile'] = '';
$defaults['generator'] = '';
 
$defaults['report'] = PHP_CodeSniffer::getConfigData('report_format');
if ($defaults['report'] === null) {
$defaults['report'] = 'full';
}
 
$showWarnings = PHP_CodeSniffer::getConfigData('show_warnings');
if ($showWarnings === null) {
$defaults['showWarnings'] = true;
} else {
$defaults['showWarnings'] = (bool) $showWarnings;
}
 
$tabWidth = PHP_CodeSniffer::getConfigData('tab_width');
if ($tabWidth === null) {
$defaults['tabWidth'] = 0;
} else {
$defaults['tabWidth'] = (int) $tabWidth;
}
 
return $defaults;
 
}//end getDefaults()
 
 
/**
* Process the command line arguments and returns the values.
*
* @return array
*/
public function getCommandLineValues()
{
$values = $this->getDefaults();
 
for ($i = 1; $i < $_SERVER['argc']; $i++) {
$arg = $_SERVER['argv'][$i];
if ($arg{0} === '-') {
if ($arg === '-' || $arg === '--') {
// Empty argument, ignore it.
continue;
}
 
if ($arg{1} === '-') {
$values
= $this->processLongArgument(substr($arg, 2), $i, $values);
} else {
$switches = str_split($arg);
foreach ($switches as $switch) {
if ($switch === '-') {
continue;
}
 
$values = $this->processShortArgument($switch, $i, $values);
}
}
} else {
$values = $this->processUnknownArgument($arg, $i, $values);
}
}//end for
 
return $values;
 
}//end getCommandLineValues()
 
 
/**
* Processes a sort (-e) command line argument.
*
* @param string $arg The command line argument.
* @param int $pos The position of the argument on the command line.
* @param array $values An array of values determined from CLI args.
*
* @return array The updated CLI values.
* @see getCommandLineValues()
*/
public function processShortArgument($arg, $pos, $values)
{
switch ($arg) {
case 'h':
case '?':
$this->printUsage();
exit(0);
break;
case 'i' :
$this->printInstalledStandards();
exit(0);
break;
case 'v' :
$values['verbosity']++;
break;
case 'l' :
$values['local'] = true;
break;
case 's' :
$values['showSources'] = true;
break;
case 'n' :
$values['showWarnings'] = false;
break;
case 'w' :
$values['showWarnings'] = true;
break;
default:
$values = $this->processUnknownArgument('-'.$arg, $pos, $values);
}//end switch
 
return $values;
 
}//end processShortArgument()
 
 
/**
* Processes a long (--example) command line argument.
*
* @param string $arg The command line argument.
* @param int $pos The position of the argument on the command line.
* @param array $values An array of values determined from CLI args.
*
* @return array The updated CLI values.
* @see getCommandLineValues()
*/
public function processLongArgument($arg, $pos, $values)
{
switch ($arg) {
case 'help':
$this->printUsage();
exit(0);
break;
case 'version':
echo 'PHP_CodeSniffer version 1.2.0RC1 (beta) ';
echo 'by Squiz Pty Ltd. (http://www.squiz.net)'.PHP_EOL;
exit(0);
break;
case 'config-set':
$key = $_SERVER['argv'][($pos + 1)];
$value = $_SERVER['argv'][($pos + 2)];
PHP_CodeSniffer::setConfigData($key, $value);
exit(0);
break;
case 'config-delete':
$key = $_SERVER['argv'][($pos + 1)];
PHP_CodeSniffer::setConfigData($key, null);
exit(0);
break;
case 'config-show':
$data = PHP_CodeSniffer::getAllConfigData();
print_r($data);
exit(0);
break;
default:
if (substr($arg, 0, 7) === 'sniffs=') {
$values['sniffs'] = array();
 
$sniffs = substr($arg, 7);
$sniffs = explode(',', $sniffs);
 
// Convert the sniffs to class names.
foreach ($sniffs as $sniff) {
$parts = explode('.', $sniff);
$values['sniffs'][] = $parts[0].'_Sniffs_'.$parts[1].'_'.$parts[2].'Sniff';
}
} else if (substr($arg, 0, 7) === 'report=') {
$values['report'] = substr($arg, 7);
$validReports = array(
'full',
'xml',
'checkstyle',
'csv',
'emacs',
'source',
'summary',
);
 
if (in_array($values['report'], $validReports) === false) {
echo 'ERROR: Report type "'.$values['report'].'" not known.'.PHP_EOL;
exit(2);
}
} else if (substr($arg, 0, 12) === 'report-file=') {
$values['reportFile'] = realpath(substr($arg, 12));
 
// It may not exist and return false instead.
if ($values['reportFile'] === false) {
$values['reportFile'] = substr($arg, 12);
}
 
if (is_dir($values['reportFile']) === true) {
echo 'ERROR: The specified report file path "'.$values['reportFile'].'" is a directory.'.PHP_EOL.PHP_EOL;
$this->printUsage();
exit(2);
}
 
$dir = dirname($values['reportFile']);
if (is_dir($dir) === false) {
echo 'ERROR: The specified report file path "'.$values['reportFile'].'" points to a non-existent directory.'.PHP_EOL.PHP_EOL;
$this->printUsage();
exit(2);
}
} else if (substr($arg, 0, 9) === 'standard=') {
$values['standard'] = substr($arg, 9);
} else if (substr($arg, 0, 11) === 'extensions=') {
$values['extensions'] = explode(',', substr($arg, 11));
} else if (substr($arg, 0, 7) === 'ignore=') {
// Split the ignore string on commas, unless the comma is escaped
// using 1 or 3 slashes (\, or \\\,).
$values['ignored']= preg_split('/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/', substr($arg, 7));
} else if (substr($arg, 0, 10) === 'generator=') {
$values['generator'] = substr($arg, 10);
} else if (substr($arg, 0, 10) === 'tab-width=') {
$values['tabWidth'] = (int) substr($arg, 10);
} else {
$values = $this->processUnknownArgument('--'.$arg, $pos, $values);
}//end if
 
break;
}//end switch
 
return $values;
 
}//end processLongArgument()
 
 
/**
* Processes an unknown command line argument.
*
* Assumes all unknown arguments are files and folders to check.
*
* @param string $arg The command line argument.
* @param int $pos The position of the argument on the command line.
* @param array $values An array of values determined from CLI args.
*
* @return array The updated CLI values.
* @see getCommandLineValues()
*/
public function processUnknownArgument($arg, $pos, $values)
{
// We don't know about any additional switches; just files.
if ($arg{0} === '-') {
echo 'ERROR: option "'.$arg.'" not known.'.PHP_EOL.PHP_EOL;
$this->printUsage();
exit(2);
}
 
$file = realpath($arg);
if (file_exists($file) === false) {
echo 'ERROR: The file "'.$arg.'" does not exist.'.PHP_EOL.PHP_EOL;
$this->printUsage();
exit(2);
} else {
$values['files'][] = $file;
}
 
return $values;
 
}//end processUnknownArgument()
 
 
/**
* Runs PHP_CodeSniffer over files are directories.
*
* @param array $values An array of values determined from CLI args.
*
* @return int The number of error and warning messages shown.
* @see getCommandLineValues()
*/
public function process($values=array())
{
if (empty($values) === true) {
$values = $this->getCommandLineValues();
}
 
if ($values['generator'] !== '') {
$phpcs = new PHP_CodeSniffer($values['verbosity']);
$phpcs->generateDocs(
$values['standard'],
$values['files'],
$values['generator']
);
exit(0);
}
 
if (empty($values['files']) === true) {
echo 'ERROR: You must supply at least one file or directory to process.'.PHP_EOL.PHP_EOL;
$this->printUsage();
exit(2);
}
 
$values['standard'] = $this->validateStandard($values['standard']);
if (PHP_CodeSniffer::isInstalledStandard($values['standard']) === false) {
// They didn't select a valid coding standard, so help them
// out by letting them know which standards are installed.
echo 'ERROR: the "'.$values['standard'].'" coding standard is not installed. ';
$this->printInstalledStandards();
exit(2);
}
 
$phpcs = new PHP_CodeSniffer($values['verbosity'], $values['tabWidth']);
 
// Set file extensions if they were specified. Otherwise,
// let PHP_CodeSniffer decide on the defaults.
if (empty($values['extensions']) === false) {
$phpcs->setAllowedFileExtensions($values['extensions']);
}
 
// Set ignore patterns if they were specified.
if (empty($values['ignored']) === false) {
$phpcs->setIgnorePatterns($values['ignored']);
}
 
$phpcs->process(
$values['files'],
$values['standard'],
$values['sniffs'],
$values['local']
);
 
return $this->printErrorReport(
$phpcs,
$values['report'],
$values['showWarnings'],
$values['showSources'],
$values['reportFile']
);
 
}//end process()
 
 
/**
* Prints the error report.
*
* @param PHP_CodeSniffer $phpcs The PHP_CodeSniffer object containing
* the errors.
* @param string $report The type of report to print.
* @param bool $showWarnings TRUE if warnings should also be printed.
* @param bool $showSources TRUE if the report should show error sources
* (not used by all reports).
* @param string $reportFile A file to log the report out to.
*
* @return int The number of error and warning messages shown.
*/
public function printErrorReport($phpcs, $report, $showWarnings, $showSources, $reportFile='')
{
if ($reportFile !== '') {
ob_start();
}
 
switch ($report) {
case 'xml':
$numErrors = $phpcs->printXMLErrorReport($showWarnings);
break;
case 'checkstyle':
$numErrors = $phpcs->printCheckstyleErrorReport($showWarnings);
break;
case 'csv':
$numErrors = $phpcs->printCSVErrorReport($showWarnings);
break;
case 'emacs':
$numErrors = $phpcs->printEmacsErrorReport($showWarnings);
break;
case 'summary':
$numErrors = $phpcs->printErrorReportSummary($showWarnings, $showSources);
break;
case 'source':
$numErrors = $phpcs->printSourceReport($showWarnings, $showSources);
break;
default:
$numErrors = $phpcs->printErrorReport($showWarnings, $showSources);
break;
}
 
if ($reportFile !== '') {
$report = ob_get_contents();
ob_end_flush();
 
$report = trim($report);
file_put_contents($reportFile, "$report\n");
}
 
return $numErrors;
 
}//end printErrorReport()
 
 
/**
* Convert the passed standard into a valid standard.
*
* Checks things like default values and case.
*
* @param string $standard The standard to validate.
*
* @return string
*/
public function validateStandard($standard)
{
if ($standard === null) {
// They did not supply a standard to use.
// Try to get the default from the config system.
$standard = PHP_CodeSniffer::getConfigData('default_standard');
if ($standard === null) {
$standard = 'PEAR';
}
}
 
// Check if the standard name is valid. If not, check that the case
// was not entered incorrectly.
if (PHP_CodeSniffer::isInstalledStandard($standard) === false) {
$installedStandards = PHP_CodeSniffer::getInstalledStandards();
foreach ($installedStandards as $validStandard) {
if (strtolower($standard) === strtolower($validStandard)) {
$standard = $validStandard;
break;
}
}
}
 
return $standard;
 
}//end validateStandard()
 
 
/**
* Prints out the usage information for this script.
*
* @return void
*/
public function printUsage()
{
echo 'Usage: phpcs [-nwlsvi] [--report=<report>] [--report-file=<reportfile>]'.PHP_EOL;
echo ' [--config-set key value] [--config-delete key] [--config-show]'.PHP_EOL;
echo ' [--standard=<standard>] [--sniffs=<sniffs>]'.PHP_EOL;
echo ' [--extensions=<extensions>] [--ignore=<patterns>]'.PHP_EOL;
echo ' [--generator=<generator>] [--tab-width=<width>] <file> ...'.PHP_EOL;
echo ' -n Do not print warnings'.PHP_EOL;
echo ' -w Print both warnings and errors (on by default)'.PHP_EOL;
echo ' -l Local directory only, no recursion'.PHP_EOL;
echo ' -s Show sniff codes in all reports'.PHP_EOL;
echo ' -v[v][v] Print verbose output'.PHP_EOL;
echo ' -i Show a list of installed coding standards'.PHP_EOL;
echo ' --help Print this help message'.PHP_EOL;
echo ' --version Print version information'.PHP_EOL;
echo ' <file> One or more files and/or directories to check'.PHP_EOL;
echo ' <extensions> A comma separated list of file extensions to check'.PHP_EOL;
echo ' (only valid if checking a directory)'.PHP_EOL;
echo ' <patterns> A comma separated list of patterns that are used'.PHP_EOL;
echo ' to ignore directories and files'.PHP_EOL;
echo ' <sniffs> A comma separated list of sniff codes to limit the check to'.PHP_EOL;
echo ' (all sniffs must be part of the specified standard)'.PHP_EOL;
echo ' <standard> The name of the coding standard to use'.PHP_EOL;
echo ' <width> The number of spaces each tab represents'.PHP_EOL;
echo ' <generator> The name of a doc generator to use'.PHP_EOL;
echo ' (forces doc generation instead of checking)'.PHP_EOL;
echo ' <report> Print either the "full", "xml", "checkstyle",'.PHP_EOL;
echo ' "csv", "emacs", "source" or "summary" report'.PHP_EOL;
echo ' (the "full" report is printed by default)'.PHP_EOL;
echo ' <reportfile> Write the report to the specified file path'.PHP_EOL;
echo ' (report is also written to screen)'.PHP_EOL;
 
}//end printUsage()
 
 
/**
* Prints out a list of installed coding standards.
*
* @return void
*/
public function printInstalledStandards()
{
$installedStandards = PHP_CodeSniffer::getInstalledStandards();
$numStandards = count($installedStandards);
 
if ($numStandards === 0) {
echo 'No coding standards are installed.'.PHP_EOL;
} else {
$lastStandard = array_pop($installedStandards);
if ($numStandards === 1) {
echo 'The only coding standard installed is $lastStandard'.PHP_EOL;
} else {
$standardList = implode(', ', $installedStandards);
$standardList .= ' and '.$lastStandard;
echo 'The installed coding standards are '.$standardList.PHP_EOL;
}
}
 
}//end printInstalledStandards()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Tokenizers/PHP.php
New file
0,0 → 1,429
<?php
/**
* Tokenizes PHP code.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: PHP.php,v 1.6 2009/01/20 23:55:15 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Tokenizes PHP code.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Tokenizers_PHP
{
 
/**
* A list of tokens that are allowed to open a scope.
*
* This array also contains information about what kind of token the scope
* opener uses to open and close the scope, if the token strictly requires
* an opener, if the token can share a scope closer, and who it can be shared
* with. An example of a token that shares a scope closer is a CASE scope.
*
* @var array
*/
public $scopeOpeners = array(
T_IF => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => false,
'shared' => false,
'with' => array(),
),
T_TRY => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => true,
'shared' => false,
'with' => array(),
),
T_CATCH => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => true,
'shared' => false,
'with' => array(),
),
T_ELSE => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => false,
'shared' => false,
'with' => array(),
),
T_ELSEIF => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => false,
'shared' => false,
'with' => array(),
),
T_FOR => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => false,
'shared' => false,
'with' => array(),
),
T_FOREACH => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => false,
'shared' => false,
'with' => array(),
),
T_INTERFACE => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => true,
'shared' => false,
'with' => array(),
),
T_FUNCTION => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => false,
'shared' => false,
'with' => array(),
),
T_CLASS => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => true,
'shared' => false,
'with' => array(),
),
T_WHILE => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => false,
'shared' => false,
'with' => array(),
),
T_DO => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => true,
'shared' => false,
'with' => array(),
),
T_SWITCH => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => true,
'shared' => false,
'with' => array(),
),
T_CASE => array(
'start' => T_COLON,
'end' => T_BREAK,
'strict' => true,
'shared' => true,
'with' => array(
T_DEFAULT,
T_CASE,
T_SWITCH,
),
),
T_DEFAULT => array(
'start' => T_COLON,
'end' => T_BREAK,
'strict' => true,
'shared' => true,
'with' => array(
T_CASE,
T_SWITCH,
),
),
T_START_HEREDOC => array(
'start' => T_START_HEREDOC,
'end' => T_END_HEREDOC,
'strict' => true,
'shared' => false,
'with' => array(),
),
);
 
/**
* A list of tokens that end the scope.
*
* This array is just a unique collection of the end tokens
* from the _scopeOpeners array. The data is duplicated here to
* save time during parsing of the file.
*
* @var array
*/
public $endScopeTokens = array(
T_CLOSE_CURLY_BRACKET,
T_BREAK,
T_END_HEREDOC,
);
 
 
/**
* Creates an array of tokens when given some PHP code.
*
* Starts by using token_get_all() but does a lot of extra processing
* to insert information about the context of the token.
*
* @param string $string The string to tokenize.
* @param string $eolChar The EOL character to use for splitting strings.
*
* @return array
*/
public function tokenizeString($string, $eolChar='\n')
{
$tokens = @token_get_all($string);
$finalTokens = array();
 
$newStackPtr = 0;
$numTokens = count($tokens);
for ($stackPtr = 0; $stackPtr < $numTokens; $stackPtr++) {
$token = $tokens[$stackPtr];
$tokenIsArray = is_array($token);
 
/*
If we are using \r\n newline characters, the \r and \n are sometimes
split over two tokens. This normally occurs after comments. We need
to merge these two characters together so that our line endings are
consistent for all lines.
*/
 
if ($tokenIsArray === true && substr($token[1], -1) === "\r") {
if (isset($tokens[($stackPtr + 1)]) === true
&& is_array($tokens[($stackPtr + 1)]) === true
&& $tokens[($stackPtr + 1)][1][0] === "\n"
) {
$token[1] .= "\n";
 
if ($tokens[($stackPtr + 1)][1] === "\n") {
// The next token's content has been merged into this token,
// so we can skip it.
$stackPtr++;
} else {
$tokens[($stackPtr + 1)][1]
= substr($tokens[($stackPtr + 1)][1], 1);
}
}
}//end if
 
/*
If this is a double quoted string, PHP will tokenise the whole
thing which causes problems with the scope map when braces are
within the string. So we need to merge the tokens together to
provide a single string.
*/
 
if ($tokenIsArray === false && $token === '"') {
$tokenContent = '"';
$nestedVars = array();
for ($i = ($stackPtr + 1); $i < $numTokens; $i++) {
$subTokenIsArray = is_array($tokens[$i]);
 
if ($subTokenIsArray === true) {
$tokenContent .= $tokens[$i][1];
if ($tokens[$i][1] === '{'
&& $tokens[$i][0] !== T_ENCAPSED_AND_WHITESPACE
) {
$nestedVars[] = $i;
}
} else {
$tokenContent .= $tokens[$i];
if ($tokens[$i] === '}') {
array_pop($nestedVars);
}
}
 
if ($subTokenIsArray === false
&& $tokens[$i] === '"'
&& empty($nestedVars) === true
) {
// We found the other end of the double quoted string.
break;
}
}
 
$stackPtr = $i;
 
// Convert each line within the double quoted string to a
// new token, so it conforms with other multiple line tokens.
$tokenLines = explode($eolChar, $tokenContent);
$numLines = count($tokenLines);
$newToken = array();
 
for ($j = 0; $j < $numLines; $j++) {
$newToken['content'] = $tokenLines[$j];
if ($j === ($numLines - 1)) {
if ($tokenLines[$j] === '') {
break;
}
} else {
$newToken['content'] .= $eolChar;
}
 
$newToken['code'] = T_DOUBLE_QUOTED_STRING;
$newToken['type'] = 'T_DOUBLE_QUOTED_STRING';
$finalTokens[$newStackPtr] = $newToken;
$newStackPtr++;
}
 
// Continue, as we're done with this token.
continue;
}//end if
 
/*
If this is a heredoc, PHP will tokenise the whole
thing which causes problems when heredocs don't
contain real PHP code, which is almost never.
We want to leave the start and end heredoc tokens
alone though.
*/
 
if ($tokenIsArray === true && $token[0] === T_START_HEREDOC) {
// Add the start heredoc token to the final array.
$finalTokens[$newStackPtr]
= PHP_CodeSniffer::standardiseToken($token);
$newStackPtr++;
 
$tokenContent = '';
for ($i = ($stackPtr + 1); $i < $numTokens; $i++) {
$subTokenIsArray = is_array($tokens[$i]);
if ($subTokenIsArray === true
&& $tokens[$i][0] === T_END_HEREDOC
) {
// We found the other end of the heredoc.
break;
}
 
if ($subTokenIsArray === true) {
$tokenContent .= $tokens[$i][1];
} else {
$tokenContent .= $tokens[$i];
}
}
 
$stackPtr = $i;
 
// Convert each line within the heredoc to a
// new token, so it conforms with other multiple line tokens.
$tokenLines = explode($eolChar, $tokenContent);
$numLines = count($tokenLines);
$newToken = array();
 
for ($j = 0; $j < $numLines; $j++) {
$newToken['content'] = $tokenLines[$j];
if ($j === ($numLines - 1)) {
if ($tokenLines[$j] === '') {
break;
}
} else {
$newToken['content'] .= $eolChar;
}
 
$newToken['code'] = T_HEREDOC;
$newToken['type'] = 'T_HEREDOC';
$finalTokens[$newStackPtr] = $newToken;
$newStackPtr++;
}
 
// Add the end heredoc token to the final array.
$finalTokens[$newStackPtr]
= PHP_CodeSniffer::standardiseToken($tokens[$stackPtr]);
$newStackPtr++;
 
// Continue, as we're done with this token.
continue;
}//end if
 
/*
If this token has newlines in its content, split each line up
and create a new token for each line. We do this so it's easier
to asertain where errors occur on a line.
Note that $token[1] is the token's content.
*/
 
if ($tokenIsArray === true && strpos($token[1], $eolChar) !== false) {
$tokenLines = explode($eolChar, $token[1]);
$numLines = count($tokenLines);
$tokenName = token_name($token[0]);
 
for ($i = 0; $i < $numLines; $i++) {
$newToken['content'] = $tokenLines[$i];
if ($i === ($numLines - 1)) {
if ($tokenLines[$i] === '') {
break;
}
} else {
$newToken['content'] .= $eolChar;
}
 
$newToken['type'] = $tokenName;
$newToken['code'] = $token[0];
$finalTokens[$newStackPtr] = $newToken;
$newStackPtr++;
}
} else {
$newToken = PHP_CodeSniffer::standardiseToken($token);
 
// This is a special condition for T_ARRAY tokens use to
// type hint function arguments as being arrays. We want to keep
// the parenthsis map clean, so let's tag these tokens as
// T_ARRAY_HINT.
if ($newToken['code'] === T_ARRAY) {
// Recalculate number of tokens.
$numTokens = count($tokens);
for ($i = $stackPtr; $i < $numTokens; $i++) {
if (is_array($tokens[$i]) === false) {
if ($tokens[$i] === '(') {
break;
}
} else if ($tokens[$i][0] === T_VARIABLE) {
$newToken['code'] = T_ARRAY_HINT;
$newToken['type'] = 'T_ARRAY_HINT';
break;
}
}
}
 
$finalTokens[$newStackPtr] = $newToken;
$newStackPtr++;
}//end if
}//end for
 
return $finalTokens;
 
}//end tokenizeString()
 
 
/**
* Performs additional processing after main tokenizing.
*
* @param array &$tokens The array of tokens to process.
* @param string $eolChar The EOL character to use for splitting strings.
*
* @return array
*/
public function processAdditional(&$tokens, $eolChar)
{
 
}//end processAdditional()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Tokenizers/CSS.php
New file
0,0 → 1,221
<?php
/**
* Tokenizes CSS code.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: CSS.php,v 1.7 2009/02/23 03:26:19 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_Tokenizers_PHP', true) === false) {
throw new Exception('Class PHP_CodeSniffer_Tokenizers_PHP not found');
}
 
/**
* Tokenizes CSS code.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Tokenizers_CSS extends PHP_CodeSniffer_Tokenizers_PHP
{
 
 
/**
* Creates an array of tokens when given some CSS code.
*
* Uses the PHP tokenizer to do all the tricky work
*
* @param string $string The string to tokenize.
* @param string $eolChar The EOL character to use for splitting strings.
*
* @return array
*/
public function tokenizeString($string, $eolChar='\n')
{
$tokens = parent::tokenizeString('<?php '.$string.' ?>', $eolChar);
$finalTokens = array();
 
$newStackPtr = 0;
$numTokens = count($tokens);
for ($stackPtr = 0; $stackPtr < $numTokens; $stackPtr++) {
$token = $tokens[$stackPtr];
 
// Styles like list-style are tokenized as T_LIST-T_STRING
// so convert the T_LIST to a string.
if ($token['code'] === T_LIST) {
$token['code'] = T_STRING;
$token['type'] = 'T_STRING';
}
 
if ($token['code'] === T_COMMENT
&& (substr($token['content'], 0, 2) === '//'
|| $token['content']{0} === '#')
) {
$content = ltrim($token['content'], '#/');
$commentTokens
= parent::tokenizeString('<?php '.$content.'?>', $eolChar);
 
// The first and last tokens are the open/close tags.
array_shift($commentTokens);
array_pop($commentTokens);
 
if ($token['content']{0} === '#') {
// The # character is not a comment in CSS files, so determine
// what it means in this context.
$firstContent = $commentTokens[0]['content'];
 
// If the first content is just a number, it is probably a
// colour like 8FB7DB, which PHP splits into 8 and FB7DB.
if ($commentTokens[0]['code'] === T_LNUMBER
&& $commentTokens[1]['code'] === T_STRING
) {
$firstContent .= $commentTokens[1]['content'];
array_shift($commentTokens);
}
 
// If the first content looks like a colour and not a class
// definition, join the tokens together.
if (preg_match('/^[ABCDEF0-9]+$/i', $firstContent) === 1) {
array_shift($commentTokens);
$finalTokens[$newStackPtr] = array(
'type' => 'T_COLOUR',
'code' => T_COLOUR,
'content' => '#'.$firstContent,
);
} else {
$finalTokens[$newStackPtr] = array(
'type' => 'T_HASH',
'code' => T_HASH,
'content' => '#',
);
}
} else {
$finalTokens[$newStackPtr] = array(
'type' => 'T_STRING',
'code' => T_STRING,
'content' => '//',
);
}//end if
 
$newStackPtr++;
 
foreach ($commentTokens as $tokenData) {
$finalTokens[$newStackPtr] = $tokenData;
$newStackPtr++;
}
 
continue;
}//end if
 
$finalTokens[$newStackPtr] = $token;
$newStackPtr++;
}//end for
 
$numTokens = count($finalTokens);
for ($stackPtr = 0; $stackPtr < $numTokens; $stackPtr++) {
$token = $finalTokens[$stackPtr];
 
switch ($token['code']) {
case T_MINUS:
// Minus signs are often used instead of spaces inside
// class names, IDs and styles.
if ($finalTokens[($stackPtr + 1)]['code'] === T_STRING) {
if ($finalTokens[($stackPtr - 1)]['code'] === T_STRING) {
$newContent = $finalTokens[($stackPtr - 1)]['content'].'-'.$finalTokens[($stackPtr + 1)]['content'];
 
$finalTokens[($stackPtr - 1)]['content'] = $newContent;
unset($finalTokens[$stackPtr]);
unset($finalTokens[($stackPtr + 1)]);
$stackPtr -= 2;
} else {
$newContent = '-'.$finalTokens[($stackPtr + 1)]['content'];
 
$finalTokens[($stackPtr + 1)]['content'] = $newContent;
unset($finalTokens[$stackPtr]);
$stackPtr--;
}
 
$finalTokens = array_values($finalTokens);
$numTokens = count($finalTokens);
} else if ($finalTokens[($stackPtr + 1)]['code'] === T_LNUMBER) {
// They can also be used to provide negative numbers.
$finalTokens[($stackPtr + 1)]['content']
= '-'.$finalTokens[($stackPtr + 1)]['content'];
unset($finalTokens[$stackPtr]);
 
$finalTokens = array_values($finalTokens);
$numTokens = count($finalTokens);
}
 
break;
case T_COLON:
// Find the previous content.
for ($x = ($stackPtr - 1); $x >= 0; $x--) {
if (in_array($finalTokens[$x]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
break;
}
}
 
$finalTokens[$x]['type'] = 'T_STYLE';
$finalTokens[$x]['code'] = T_STYLE;
break;
case T_STRING:
if (strtolower($token['content']) === 'url') {
// Find the next content.
for ($x = ($stackPtr + 1); $x < $numTokens; $x++) {
if (in_array($finalTokens[$x]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
break;
}
}
 
// Needs to be in the format url( for it to be a URL.
if ($finalTokens[$x]['code'] !== T_OPEN_PARENTHESIS) {
continue;
}
 
// Join all the content together inside the url() statement.
$newContent = '';
for ($i = ($x + 2); $i < $numTokens; $i++) {
if ($finalTokens[$i]['code'] === T_CLOSE_PARENTHESIS) {
break;
}
 
$newContent .= $finalTokens[$i]['content'];
unset($finalTokens[$i]);
}
 
$finalTokens[($x + 1)]['type'] = 'T_URL';
$finalTokens[($x + 1)]['code'] = T_URL;
$finalTokens[($x + 1)]['content'] .= $newContent;
 
$finalTokens = array_values($finalTokens);
$numTokens = count($finalTokens);
}//end if
 
break;
default:
// Nothing special to be done with this token.
break;
}//end switch
}//end for
 
return $finalTokens;
 
}//end tokenizeString()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/Tokenizers/JS.php
New file
0,0 → 1,998
<?php
/**
* Tokenizes JS code.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: JS.php,v 1.25 2008/12/04 06:07:15 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* Tokenizes JS code.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_Tokenizers_JS
{
 
/**
* A list of tokens that are allowed to open a scope.
*
* This array also contains information about what kind of token the scope
* opener uses to open and close the scope, if the token strictly requires
* an opener, if the token can share a scope closer, and who it can be shared
* with. An example of a token that shares a scope closer is a CASE scope.
*
* @var array
*/
public $scopeOpeners = array(
T_IF => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => false,
'shared' => false,
'with' => array(),
),
T_TRY => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => true,
'shared' => false,
'with' => array(),
),
T_CATCH => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => true,
'shared' => false,
'with' => array(),
),
T_ELSE => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => false,
'shared' => false,
'with' => array(),
),
T_FOR => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => false,
'shared' => false,
'with' => array(),
),
T_FUNCTION => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => false,
'shared' => false,
'with' => array(),
),
T_WHILE => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => false,
'shared' => false,
'with' => array(),
),
T_DO => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => true,
'shared' => false,
'with' => array(),
),
T_SWITCH => array(
'start' => T_OPEN_CURLY_BRACKET,
'end' => T_CLOSE_CURLY_BRACKET,
'strict' => true,
'shared' => false,
'with' => array(),
),
T_CASE => array(
'start' => T_COLON,
'end' => T_BREAK,
'strict' => true,
'shared' => true,
'with' => array(
T_DEFAULT,
T_CASE,
T_SWITCH,
),
),
T_DEFAULT => array(
'start' => T_COLON,
'end' => T_BREAK,
'strict' => true,
'shared' => true,
'with' => array(
T_CASE,
T_SWITCH,
),
),
);
 
/**
* A list of tokens that end the scope.
*
* This array is just a unique collection of the end tokens
* from the _scopeOpeners array. The data is duplicated here to
* save time during parsing of the file.
*
* @var array
*/
public $endScopeTokens = array(
T_CLOSE_CURLY_BRACKET,
T_BREAK,
);
 
/**
* A list of special JS tokens and their types.
*
* @var array
*/
protected $tokenValues = array(
'function' => 'T_FUNCTION',
'prototype' => 'T_PROTOTYPE',
'try' => 'T_TRY',
'catch' => 'T_CATCH',
'return' => 'T_RETURN',
'break' => 'T_BREAK',
'switch' => 'T_SWITCH',
'continue' => 'T_CONTINUE',
'if' => 'T_IF',
'else' => 'T_ELSE',
'do' => 'T_DO',
'while' => 'T_WHILE',
'for' => 'T_FOR',
'var' => 'T_VAR',
'case' => 'T_CASE',
'default' => 'T_DEFAULT',
'true' => 'T_TRUE',
'false' => 'T_FALSE',
'null' => 'T_NULL',
'this' => 'T_THIS',
'(' => 'T_OPEN_PARENTHESIS',
')' => 'T_CLOSE_PARENTHESIS',
'{' => 'T_OPEN_CURLY_BRACKET',
'}' => 'T_CLOSE_CURLY_BRACKET',
'[' => 'T_OPEN_SQUARE_BRACKET',
']' => 'T_CLOSE_SQUARE_BRACKET',
'?' => 'T_INLINE_THEN',
'.' => 'T_OBJECT_OPERATOR',
'+' => 'T_PLUS',
'-' => 'T_MINUS',
'*' => 'T_MULTIPLY',
'%' => 'T_MODULUS',
'/' => 'T_DIVIDE',
',' => 'T_COMMA',
';' => 'T_SEMICOLON',
':' => 'T_COLON',
'<' => 'T_LESS_THAN',
'>' => 'T_GREATER_THAN',
'<=' => 'T_IS_SMALLER_OR_EQUAL',
'>=' => 'T_IS_GREATER_OR_EQUAL',
'!' => 'T_BOOLEAN_NOT',
'!=' => 'T_IS_NOT_EQUAL',
'!==' => 'T_IS_NOT_IDENTICAL',
'=' => 'T_EQUAL',
'==' => 'T_IS_EQUAL',
'===' => 'T_IS_IDENTICAL',
'-=' => 'T_MINUS_EQUAL',
'+=' => 'T_PLUS_EQUAL',
'*=' => 'T_MUL_EQUAL',
'/=' => 'T_DIV_EQUAL',
'++' => 'T_INC',
'--' => 'T_DEC',
'//' => 'T_COMMENT',
'/*' => 'T_COMMENT',
'/**' => 'T_DOC_COMMENT',
'*/' => 'T_COMMENT',
);
 
/**
* A list string delimiters.
*
* @var array
*/
protected $stringTokens = array(
'\'',
'"',
);
 
/**
* A list tokens that start and end comments.
*
* @var array
*/
protected $commentTokens = array(
'//' => null,
'/*' => '*/',
'/**' => '*/',
);
 
 
/**
* Creates an array of tokens when given some PHP code.
*
* Starts by using token_get_all() but does a lot of extra processing
* to insert information about the context of the token.
*
* @param string $string The string to tokenize.
* @param string $eolChar The EOL character to use for splitting strings.
*
* @return array
*/
public function tokenizeString($string, $eolChar='\n')
{
$tokenTypes = array_keys($this->tokenValues);
 
$maxTokenLength = 0;
foreach ($tokenTypes as $token) {
if (strlen($token) > $maxTokenLength) {
$maxTokenLength = strlen($token);
}
}
 
$tokens = array();
$inString = '';
$stringChar = null;
$inComment = '';
$buffer = '';
$preStringBuffer = '';
$cleanBuffer = false;
 
$tokens[] = array(
'code' => T_OPEN_TAG,
'type' => 'T_OPEN_TAG',
'content' => '',
);
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t*** START TOKENIZING ***".PHP_EOL;
}
 
// Convert newlines to single characters for ease of
// processing. We will change them back later.
$string = str_replace($eolChar, "\n", $string);
 
$chars = str_split($string);
$numChars = count($chars);
for ($i = 0; $i < $numChars; $i++) {
$char = $chars[$i];
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$content = str_replace("\n", '\n', $char);
$bufferContent = str_replace("\n", '\n', $buffer);
if ($inString !== '') {
echo "\t";
}
 
if ($inComment !== '') {
echo "\t";
}
 
echo "Process char $i => $content (buffer: $bufferContent)".PHP_EOL;
}
 
if ($inString === '' && $inComment === '' && $buffer !== '') {
// If the buffer only has whitespace and we are about to
// add a character, store the whitespace first.
if (trim($char) !== '' && trim($buffer) === '') {
$tokens[] = array(
'code' => T_WHITESPACE,
'type' => 'T_WHITESPACE',
'content' => str_replace("\n", $eolChar, $buffer),
);
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$content = str_replace("\n", '\n', $buffer);
echo "=> Added token T_WHITESPACE ($content)".PHP_EOL;
}
 
$buffer = '';
}
 
// If the buffer is not whitespace and we are about to
// add a whitespace character, store the content first.
if ($inString === ''
&& $inComment === ''
&& trim($char) === ''
&& trim($buffer) !== ''
) {
$tokens[] = array(
'code' => T_STRING,
'type' => 'T_STRING',
'content' => str_replace("\n", $eolChar, $buffer),
);
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$content = str_replace("\n", '\n', $buffer);
echo "=> Added token T_STRING ($content)".PHP_EOL;
}
 
$buffer = '';
}
}//end if
 
// Process strings.
if ($inComment === '' && in_array($char, $this->stringTokens) === true) {
if ($inString === $char) {
// This could be the end of the string, but make sure it
// is not escaped first.
$escapes = 0;
for ($x = ($i - 1); $x >= 0; $x--) {
if ($chars[$x] !== '\\') {
break;
}
 
$escapes++;
}
 
if ($escapes === 0 || ($escapes % 2) === 0) {
// There is an even number escape chars,
// so this is not escaped, it is the end of the string.
$tokens[] = array(
'code' => T_CONSTANT_ENCAPSED_STRING,
'type' => 'T_CONSTANT_ENCAPSED_STRING',
'content' => str_replace("\n", $eolChar, $buffer).$char,
);
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t* found end of string *".PHP_EOL;
$content = str_replace("\n", '\n', $buffer.$char);
echo "=> Added token T_CONSTANT_ENCAPSED_STRING $content)".PHP_EOL;
}
 
$buffer = '';
$preStringBuffer = '';
$inString = '';
$stringChar = null;
continue;
}
} else if ($inString === '') {
$inString = $char;
$stringChar = $i;
$preStringBuffer = $buffer;
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t* looking for string closer *".PHP_EOL;
}
}//end if
}//end if
 
if ($inString !== '' && $char === "\n") {
// Unless this newline character is escaped, the string did not
// end before the end of the line, which means it probably
// wasn't a string at all (maybe a regex).
if ($chars[($i - 1)] !== '\\') {
$i = $stringChar;
$buffer = $preStringBuffer;
$preStringBuffer = '';
$inString = '';
$stringChar = null;
$char = $chars[$i];
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t* found newline before end of string, bailing *".PHP_EOL;
}
}
}
 
$buffer .= $char;
 
// We don't look for special tokens inside strings,
// so if we are in a string, we can continue here now
// that the current char is in the buffer.
if ($inString !== '') {
continue;
}
 
// Check for known tokens, but ignore tokens found that are not at
// the end of a string, like FOR and this.FORmat.
if (in_array(strtolower($buffer), $tokenTypes) === true
&& (preg_match('|[a-zA-z0-9_]|', $char) === 0
|| preg_match('|[a-zA-z0-9_]|', $chars[($i + 1)]) === 0)
) {
$matchedToken = false;
$lookAheadLength = ($maxTokenLength - strlen($buffer));
 
if ($lookAheadLength > 0) {
// The buffer contains a token type, but we need
// to look ahead at the next chars to see if this is
// actually part of a larger token. For example,
// FOR and FOREACH.
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t* buffer possibly contains token, looking ahead $lookAheadLength chars *".PHP_EOL;
}
 
$charBuffer = $buffer;
for ($x = 1; $x <= $lookAheadLength; $x++) {
if (isset($chars[($i + $x)]) === false) {
break;
}
 
$charBuffer .= $chars[($i + $x)];
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$content = str_replace("\n", '\n', $charBuffer);
echo "\t=> Looking ahead $x chars => $content".PHP_EOL;
}
 
if (in_array(strtolower($charBuffer), $tokenTypes) === true) {
// We've found something larger that matches
// so we can ignore this char.
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $this->tokenValues[strtolower($charBuffer)];
echo "\t* look ahead found more specific token ($type), ignoring $i *".PHP_EOL;
}
 
$matchedToken = true;
break;
}
}//end for
}//end if
 
if ($matchedToken === false) {
$value = $this->tokenValues[strtolower($buffer)];
$tokens[] = array(
'code' => constant($value),
'type' => $value,
'content' => $buffer,
);
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
if ($lookAheadLength > 0) {
echo "\t* look ahead found nothing *".PHP_EOL;
}
 
$content = str_replace("\n", '\n', $buffer);
echo "=> Added token $value ($content)".PHP_EOL;
}
 
$cleanBuffer = true;
}
} else if (in_array(strtolower($char), $tokenTypes) === true) {
// No matter what token we end up using, we don't
// need the content in the buffer any more because we have
// found a valid token.
$newContent = substr(str_replace("\n", $eolChar, $buffer), 0, -1);
if ($newContent !== '') {
$tokens[] = array(
'code' => T_STRING,
'type' => 'T_STRING',
'content' => $newContent,
);
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$content = str_replace("\n", '\n', substr($buffer, 0, -1));
echo "=> Added token T_STRING ($content)".PHP_EOL;
}
}
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t* char is token, looking ahead ".($maxTokenLength - 1).' chars *'.PHP_EOL;
}
 
// The char is a token type, but we need to look ahead at the
// next chars to see if this is actually part of a larger token.
// For example, = and ===.
$charBuffer = $char;
$matchedToken = false;
for ($x = 1; $x <= $maxTokenLength; $x++) {
if (isset($chars[($i + $x)]) === false) {
break;
}
 
$charBuffer .= $chars[($i + $x)];
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$content = str_replace("\n", '\n', $charBuffer);
echo "\t=> Looking ahead $x chars => $content".PHP_EOL;
}
 
if (in_array(strtolower($charBuffer), $tokenTypes) === true) {
// We've found something larger that matches
// so we can ignore this char.
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $this->tokenValues[strtolower($charBuffer)];
echo "\t* look ahead found more specific token ($type), ignoring $i *".PHP_EOL;
}
 
$matchedToken = true;
break;
}
}//end for
 
if ($matchedToken === false) {
$value = $this->tokenValues[strtolower($char)];
$tokens[] = array(
'code' => constant($value),
'type' => $value,
'content' => $char,
);
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t* look ahead found nothing *".PHP_EOL;
$content = str_replace("\n", '\n', $char);
echo "=> Added token $value ($content)".PHP_EOL;
}
 
$cleanBuffer = true;
} else {
$buffer = $char;
}
}//end if
 
// Keep track of content inside comments.
if ($inComment === ''
&& array_key_exists($buffer, $this->commentTokens) === true
) {
// We have started a comment.
$inComment = $buffer;
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t* looking for end of comment *".PHP_EOL;
}
} else if ($inComment !== '') {
if ($this->commentTokens[$inComment] === null) {
// Comment ends at the next newline.
if (strpos($buffer, "\n") !== false) {
$inComment = '';
}
} else {
if ($this->commentTokens[$inComment] === $buffer) {
$inComment = '';
}
}
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
if ($inComment === '') {
echo "\t* found end of comment *".PHP_EOL;
}
}
 
if ($inComment === '' && $cleanBuffer === false) {
$tokens[] = array(
'code' => T_STRING,
'type' => 'T_STRING',
'content' => str_replace("\n", $eolChar, $buffer),
);
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$content = str_replace("\n", '\n', $buffer);
echo "=> Added token T_STRING ($content)".PHP_EOL;
}
 
$buffer = '';
}
}//end if
 
if ($cleanBuffer === true) {
$buffer = '';
$cleanBuffer = false;
}
}//end foreach
 
// Trim the last newline off the end of the buffer before
// adding it's contents to the token stack.
// This is so we don't count the very final newline of a file.
$buffer = substr($buffer, 0, -1);
 
if (empty($buffer) === false) {
// Buffer contians whitespace from the end of the file, and not
// just the final newline.
$tokens[] = array(
'code' => T_WHITESPACE,
'type' => 'T_WHITESPACE',
'content' => str_replace("\n", $eolChar, $buffer),
);
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$content = str_replace($eolChar, '\n', $buffer);
echo "=> Added token T_WHITESPACE ($content)".PHP_EOL;
}
}
 
$tokens[] = array(
'code' => T_CLOSE_TAG,
'type' => 'T_CLOSE_TAG',
'content' => '',
);
 
/*
Now that we have done some basic tokenizing, we need to
modify the tokens to join some together and split some apart
so they match what the PHP tokenizer does.
*/
 
$finalTokens = array();
$newStackPtr = 0;
$numTokens = count($tokens);
for ($stackPtr = 0; $stackPtr < $numTokens; $stackPtr++) {
$token = $tokens[$stackPtr];
 
/*
Look for regular expressions and join the tokens together.
*/
 
if ($token['code'] === T_DIVIDE) {
$beforeTokens = array(
T_EQUAL,
T_OPEN_PARENTHESIS,
T_RETURN,
);
 
$afterTokens = array(
T_COMMA,
T_CLOSE_PARENTHESIS,
T_SEMICOLON,
T_WHITESPACE,
T_OBJECT_OPERATOR,
);
 
for ($prev = ($stackPtr - 1); $prev >= 0; $prev--) {
if (in_array($tokens[$prev]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
break;
}
}
 
if (in_array($tokens[$prev]['code'], $beforeTokens) === true) {
// This is probably a regular expression,
// so look for the end of it.
for ($next = ($stackPtr + 1); $next < $numTokens; $next++) {
if ($tokens[$next]['code'] === T_DIVIDE) {
// Just make sure this is not escaped first.
if (substr($tokens[($next - 1)]['content'], -1) !== '\\') {
break;
}
} else if (strpos($tokens[$next]['content'], $eolChar) !== false) {
// If this is the last token on the line and regular
// expressions need to be defined on a single line.
break;
}
}
 
if ($tokens[$next]['code'] === T_DIVIDE) {
if ($tokens[($next + 1)]['code'] === T_STRING) {
// The token directly after the end of the regex can
// be modifiers like global and case insensitive
// (.e.g, /pattern/gi).
$next++;
}
 
$regexEnd = $next;
 
for ($next = ($next + 1); $next < $numTokens; $next++) {
if (in_array($tokens[$next]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
break;
} else if (strpos($tokens[$next]['content'], $eolChar) !== false) {
// If this is the last token on the line.
break;
}
}
 
if (in_array($tokens[$next]['code'], $afterTokens) === true) {
// This is a regular expression, so join all the
// tokens together.
for ($i = ($stackPtr + 1); $i <= $regexEnd; $i++) {
$token['content'] .= $tokens[$i]['content'];
}
 
$token['code'] = T_REGULAR_EXPRESSION;
$token['type'] = 'T_REGULAR_EXPRESSION';
$stackPtr = $regexEnd;
}
}//end if
}//end if
}//end if
 
/*
Look for comments and join the tokens together.
*/
 
if (array_key_exists($token['content'], $this->commentTokens) === true) {
$newContent = '';
$tokenContent = $token['content'];
$endContent = $this->commentTokens[$tokenContent];
while ($tokenContent !== $endContent) {
if ($endContent === null
&& strpos($tokenContent, $eolChar) !== false
) {
// A null end token means the comment ends at the end of
// the line so we look for newlines and split the token.
$tokens[$stackPtr]['content'] = substr(
$tokenContent,
(strpos($tokenContent, $eolChar) + strlen($eolChar))
);
 
$tokenContent = substr(
$tokenContent,
0,
(strpos($tokenContent, $eolChar) + strlen($eolChar))
);
 
// If the substr failed, skip the token as the content
// will now be blank.
if ($tokens[$stackPtr]['content'] !== false) {
$stackPtr--;
}
 
break;
}//end if
 
$stackPtr++;
$newContent .= $tokenContent;
if (isset($tokens[$stackPtr]) === false) {
break;
}
 
$tokenContent = $tokens[$stackPtr]['content'];
}//end while
 
// Save the new content in the current token so
// the code below can chop it up on newlines.
$token['content'] = $newContent.$tokenContent;
}//end if
 
/*
If this token has newlines in its content, split each line up
and create a new token for each line. We do this so it's easier
to asertain where errors occur on a line.
Note that $token[1] is the token's content.
*/
 
if (strpos($token['content'], $eolChar) !== false) {
$tokenLines = explode($eolChar, $token['content']);
$numLines = count($tokenLines);
 
for ($i = 0; $i < $numLines; $i++) {
$newToken['content'] = $tokenLines[$i];
if ($i === ($numLines - 1)) {
if ($tokenLines[$i] === '') {
break;
}
} else {
$newToken['content'] .= $eolChar;
}
 
$newToken['type'] = $token['type'];
$newToken['code'] = $token['code'];
$finalTokens[$newStackPtr] = $newToken;
$newStackPtr++;
}
} else {
$finalTokens[$newStackPtr] = $token;
$newStackPtr++;
}//end if
 
// Convert numbers, including decimals.
if ($token['code'] === T_STRING
|| $token['code'] === T_OBJECT_OPERATOR
) {
$newContent = '';
$oldStackPtr = $stackPtr;
while (preg_match('|^[0-9\.]+$|', $tokens[$stackPtr]['content']) !== 0) {
$newContent .= $tokens[$stackPtr]['content'];
$stackPtr++;
}
 
if ($newContent !== '' && $newContent !== '.') {
$finalTokens[($newStackPtr - 1)]['content'] = $newContent;
if (ctype_digit($newContent) === true) {
$finalTokens[($newStackPtr - 1)]['code']
= constant('T_LNUMBER');
$finalTokens[($newStackPtr - 1)]['type'] = 'T_LNUMBER';
} else {
$finalTokens[($newStackPtr - 1)]['code']
= constant('T_DNUMBER');
$finalTokens[($newStackPtr - 1)]['type'] = 'T_DNUMBER';
}
 
$stackPtr--;
} else {
$stackPtr = $oldStackPtr;
}
}//end if
}//end for
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t*** END TOKENIZING ***".PHP_EOL;
}
 
return $finalTokens;
 
}//end tokenizeString()
 
 
/**
* Performs additional processing after main tokenizing.
*
* This additional processing looks for properties, labels and objects.
*
* @param array &$tokens The array of tokens to process.
* @param string $eolChar The EOL character to use for splitting strings.
*
* @return void
*/
public function processAdditional(&$tokens, $eolChar)
{
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t*** START ADDITIONAL JS PROCESSING ***".PHP_EOL;
}
 
$numTokens = count($tokens);
$classStack = array();
 
for ($i = 0; $i < $numTokens; $i++) {
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$i]['type'];
$content = str_replace($eolChar, '\n', $tokens[$i]['content']);
echo str_repeat("\t", count($classStack));
 
echo "\tProcess token $i: $type => $content".PHP_EOL;
}
 
if ($tokens[$i]['code'] === T_OPEN_CURLY_BRACKET
&& isset($tokens[$i]['scope_condition']) === false
) {
$classStack[] = $i;
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", count($classStack));
echo "\t=> Found property opener".PHP_EOL;
}
 
// This could also be an object definition.
for ($x = ($i - 1); $x >= 0; $x--) {
if (in_array($tokens[$x]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
// Non-whitespace content.
break;
}
}
 
if ($tokens[$x]['code'] === T_EQUAL) {
for ($x--; $x >= 0; $x--) {
if (in_array($tokens[$x]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
break;
}
}
 
if ($tokens[$x]['code'] === T_STRING
|| $tokens[$x]['code'] === T_PROTOTYPE
) {
// Find the first string in this definition.
// E.g., WantedString.DontWantThis.prototype
for ($x--; $x >= 0; $x--) {
$wantedTokens = array(
T_STRING,
T_PROTOTYPE,
T_OBJECT_OPERATOR,
);
 
if (in_array($tokens[$x]['code'], $wantedTokens) === false) {
$x++;
break;
}
}
 
$closer = $tokens[$i]['bracket_closer'];
$tokens[$i]['scope_condition'] = $x;
$tokens[$i]['scope_closer'] = $closer;
$tokens[$closer]['scope_condition'] = $x;
$tokens[$closer]['scope_opener'] = $i;
$tokens[$x]['scope_opener'] = $i;
$tokens[$x]['scope_closer'] = $closer;
$tokens[$x]['code'] = T_OBJECT;
$tokens[$x]['type'] = 'T_OBJECT';
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", count($classStack));
echo "\t* token $x converted from T_STRING to T_OBJECT *".PHP_EOL;
echo str_repeat("\t", count($classStack));
echo "\t* set scope opener ($i) and closer ($closer) for token $x *".PHP_EOL;
}
}//end if
}//end if
} else if ($tokens[$i]['code'] === T_CLOSE_CURLY_BRACKET
&& (isset($tokens[$i]['scope_condition']) === false
|| $tokens[$tokens[$i]['scope_condition']]['code'] === T_OBJECT)
) {
$opener = array_pop($classStack);
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", count($classStack));
echo "\t\t=> Found property closer for $opener".PHP_EOL;
}
} else if ($tokens[$i]['code'] === T_COLON) {
// If it is a scope opener, it belongs to a
// DEFAULT or CASE statement.
if (isset($tokens[$i]['scope_condition']) === true) {
continue;
}
 
// Make sure this is not part of an inline IF statement.
for ($x = ($i - 1); $x >= 0; $x--) {
if ($tokens[$x]['code'] === T_INLINE_THEN) {
continue(2);
} else if ($tokens[$x]['line'] < $tokens[$i]['line']) {
break;
}
}
 
// The string to the left of the colon is either a property or label.
for ($label = ($i - 1); $label >= 0; $label--) {
if (in_array($tokens[$label]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
break;
}
}
 
if ($tokens[$label]['code'] !== T_STRING) {
continue;
}
 
if (empty($classStack) === false) {
$tokens[$label]['code'] = T_PROPERTY;
$tokens[$label]['type'] = 'T_PROPERTY';
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", count($classStack));
echo "\t* token $label converted from T_STRING to T_PROPERTY *".PHP_EOL;
}
 
// If the net token after the colon is a curly brace,
// this property is actually an object, so we can give it
// and opener and closer.
for ($x = ($i + 1); $x < $numTokens; $x++) {
if (in_array($tokens[$x]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === false) {
break;
}
}
 
if ($tokens[$x]['code'] === T_OPEN_CURLY_BRACKET) {
$closer = $tokens[$x]['bracket_closer'];
$tokens[$label]['scope_opener'] = $x;
$tokens[$label]['scope_closer'] = $closer;
$tokens[$x]['scope_condition'] = $label;
$tokens[$x]['scope_closer'] = $closer;
$tokens[$closer]['scope_condition'] = $label;
$tokens[$closer]['scope_opener'] = $x;
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", count($classStack));
echo "\t* set scope opener ($x) and closer ($closer) for token $label *".PHP_EOL;
}
}
} else {
$tokens[$label]['code'] = T_LABEL;
$tokens[$label]['type'] = 'T_LABEL';
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo str_repeat("\t", count($classStack));
echo "\t* token $label converted from T_STRING to T_LABEL *".PHP_EOL;
}
}
}//end if
}//end for
 
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t*** END ADDITIONAL JS PROCESSING ***".PHP_EOL;
}
 
}//end processAdditional()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/CommentParser/AbstractDocElement.php
New file
0,0 → 1,342
<?php
/**
* A class to handle most of the parsing operations of a doc comment element.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: AbstractDocElement.php,v 1.11 2008/12/02 02:38:33 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (interface_exists('PHP_CodeSniffer_CommentParser_DocElement', true) === false) {
$error = 'Interface PHP_CodeSniffer_CommentParser_DocElement not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* A class to handle most of the parsing operations of a doc comment element.
*
* Extending classes should implement the getSubElements method to return
* a list of elements that the doc comment element contains, in the order that
* they appear in the element. For example a function parameter element has a
* type, a variable name and a comment. It should therefore implement the method
* as follows:
*
* <code>
* protected function getSubElements()
* {
* return array(
* 'type',
* 'variable',
* 'comment',
* );
* }
* </code>
*
* The processSubElement will be called for each of the sub elements to allow
* the extending class to process them. So for the parameter element we would
* have:
*
* <code>
* protected function processSubElement($name, $content, $whitespaceBefore)
* {
* if ($name === 'type') {
* echo 'The name of the variable was '.$content;
* }
* // Process other tags.
* }
* </code>
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
abstract class PHP_CodeSniffer_CommentParser_AbstractDocElement implements PHP_CodeSniffer_CommentParser_DocElement
{
 
/**
* The element previous to this element.
*
* @var PHP_CodeSniffer_CommentParser_DocElement
*/
protected $previousElement = null;
 
/**
* The element proceeding this element.
*
* @var PHP_CodeSniffer_CommentParser_DocElement
*/
protected $nextElement = null;
 
/**
* The whitespace the occurs after this element and its sub elements.
*
* @var string
*/
protected $afterWhitespace = '';
 
/**
* The tokens that comprise this element.
*
* @var array(string)
*/
protected $tokens = array();
 
/**
* The file this element is in.
*
* @var array(string)
*/
protected $phpcsFile = null;
 
/**
* The tag that this element represents (omiting the @ symbol).
*
* @var string
*/
protected $tag = '';
 
 
/**
* Constructs a Doc Element.
*
* @param PHP_CodeSniffer_CommentParser_DocElement $previousElement The element
* that ocurred
* before this.
* @param array $tokens The tokens of
* this element.
* @param string $tag The doc
* element tag
* this element
* represents.
* @param PHP_CodeSniffer_File $phpcsFile The file that
* this element
* is in.
*
* @throws Exception If $previousElement in not a DocElement or if
* getSubElements() does not return an array.
*/
public function __construct(
$previousElement,
array $tokens,
$tag,
PHP_CodeSniffer_File $phpcsFile
) {
if ($previousElement !== null
&& ($previousElement instanceof PHP_CodeSniffer_CommentParser_DocElement) === false
) {
$error = '$previousElement must be an instance of DocElement';
throw new Exception($error);
}
 
$this->phpcsFile = $phpcsFile;
 
$this->previousElement = $previousElement;
if ($previousElement !== null) {
$this->previousElement->nextElement = $this;
}
 
$this->tag = $tag;
$this->tokens = $tokens;
 
$subElements = $this->getSubElements();
 
if (is_array($subElements) === false) {
throw new Exception('getSubElements() must return an array');
}
 
$whitespace = '';
$currElem = 0;
$lastElement = '';
$lastElementWhitespace = null;
$numSubElements = count($subElements);
 
foreach ($this->tokens as $token) {
if (trim($token) === '') {
$whitespace .= $token;
} else {
if ($currElem < ($numSubElements - 1)) {
$element = $subElements[$currElem];
$this->processSubElement($element, $token, $whitespace);
$whitespace = '';
$currElem++;
} else {
if ($lastElementWhitespace === null) {
$lastElementWhitespace = $whitespace;
}
 
$lastElement .= $whitespace.$token;
$whitespace = '';
}
}
}//end foreach
 
$lastElement = ltrim($lastElement);
$lastElementName = $subElements[($numSubElements - 1)];
 
// Process the last element in this tag.
$this->processSubElement(
$lastElementName,
$lastElement,
$lastElementWhitespace
);
 
$this->afterWhitespace = $whitespace;
 
}//end __construct()
 
 
/**
* Returns the element that exists before this.
*
* @return PHP_CodeSniffer_CommentParser_DocElement
*/
public function getPreviousElement()
{
return $this->previousElement;
 
}//end getPreviousElement()
 
 
/**
* Returns the element that exists after this.
*
* @return PHP_CodeSniffer_CommentParser_DocElement
*/
public function getNextElement()
{
return $this->nextElement;
 
}//end getNextElement()
 
 
/**
* Returns the whitespace that exists before this element.
*
* @return string
*/
public function getWhitespaceBefore()
{
if ($this->previousElement !== null) {
return $this->previousElement->getWhitespaceAfter();
}
 
return '';
 
}//end getWhitespaceBefore()
 
 
/**
* Returns the whitespace that exists after this element.
*
* @return string
*/
public function getWhitespaceAfter()
{
return $this->afterWhitespace;
 
}//end getWhitespaceAfter()
 
 
/**
* Returns the order that this element appears in the comment.
*
* @return int
*/
public function getOrder()
{
if ($this->previousElement === null) {
return 1;
} else {
return ($this->previousElement->getOrder() + 1);
}
 
}//end getOrder()
 
 
/**
* Returns the tag that this element represents, ommiting the @ symbol.
*
* @return string
*/
public function getTag()
{
return $this->tag;
 
}//end getTag()
 
 
/**
* Returns the raw content of this element, ommiting the tag.
*
* @return string
*/
public function getRawContent()
{
return implode('', $this->tokens);
 
}//end getRawContent()
 
 
/**
* Returns the line in which this element first occured.
*
* @return int
*/
public function getLine()
{
if ($this->previousElement === null) {
// First element is on line one.
return 1;
} else {
$previousContent = $this->previousElement->getRawContent();
$previousLine = $this->previousElement->getLine();
 
return ($previousLine + substr_count($previousContent, $this->phpcsFile->eolChar));
}
 
}//end getLine()
 
 
/**
* Returns the sub element names that make up this element in the order they
* appear in the element.
*
* @return array(string)
* @see processSubElement()
*/
abstract protected function getSubElements();
 
 
/**
* Called to process each sub element as sepcified in the return value
* of getSubElements().
*
* @param string $name The name of the element to process.
* @param string $content The content of the the element.
* @param string $whitespaceBefore The whitespace found before this element.
*
* @return void
* @see getSubElements()
*/
abstract protected function processSubElement(
$name,
$content,
$whitespaceBefore
);
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/CommentParser/ClassCommentParser.php
New file
0,0 → 1,342
<?php
/**
* Parses Class doc comments.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ClassCommentParser.php,v 1.12 2008/12/02 02:38:33 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractParser', true) === false) {
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractParser not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* Parses Class doc comments.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_CommentParser_ClassCommentParser extends PHP_CodeSniffer_CommentParser_AbstractParser
{
 
/**
* The package element of this class.
*
* @var SingleElement
*/
private $_package = null;
 
/**
* The subpackage element of this class.
*
* @var SingleElement
*/
private $_subpackage = null;
 
/**
* The version element of this class.
*
* @var SingleElement
*/
private $_version = null;
 
/**
* The category element of this class.
*
* @var SingleElement
*/
private $_category = null;
 
/**
* The copyright elements of this class.
*
* @var array(SingleElement)
*/
private $_copyrights = array();
 
/**
* The licence element of this class.
*
* @var PairElement
*/
private $_license = null;
 
/**
* The author elements of this class.
*
* @var array(SingleElement)
*/
private $_authors = array();
 
 
/**
* Returns the allowed tags withing a class comment.
*
* @return array(string => int)
*/
protected function getAllowedTags()
{
return array(
'category' => false,
'package' => true,
'subpackage' => true,
'author' => false,
'copyright' => true,
'license' => false,
'version' => true,
);
 
}//end getAllowedTags()
 
 
/**
* Parses the license tag of this class comment.
*
* @param array $tokens The tokens that comprise this tag.
*
* @return PHP_CodeSniffer_CommentParser_PairElement
*/
protected function parseLicense($tokens)
{
$this->_license = new PHP_CodeSniffer_CommentParser_PairElement(
$this->previousElement,
$tokens,
'license',
$this->phpcsFile
);
 
return $this->_license;
 
}//end parseLicense()
 
 
/**
* Parses the copyright tags of this class comment.
*
* @param array $tokens The tokens that comprise this tag.
*
* @return PHP_CodeSniffer_CommentParser_SingleElement
*/
protected function parseCopyright($tokens)
{
$copyright = new PHP_CodeSniffer_CommentParser_SingleElement(
$this->previousElement,
$tokens,
'copyright',
$this->phpcsFile
);
 
$this->_copyrights[] = $copyright;
return $copyright;
 
}//end parseCopyright()
 
 
/**
* Parses the category tag of this class comment.
*
* @param array $tokens The tokens that comprise this tag.
*
* @return PHP_CodeSniffer_CommentParser_SingleElement
*/
protected function parseCategory($tokens)
{
$this->_category = new PHP_CodeSniffer_CommentParser_SingleElement(
$this->previousElement,
$tokens,
'category',
$this->phpcsFile
);
 
return $this->_category;
 
}//end parseCategory()
 
 
/**
* Parses the author tag of this class comment.
*
* @param array $tokens The tokens that comprise this tag.
*
* @return array(PHP_CodeSniffer_CommentParser_SingleElement)
*/
protected function parseAuthor($tokens)
{
$author = new PHP_CodeSniffer_CommentParser_SingleElement(
$this->previousElement,
$tokens,
'author',
$this->phpcsFile
);
 
$this->_authors[] = $author;
return $author;
 
}//end parseAuthor()
 
 
/**
* Parses the version tag of this class comment.
*
* @param array $tokens The tokens that comprise this tag.
*
* @return PHP_CodeSniffer_CommentParser_SingleElement
*/
protected function parseVersion($tokens)
{
$this->_version = new PHP_CodeSniffer_CommentParser_SingleElement(
$this->previousElement,
$tokens,
'version',
$this->phpcsFile
);
 
return $this->_version;
 
}//end parseVersion()
 
 
/**
* Parses the package tag found in this test.
*
* @param array $tokens The tokens that comprise this var.
*
* @return PHP_CodeSniffer_CommentParser_SingleElement
*/
protected function parsePackage($tokens)
{
$this->_package = new PHP_CodeSniffer_CommentParser_SingleElement(
$this->previousElement,
$tokens,
'package',
$this->phpcsFile
);
 
return $this->_package;
 
}//end parsePackage()
 
 
/**
* Parses the package tag found in this test.
*
* @param array $tokens The tokens that comprise this var.
*
* @return PHP_CodeSniffer_CommentParser_SingleElement
*/
protected function parseSubpackage($tokens)
{
$this->_subpackage = new PHP_CodeSniffer_CommentParser_SingleElement(
$this->previousElement,
$tokens,
'subpackage',
$this->phpcsFile
);
 
return $this->_subpackage;
 
}//end parseSubpackage()
 
 
/**
* Returns the authors of this class comment.
*
* @return array(PHP_CodeSniffer_CommentParser_SingleElement)
*/
public function getAuthors()
{
return $this->_authors;
 
}//end getAuthors()
 
 
/**
* Returns the version of this class comment.
*
* @return PHP_CodeSniffer_CommentParser_SingleElement
*/
public function getVersion()
{
return $this->_version;
 
}//end getVersion()
 
 
/**
* Returns the license of this class comment.
*
* @return PHP_CodeSniffer_CommentParser_PairElement
*/
public function getLicense()
{
return $this->_license;
 
}//end getLicense()
 
 
/**
* Returns the copyrights of this class comment.
*
* @return PHP_CodeSniffer_CommentParser_SingleElement
*/
public function getCopyrights()
{
return $this->_copyrights;
 
}//end getCopyrights()
 
 
/**
* Returns the category of this class comment.
*
* @return PHP_CodeSniffer_CommentParser_SingleElement
*/
public function getCategory()
{
return $this->_category;
 
}//end getCategory()
 
 
/**
* Returns the package that this class belongs to.
*
* @return PHP_CodeSniffer_CommentParser_SingleElement
*/
public function getPackage()
{
return $this->_package;
 
}//end getPackage()
 
 
/**
* Returns the subpackage that this class belongs to.
*
* @return PHP_CodeSniffer_CommentParser_SingleElement
*/
public function getSubpackage()
{
return $this->_subpackage;
 
}//end getSubpackage()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/CommentParser/FunctionCommentParser.php
New file
0,0 → 1,213
<?php
/**
* Parses function doc comments.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: FunctionCommentParser.php,v 1.9 2008/12/02 02:38:33 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractParser', true) === false) {
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractParser not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
if (class_exists('PHP_CodeSniffer_CommentParser_ParameterElement', true) === false) {
$error = 'Class PHP_CodeSniffer_CommentParser_ParameterElement not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
if (class_exists('PHP_CodeSniffer_CommentParser_PairElement', true) === false) {
$error = 'Class PHP_CodeSniffer_CommentParser_PairElement not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
if (class_exists('PHP_CodeSniffer_CommentParser_SingleElement', true) === false) {
$error = 'Class PHP_CodeSniffer_CommentParser_SingleElement not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* Parses function doc comments.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_CommentParser_FunctionCommentParser extends PHP_CodeSniffer_CommentParser_AbstractParser
{
 
/**
* The parameter elements within this function comment.
*
* @var array(PHP_CodeSniffer_CommentParser_ParameterElement)
*/
private $_params = array();
 
/**
* The return element in this function comment.
*
* @var PHP_CodeSniffer_CommentParser_PairElement.
*/
private $_return = null;
 
/**
* The throws element list for this function comment.
*
* @var array(PHP_CodeSniffer_CommentParser_PairElement)
*/
private $_throws = array();
 
 
/**
* Constructs a PHP_CodeSniffer_CommentParser_FunctionCommentParser.
*
* @param string $comment The comment to parse.
* @param PHP_CodeSniffer_File $phpcsFile The file that this comment is in.
*/
public function __construct($comment, PHP_CodeSniffer_File $phpcsFile)
{
parent::__construct($comment, $phpcsFile);
 
}//end __construct()
 
 
/**
* Parses parameter elements.
*
* @param array(string) $tokens The tokens that conmpise this sub element.
*
* @return PHP_CodeSniffer_CommentParser_ParameterElement
*/
protected function parseParam($tokens)
{
$param = new PHP_CodeSniffer_CommentParser_ParameterElement(
$this->previousElement,
$tokens,
$this->phpcsFile
);
 
$this->_params[] = $param;
return $param;
 
}//end parseParam()
 
 
/**
* Parses return elements.
*
* @param array(string) $tokens The tokens that conmpise this sub element.
*
* @return PHP_CodeSniffer_CommentParser_PairElement
*/
protected function parseReturn($tokens)
{
$return = new PHP_CodeSniffer_CommentParser_PairElement(
$this->previousElement,
$tokens,
'return',
$this->phpcsFile
);
 
$this->_return = $return;
return $return;
 
}//end parseReturn()
 
 
/**
* Parses throws elements.
*
* @param array(string) $tokens The tokens that conmpise this sub element.
*
* @return PHP_CodeSniffer_CommentParser_PairElement
*/
protected function parseThrows($tokens)
{
$throws = new PHP_CodeSniffer_CommentParser_PairElement(
$this->previousElement,
$tokens,
'throws',
$this->phpcsFile
);
 
$this->_throws[] = $throws;
return $throws;
 
}//end parseThrows()
 
 
/**
* Returns the parameter elements that this function comment contains.
*
* Returns an empty array if no parameter elements are contained within
* this function comment.
*
* @return array(PHP_CodeSniffer_CommentParser_ParameterElement)
*/
public function getParams()
{
return $this->_params;
 
}//end getParams()
 
 
/**
* Returns the return element in this fucntion comment.
*
* Returns null if no return element exists in the comment.
*
* @return PHP_CodeSniffer_CommentParser_PairElement
*/
public function getReturn()
{
return $this->_return;
 
}//end getReturn()
 
 
/**
* Returns the throws elements in this fucntion comment.
*
* Returns empty array if no throws elements in the comment.
*
* @return array(PHP_CodeSniffer_CommentParser_PairElement)
*/
public function getThrows()
{
return $this->_throws;
 
}//end getThrows()
 
 
/**
* Returns the allowed tags that can exist in a function comment.
*
* @return array(string => boolean)
*/
protected function getAllowedTags()
{
return array(
'param' => false,
'return' => true,
'throws' => false,
);
 
}//end getAllowedTags()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/CommentParser/PairElement.php
New file
0,0 → 1,172
<?php
/**
* A class to represent elements that have a value => comment format.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: PairElement.php,v 1.9 2008/12/02 02:38:33 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractDocElement', true) === false) {
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractDocElement not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* A class to represent elements that have a value => comment format.
*
* An example of a pair element tag is the \@throws as it has an exception type
* and a comment on the circumstance of when the exception is thrown.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_CommentParser_PairElement extends PHP_CodeSniffer_CommentParser_AbstractDocElement
{
 
/**
* The value of the tag.
*
* @var string
*/
private $_value = '';
 
/**
* The comment of the tag.
*
* @var string
*/
private $_comment = '';
 
/**
* The whitespace that exists before the value elem.
*
* @var string
*/
private $_valueWhitespace = '';
 
/**
* The whitespace that exists before the comment elem.
*
* @var string
*/
private $_commentWhitespace = '';
 
 
/**
* Constructs a PHP_CodeSniffer_CommentParser_PairElement doc tag.
*
* @param PHP_CodeSniffer_CommentParser_DocElement $previousElement The element
* before this
* one.
* @param array $tokens The tokens
* that comprise
* this element.
* @param string $tag The tag that
* this element
* represents.
* @param PHP_CodeSniffer_File $phpcsFile The file that
* this element
* is in.
*/
public function __construct(
$previousElement,
$tokens,
$tag,
PHP_CodeSniffer_File $phpcsFile
) {
parent::__construct($previousElement, $tokens, $tag, $phpcsFile);
 
}//end __construct()
 
 
/**
* Returns the element names that this tag is comprised of, in the order
* that they appear in the tag.
*
* @return array(string)
* @see processSubElement()
*/
protected function getSubElements()
{
return array(
'value',
'comment',
);
 
}//end getSubElements()
 
 
/**
* Processes the sub element with the specified name.
*
* @param string $name The name of the sub element to process.
* @param string $content The content of this sub element.
* @param string $whitespaceBefore The whitespace that exists before the
* sub element.
*
* @return void
* @see getSubElements()
*/
protected function processSubElement($name, $content, $whitespaceBefore)
{
$element = '_'.$name;
$whitespace = $element.'Whitespace';
$this->$element = $content;
$this->$whitespace = $whitespaceBefore;
 
}//end processSubElement()
 
 
/**
* Returns the value of the tag.
*
* @return string
*/
public function getValue()
{
return $this->_value;
 
}//end getValue()
 
 
/**
* Returns the comment associated with the value of this tag.
*
* @return string
*/
public function getComment()
{
return $this->_comment;
 
}//end getComment()
 
 
/**
* Returns the witespace before the content of this tag.
*
* @return string
*/
public function getWhitespaceBeforeValue()
{
return $this->_valueWhitespace;
 
}//end getWhitespaceBeforeValue()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/CommentParser/MemberCommentParser.php
New file
0,0 → 1,92
<?php
/**
* Parses class member comments.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: MemberCommentParser.php,v 1.10 2008/12/02 02:38:33 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_CommentParser_ClassCommentParser', true) === false) {
$error = 'Class PHP_CodeSniffer_CommentParser_ClassCommentParser not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* Parses class member comments.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_CommentParser_MemberCommentParser extends PHP_CodeSniffer_CommentParser_ClassCommentParser
{
 
/**
* Represents a \@var tag in a member comment.
*
* @var PHP_CodeSniffer_CommentParser_SingleElement
*/
private $_var = null;
 
 
/**
* Parses Var tags.
*
* @param array $tokens The tokens that represent this tag.
*
* @return PHP_CodeSniffer_CommentParser_SingleElement
*/
protected function parseVar($tokens)
{
$this->_var = new PHP_CodeSniffer_CommentParser_SingleElement(
$this->previousElement,
$tokens,
'var',
$this->phpcsFile
);
 
return $this->_var;
 
}//end parseVar()
 
 
/**
* Returns the var tag found in the member comment.
*
* @return PHP_CodeSniffer_CommentParser_PairElement
*/
public function getVar()
{
return $this->_var;
 
}//end getVar()
 
 
/**
* Returns the allowed tags for this parser.
*
* @return array
*/
protected function getAllowedTags()
{
return array('var' => true);
 
}//end getAllowedTags()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/CommentParser/ParameterElement.php
New file
0,0 → 1,335
<?php
/**
* A class to represent param tags within a function comment.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ParameterElement.php,v 1.14 2008/12/02 02:38:33 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractDocElement', true) === false) {
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractDocElement not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* A class to represent param tags within a function comment.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_CommentParser_ParameterElement extends PHP_CodeSniffer_CommentParser_AbstractDocElement
{
 
/**
* The variable name of this parameter name, including the $ sign.
*
* @var string
*/
private $_varName = '';
 
/**
* The comment of this parameter tag.
*
* @var string
*/
private $_comment = '';
 
/**
* The variable type of this parameter tag.
*
* @var string
*/
private $_type = '';
 
/**
* The whitespace that exists before the variable name.
*
* @var string
*/
private $_varNameWhitespace = '';
 
/**
* The whitespace that exists before the comment.
*
* @var string
*/
private $_commentWhitespace = null;
 
/**
* The whitespace that exists before the variable type.
*
* @var string
*/
private $_typeWhitespace = '';
 
 
/**
* Constructs a PHP_CodeSniffer_CommentParser_ParameterElement.
*
* @param PHP_CodeSniffer_CommentParser_DocElement $previousElement The element
* previous to
* this one.
* @param array $tokens The tokens
* that make up
* this element.
* @param PHP_CodeSniffer_File $phpcsFile The file that
* this element
* is in.
*/
public function __construct(
$previousElement,
$tokens,
PHP_CodeSniffer_File $phpcsFile
) {
parent::__construct($previousElement, $tokens, 'param', $phpcsFile);
 
// Handle special variable type: array(x => y).
$type = strtolower($this->_type);
if ($this->_varName === '=>' && strpos($type, 'array(') !== false) {
$rawContent = $this->getRawContent();
$matches = array();
$pattern = '/^(\s+)(array\(.*\))(\s+)(\$\S*)(\s+)(.*)/i';
if (preg_match($pattern, $rawContent, $matches) !== 0) {
// Process the sub elements correctly for this special case.
if (count($matches) === 7) {
$this->processSubElement('type', $matches[2], $matches[1]);
$this->processSubElement('varName', $matches[4], $matches[3]);
$this->processSubElement('comment', $matches[6], $matches[5]);
}
}
}
 
}//end __construct()
 
 
/**
* Returns the element names that this tag is comprised of, in the order
* that they appear in the tag.
*
* @return array(string)
* @see processSubElement()
*/
protected function getSubElements()
{
return array(
'type',
'varName',
'comment',
);
 
}//end getSubElements()
 
 
/**
* Processes the sub element with the specified name.
*
* @param string $name The name of the sub element to process.
* @param string $content The content of this sub element.
* @param string $beforeWhitespace The whitespace that exists before the
* sub element.
*
* @return void
* @see getSubElements()
*/
protected function processSubElement($name, $content, $beforeWhitespace)
{
$element = '_'.$name;
$whitespace = $element.'Whitespace';
$this->$element = $content;
$this->$whitespace = $beforeWhitespace;
 
}//end processSubElement()
 
 
/**
* Returns the variable name that this parameter tag represents.
*
* @return string
*/
public function getVarName()
{
return $this->_varName;
 
}//end getVarName()
 
 
/**
* Returns the variable type that this string represents.
*
* @return string
*/
public function getType()
{
return $this->_type;
 
}//end getType()
 
 
/**
* Returns the comment of this comment for this parameter.
*
* @return string
*/
public function getComment()
{
return $this->_comment;
 
}//end getComment()
 
 
/**
* Returns the whitespace before the variable type.
*
* @return stirng
* @see getWhiteSpaceBeforeVarName()
* @see getWhiteSpaceBeforeComment()
*/
public function getWhiteSpaceBeforeType()
{
return $this->_typeWhitespace;
 
}//end getWhiteSpaceBeforeType()
 
 
/**
* Returns the whitespace before the variable name.
*
* @return string
* @see getWhiteSpaceBeforeComment()
* @see getWhiteSpaceBeforeType()
*/
public function getWhiteSpaceBeforeVarName()
{
return $this->_varNameWhitespace;
 
}//end getWhiteSpaceBeforeVarName()
 
 
/**
* Returns the whitespace before the comment.
*
* @return string
* @see getWhiteSpaceBeforeVarName()
* @see getWhiteSpaceBeforeType()
*/
public function getWhiteSpaceBeforeComment()
{
return $this->_commentWhitespace;
 
}//end getWhiteSpaceBeforeComment()
 
 
/**
* Returns the postition of this parameter are it appears in the comment.
*
* This method differs from getOrder as it is only relative to method
* parameters.
*
* @return int
*/
public function getPosition()
{
if (($this->getPreviousElement() instanceof PHP_CodeSniffer_CommentParser_ParameterElement) === false) {
return 1;
} else {
return ($this->getPreviousElement()->getPosition() + 1);
}
 
}//end getPosition()
 
 
/**
* Returns true if this parameter's variable aligns with the other's.
*
* @param PHP_CodeSniffer_CommentParser_ParameterElement $other The other param
* to check
* alignment with.
*
* @return boolean
*/
public function alignsVariableWith(
PHP_CodeSniffer_CommentParser_ParameterElement $other
) {
// Format is:
// @param type $variable Comment.
// @param <-a-><---b---->
// Compares the index before param variable.
$otherVar = (strlen($other->_type) + strlen($other->_varNameWhitespace));
$thisVar = (strlen($this->_type) + strlen($this->_varNameWhitespace));
if ($otherVar !== $thisVar) {
return false;
}
 
return true;
 
}//end alignsVariableWith()
 
 
/**
* Returns true if this parameter's comment aligns with the other's.
*
* @param PHP_CodeSniffer_CommentParser_ParameterElement $other The other param
* to check
* alignment with.
*
* @return boolean
*/
public function alignsCommentWith(
PHP_CodeSniffer_CommentParser_ParameterElement $other
) {
// Compares the index before param comment.
$otherComment
= (strlen($other->_varName) + strlen($other->_commentWhitespace));
$thisComment
= (strlen($this->_varName) + strlen($this->_commentWhitespace));
 
if ($otherComment !== $thisComment) {
return false;
}
 
return true;
 
}//end alignsCommentWith()
 
 
/**
* Returns true if this parameter aligns with the other paramter.
*
* @param PHP_CodeSniffer_CommentParser_ParameterElement $other The other param
* to check
* alignment with.
*
* @return boolean
*/
public function alignsWith(PHP_CodeSniffer_CommentParser_ParameterElement $other)
{
if ($this->alignsVariableWith($other) === false) {
return false;
}
 
if ($this->alignsCommentWith($other) === false) {
return false;
}
 
return true;
 
}//end alignsWith()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/CommentParser/ParserException.php
New file
0,0 → 1,72
<?php
/**
* An exception to be thrown when a DocCommentParser finds an anomilty in a
* doc comment.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: ParserException.php,v 1.2 2006/12/11 23:59:35 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* An exception to be thrown when a DocCommentParser finds an anomilty in a
* doc comment.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_CommentParser_ParserException extends Exception
{
 
/**
* The line where the exception occured, in relation to the doc comment.
*
* @var int
*/
private $_line = 0;
 
 
/**
* Constructs a DocCommentParserException.
*
* @param string $message The message of the exception.
* @param int $line The position in comment where the error occured.
* A position of 0 indicates that the error occured
* at the opening line of the doc comment.
*/
public function __construct($message, $line)
{
parent::__construct($message);
$this->_line = $line;
 
}//end __construct()
 
 
/**
* Returns the line number within the comment where the exception occured.
*
* @return int
*/
public function getLineWithinComment()
{
return $this->_line;
 
}//end getLineWithinComment()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/CommentParser/SingleElement.php
New file
0,0 → 1,168
<?php
/**
* A class to represent single element doc tags.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: SingleElement.php,v 1.13 2008/12/02 02:38:33 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractDocElement', true) === false) {
$error = 'Class PHP_CodeSniffer_CommentParser_AbstractDocElement not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* A class to represent single element doc tags.
*
* A single element doc tag contains only one value after the tag itself. An
* example would be the \@package tag.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_CommentParser_SingleElement extends PHP_CodeSniffer_CommentParser_AbstractDocElement
{
 
/**
* The content that exists after the tag.
*
* @var string
* @see getContent()
*/
protected $content = '';
 
/**
* The whitespace that exists before the content.
*
* @var string
* @see getWhitespaceBeforeContent()
*/
protected $contentWhitespace = '';
 
 
/**
* Constructs a SingleElement doc tag.
*
* @param PHP_CodeSniffer_CommentParser_DocElement $previousElement The element
* before this
* one.
* @param array $tokens The tokens
* that comprise
* this element.
* @param string $tag The tag that
* this element
* represents.
* @param PHP_CodeSniffer_File $phpcsFile The file that
* this element
* is in.
*/
public function __construct(
$previousElement,
$tokens,
$tag,
PHP_CodeSniffer_File $phpcsFile
) {
parent::__construct($previousElement, $tokens, $tag, $phpcsFile);
 
}//end __construct()
 
 
/**
* Returns the element names that this tag is comprised of, in the order
* that they appear in the tag.
*
* @return array(string)
* @see processSubElement()
*/
protected function getSubElements()
{
return array('content');
 
}//end getSubElements()
 
 
/**
* Processes the sub element with the specified name.
*
* @param string $name The name of the sub element to process.
* @param string $content The content of this sub element.
* @param string $whitespaceBefore The whitespace that exists before the
* sub element.
*
* @return void
* @see getSubElements()
*/
protected function processSubElement($name, $content, $whitespaceBefore)
{
$this->content = $content;
$this->contentWhitespace = $whitespaceBefore;
 
}//end processSubElement()
 
 
/**
* Returns the content of this tag.
*
* @return string
*/
public function getContent()
{
return $this->content;
 
}//end getContent()
 
 
/**
* Returns the witespace before the content of this tag.
*
* @return string
*/
public function getWhitespaceBeforeContent()
{
return $this->contentWhitespace;
 
}//end getWhitespaceBeforeContent()
 
 
/**
* Processes a content check for single doc element.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $commentStart The line number where
* the error occurs.
* @param string $docBlock Whether this is a file or
* class comment doc.
*
* @return void
*/
public function process(
PHP_CodeSniffer_File $phpcsFile,
$commentStart,
$docBlock
) {
if ($this->content === '') {
$errorPos = ($commentStart + $this->getLine());
$error = "Content missing for $this->tag tag in $docBlock comment";
$phpcsFile->addError($error, $errorPos);
}
 
}//end process()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/CommentParser/CommentElement.php
New file
0,0 → 1,246
<?php
/**
* A class to represent Comments of a doc comment.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: CommentElement.php,v 1.14 2008/12/02 02:38:33 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_CommentParser_SingleElement', true) === false) {
$error = 'Class PHP_CodeSniffer_CommentParser_SingleElement not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* A class to represent Comments of a doc comment.
*
* Comments are in the following format.
* <code>
* /** <--this is the start of the comment.
* * This is a short comment description
* *
* * This is a long comment description
* * <-- this is the end of the comment
* * @return something
* {@/}
* </code>
*
* Note that the sentence before two newlines is assumed
* the short comment description.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_CommentParser_CommentElement extends PHP_CodeSniffer_CommentParser_SingleElement
{
 
 
/**
* Constructs a PHP_CodeSniffer_CommentParser_CommentElement.
*
* @param PHP_CodeSniffer_CommentParser_DocElemement $previousElement The element
* that
* appears
* before this
* element.
* @param array $tokens The tokens
* that make
* up this
* element.
* @param PHP_CodeSniffer_File $phpcsFile The file
* that this
* element is
* in.
*/
public function __construct(
$previousElement,
$tokens,
PHP_CodeSniffer_File $phpcsFile
) {
parent::__construct($previousElement, $tokens, 'comment', $phpcsFile);
 
}//end __construct()
 
 
/**
* Returns the short comment description.
*
* @return string
* @see getLongComment()
*/
public function getShortComment()
{
$pos = $this->_getShortCommentEndPos();
if ($pos === -1) {
return '';
}
 
return implode('', array_slice($this->tokens, 0, ($pos + 1)));
 
}//end getShortComment()
 
 
/**
* Returns the last token position of the short comment description.
*
* @return int The last token position of the short comment description
* @see _getLongCommentStartPos()
*/
private function _getShortCommentEndPos()
{
$found = false;
$whiteSpace = array(
' ',
"\t",
);
 
foreach ($this->tokens as $pos => $token) {
$token = str_replace($whiteSpace, '', $token);
if ($token === $this->phpcsFile->eolChar) {
if ($found === false) {
// Include newlines before short description.
continue;
} else {
if (isset($this->tokens[($pos + 1)]) === true) {
if ($this->tokens[($pos + 1)] === $this->phpcsFile->eolChar) {
return ($pos - 1);
}
} else {
return $pos;
}
}
} else {
$found = true;
}
}//end foreach
 
return (count($this->tokens) - 1);
 
}//end _getShortCommentEndPos()
 
 
/**
* Returns the long comment description.
*
* @return string
* @see getShortComment
*/
public function getLongComment()
{
$start = $this->_getLongCommentStartPos();
if ($start === -1) {
return '';
}
 
return implode('', array_slice($this->tokens, $start));
 
}//end getLongComment()
 
 
/**
* Returns the start position of the long comment description.
*
* Returns -1 if there is no long comment.
*
* @return int The start position of the long comment description.
* @see _getShortCommentEndPos()
*/
private function _getLongCommentStartPos()
{
$pos = ($this->_getShortCommentEndPos() + 1);
if ($pos === (count($this->tokens) - 1)) {
return -1;
}
 
$count = count($this->tokens);
for ($i = $pos; $i < $count; $i++) {
$content = trim($this->tokens[$i]);
if ($content !== '') {
if ($content{0} === '@') {
return -1;
}
 
return $i;
}
}
 
return -1;
 
}//end _getLongCommentStartPos()
 
 
/**
* Returns the whitespace that exists between
* the short and the long comment description.
*
* @return string
*/
public function getWhiteSpaceBetween()
{
$endShort = ($this->_getShortCommentEndPos() + 1);
$startLong = ($this->_getLongCommentStartPos() - 1);
if ($startLong === -1) {
return '';
}
 
return implode(
'',
array_slice($this->tokens, $endShort, ($startLong - $endShort))
);
 
}//end getWhiteSpaceBetween()
 
 
/**
* Returns the number of newlines that exist before the tags.
*
* @return int
*/
public function getNewlineAfter()
{
$long = $this->getLongComment();
if ($long !== '') {
$long = rtrim($long, ' ');
$long = strrev($long);
$newlines = strspn($long, $this->phpcsFile->eolChar);
} else {
$endShort = ($this->_getShortCommentEndPos() + 1);
$after = implode('', array_slice($this->tokens, $endShort));
$after = trim($after, ' ');
$newlines = strspn($after, $this->phpcsFile->eolChar);
}
 
return ($newlines / strlen($this->phpcsFile->eolChar));
 
}//end getNewlineAfter()
 
 
/**
* Returns true if there is no comment.
*
* @return boolean
*/
public function isEmpty()
{
return (trim($this->getContent()) === '');
 
}//end isEmpty()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/CommentParser/DocElement.php
New file
0,0 → 1,105
<?php
/**
* A DocElement represents a logical element within a Doc Comment.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: DocElement.php,v 1.3 2007/01/08 05:07:29 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* A DocElement represents a logical element within a Doc Comment.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
interface PHP_CodeSniffer_CommentParser_DocElement
{
 
 
/**
* Returns the name of the tag this element represents, omitting the @ symbol.
*
* @return string
*/
public function getTag();
 
 
/**
* Returns the whitespace that exists before this element.
*
* @return string
* @see getWhitespaceAfter()
*/
public function getWhitespaceBefore();
 
 
/**
* Returns the whitespace that exists after this element.
*
* @return string
* @see getWhitespaceBefore()
*/
public function getWhitespaceAfter();
 
 
/**
* Returns the order that this element appears in the doc comment.
*
* The first element in the comment should have an order of 1.
*
* @return int
*/
public function getOrder();
 
 
/**
* Returns the element that appears before this element.
*
* @return PHP_CodeSniffer_CommentParser_DocElement
* @see getNextElement()
*/
public function getPreviousElement();
 
 
/**
* Returns the element that appears after this element.
*
* @return PHP_CodeSniffer_CommentParser_DocElement
* @see getPreviousElement()
*/
public function getNextElement();
 
 
/**
* Returns the line that this element started on.
*
* @return int
*/
public function getLine();
 
 
/**
* Returns the raw content of this element, ommiting the tag.
*
* @return string
*/
public function getRawContent();
 
 
}//end interface
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/CommentParser/AbstractParser.php
New file
0,0 → 1,654
<?php
/**
* Parses doc comments.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: AbstractParser.php,v 1.22 2008/12/04 00:35:14 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (class_exists('PHP_CodeSniffer_CommentParser_SingleElement', true) === false) {
$error = 'Class PHP_CodeSniffer_CommentParser_SingleElement not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
if (class_exists('PHP_CodeSniffer_CommentParser_CommentElement', true) === false) {
$error = 'Class PHP_CodeSniffer_CommentParser_CommentElement not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
if (class_exists('PHP_CodeSniffer_CommentParser_ParserException', true) === false) {
$error = 'Class PHP_CodeSniffer_CommentParser_ParserException not found';
throw new PHP_CodeSniffer_Exception($error);
}
 
/**
* Parses doc comments.
*
* This abstract parser handles the following tags:
*
* <ul>
* <li>The short description and the long description</li>
* <li>@see</li>
* <li>@link</li>
* <li>@deprecated</li>
* <li>@since</li>
* </ul>
*
* Extending classes should implement the getAllowedTags() method to return the
* tags that they wish to process, ommiting the tags that this base class
* processes. When one of these tags in encountered, the process&lt;tag_name&gt;
* method is called on that class. For example, if a parser's getAllowedTags()
* method returns \@param as one of its tags, the processParam method will be
* called so that the parser can process such a tag.
*
* The method is passed the tokens that comprise this tag. The tokens array
* includes the whitespace that exists between the tokens, as seperate tokens.
* It's up to the method to create a element that implements the DocElement
* interface, which should be returned. The AbstractDocElement class is a helper
* class that can be used to handle most of the parsing of the tokens into their
* individual sub elements. It requires that you construct it with the element
* previous to the element currently being processed, which can be acquired
* with the protected $previousElement class member of this class.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
abstract class PHP_CodeSniffer_CommentParser_AbstractParser
{
 
/**
* The comment element that appears in the doc comment.
*
* @var PHP_CodeSniffer_CommentParser_CommentElement
*/
protected $comment = null;
 
/**
* The string content of the comment.
*
* @var string
*/
protected $commentString = '';
 
/**
* The file that the comment exists in.
*
* @var PHP_CodeSniffer_File
*/
protected $phpcsFile = null;
 
/**
* The word tokens that appear in the comment.
*
* Whitespace tokens also appear in this stack, but are separate tokens
* from words.
*
* @var array(string)
*/
protected $words = array();
 
/**
* The previous doc element that was processed.
*
* null if the current element being processed is the first element in the
* doc comment.
*
* @var PHP_CodeSniffer_CommentParser_DocElement
*/
protected $previousElement = null;
 
/**
* A list of see elements that appear in this doc comment.
*
* @var array(PHP_CodeSniffer_CommentParser_SingleElement)
*/
protected $sees = array();
 
/**
* A list of see elements that appear in this doc comment.
*
* @var array(PHP_CodeSniffer_CommentParser_SingleElement)
*/
protected $deprecated = null;
 
/**
* A list of see elements that appear in this doc comment.
*
* @var array(PHP_CodeSniffer_CommentParser_SingleElement)
*/
protected $links = array();
 
/**
* A element to represent \@since tags.
*
* @var PHP_CodeSniffer_CommentParser_SingleElement
*/
protected $since = null;
 
/**
* True if the comment has been parsed.
*
* @var boolean
*/
private $_hasParsed = false;
 
/**
* The tags that this class can process.
*
* @var array(string)
*/
private static $_tags = array(
'see' => false,
'link' => false,
'deprecated' => true,
'since' => true,
);
 
/**
* An array of unknown tags.
*
* @var array(string)
*/
public $unknown = array();
 
/**
* The order of tags.
*
* @var array(string)
*/
public $orders = array();
 
 
/**
* Constructs a Doc Comment Parser.
*
* @param string $comment The comment to parse.
* @param PHP_CodeSniffer_File $phpcsFile The file that this comment is in.
*/
public function __construct($comment, PHP_CodeSniffer_File $phpcsFile)
{
$this->commentString = $comment;
$this->phpcsFile = $phpcsFile;
 
}//end __construct()
 
 
/**
* Initiates the parsing of the doc comment.
*
* @return void
* @throws PHP_CodeSniffer_CommentParser_ParserException If the parser finds a
* problem with the
* comment.
*/
public function parse()
{
if ($this->_hasParsed === false) {
$this->_parse($this->commentString);
}
 
}//end parse()
 
 
/**
* Parse the comment.
*
* @param string $comment The doc comment to parse.
*
* @return void
* @see _parseWords()
*/
private function _parse($comment)
{
// Firstly, remove the comment tags and any stars from the left side.
$lines = explode($this->phpcsFile->eolChar, $comment);
foreach ($lines as &$line) {
$line = trim($line);
 
if ($line !== '') {
if (substr($line, 0, 3) === '/**') {
$line = substr($line, 3);
} else if (substr($line, -2, 2) === '*/') {
$line = substr($line, 0, -2);
} else if ($line{0} === '*') {
$line = substr($line, 1);
}
 
// Add the words to the stack, preserving newlines. Other parsers
// might be interested in the spaces between words, so tokenize
// spaces as well as separate tokens.
$flags = (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$words = preg_split(
'|(\s+)|',
$line.$this->phpcsFile->eolChar,
-1,
$flags
);
 
$this->words = array_merge($this->words, $words);
}
}//end foreach
 
$this->_parseWords();
 
}//end _parse()
 
 
/**
* Parses each word within the doc comment.
*
* @return void
* @see _parse()
* @throws PHP_CodeSniffer_CommentParser_ParserException If more than the allowed
* number of occurances of
* a tag is found.
*/
private function _parseWords()
{
$allowedTags = (self::$_tags + $this->getAllowedTags());
$allowedTagNames = array_keys($allowedTags);
$foundTags = array();
$prevTagPos = false;
$wordWasEmpty = true;
 
foreach ($this->words as $wordPos => $word) {
 
if (trim($word) !== '') {
$wordWasEmpty = false;
}
 
if ($word{0} === '@') {
 
$tag = substr($word, 1);
 
// Filter out @ tags in the comment description.
// A real comment tag should have whitespace and a newline before it.
if (isset($this->words[($wordPos - 1)]) === false
|| trim($this->words[($wordPos - 1)]) !== ''
) {
continue;
}
 
if (isset($this->words[($wordPos - 2)]) === false
|| $this->words[($wordPos - 2)] !== $this->phpcsFile->eolChar
) {
continue;
}
 
$foundTags[] = $tag;
 
if ($prevTagPos !== false) {
// There was a tag before this so let's process it.
$prevTag = substr($this->words[$prevTagPos], 1);
$this->parseTag($prevTag, $prevTagPos, ($wordPos - 1));
} else {
// There must have been a comment before this tag, so
// let's process that.
$this->parseTag('comment', 0, ($wordPos - 1));
}
 
$prevTagPos = $wordPos;
 
if (in_array($tag, $allowedTagNames) === false) {
// This is not a tag that we process, but let's check to
// see if it is a tag we know about. If we don't know about it,
// we add it to a list of unknown tags.
$knownTags = array(
'abstract',
'access',
'example',
'filesource',
'global',
'ignore',
'internal',
'name',
'static',
'staticvar',
'todo',
'tutorial',
'uses',
'package_version@',
);
 
if (in_array($tag, $knownTags) === false) {
$this->unknown[] = array(
'tag' => $tag,
'line' => $this->getLine($wordPos),
);
}
 
}//end if
 
}//end if
}//end foreach
 
// Only process this tag if there was something to process.
if ($wordWasEmpty === false) {
if ($prevTagPos === false) {
// There must only be a comment in this doc comment.
$this->parseTag('comment', 0, count($this->words));
} else {
// Process the last tag element.
$prevTag = substr($this->words[$prevTagPos], 1);
$numWords = count($this->words);
$endPos = $numWords;
 
if ($prevTag === 'package' || $prevTag === 'subpaackage') {
// These are single-word tags, so anything after a newline
// is really a comment.
for ($endPos = $prevTagPos; $endPos < $numWords; $endPos++) {
if (strpos($this->words[$endPos], $this->phpcsFile->eolChar) !== false) {
break;
}
}
}
 
$this->parseTag($prevTag, $prevTagPos, $endPos);
 
if ($endPos !== $numWords) {
// Process the final comment, if it is not empty.
$tokens = array_slice($this->words, ($endPos + 1), $numWords);
$content = implode('', $tokens);
if (trim($content) !== '') {
$this->parseTag('comment', ($endPos + 1), $numWords);
}
}
}//end if
}//end if
 
}//end _parseWords()
 
 
/**
* Returns the line that the token exists on in the doc comment.
*
* @param int $tokenPos The position in the words stack to find the line
* number for.
*
* @return int
*/
protected function getLine($tokenPos)
{
$newlines = 0;
for ($i = 0; $i < $tokenPos; $i++) {
$newlines += substr_count($this->phpcsFile->eolChar, $this->words[$i]);
}
 
return $newlines;
 
}//end getLine()
 
 
/**
* Parses see tag element within the doc comment.
*
* @param array(string) $tokens The word tokens that comprise this element.
*
* @return DocElement The element that represents this see comment.
*/
protected function parseSee($tokens)
{
$see = new PHP_CodeSniffer_CommentParser_SingleElement(
$this->previousElement,
$tokens,
'see',
$this->phpcsFile
);
 
$this->sees[] = $see;
return $see;
 
}//end parseSee()
 
 
/**
* Parses the comment element that appears at the top of the doc comment.
*
* @param array(string) $tokens The word tokens that comprise tihs element.
*
* @return DocElement The element that represents this comment element.
*/
protected function parseComment($tokens)
{
$this->comment = new PHP_CodeSniffer_CommentParser_CommentElement(
$this->previousElement,
$tokens,
$this->phpcsFile
);
 
return $this->comment;
 
}//end parseComment()
 
 
/**
* Parses \@deprecated tags.
*
* @param array(string) $tokens The word tokens that comprise tihs element.
*
* @return DocElement The element that represents this deprecated tag.
*/
protected function parseDeprecated($tokens)
{
$this->deprecated = new PHP_CodeSniffer_CommentParser_SingleElement(
$this->previousElement,
$tokens,
'deprecated',
$this->phpcsFile
);
 
return $this->deprecated;
 
}//end parseDeprecated()
 
 
/**
* Parses \@since tags.
*
* @param array(string) $tokens The word tokens that comprise this element.
*
* @return SingleElement The element that represents this since tag.
*/
protected function parseSince($tokens)
{
$this->since = new PHP_CodeSniffer_CommentParser_SingleElement(
$this->previousElement,
$tokens,
'since',
$this->phpcsFile
);
 
return $this->since;
 
}//end parseSince()
 
 
/**
* Parses \@link tags.
*
* @param array(string) $tokens The word tokens that comprise this element.
*
* @return SingleElement The element that represents this link tag.
*/
protected function parseLink($tokens)
{
$link = new PHP_CodeSniffer_CommentParser_SingleElement(
$this->previousElement,
$tokens,
'link',
$this->phpcsFile
);
 
$this->links[] = $link;
return $link;
 
}//end parseLink()
 
 
/**
* Returns the see elements that appear in this doc comment.
*
* @return array(SingleElement)
*/
public function getSees()
{
return $this->sees;
 
}//end getSees()
 
 
/**
* Returns the comment element that appears at the top of this doc comment.
*
* @return CommentElement
*/
public function getComment()
{
return $this->comment;
 
}//end getComment()
 
 
/**
* Returns the link elements found in this comment.
*
* Returns an empty array if no links are found in the comment.
*
* @return array(SingleElement)
*/
public function getLinks()
{
return $this->links;
 
}//end getLinks()
 
 
/**
* Returns the deprecated element found in this comment.
*
* Returns null if no element exists in the comment.
*
* @return SingleElement
*/
public function getDeprecated()
{
return $this->deprecated;
 
}//end getDeprecated()
 
 
/**
* Returns the since element found in this comment.
*
* Returns null if no element exists in the comment.
*
* @return SingleElement
*/
public function getSince()
{
return $this->since;
 
}//end getSince()
 
 
/**
* Parses the specified tag.
*
* @param string $tag The tag name to parse (omitting the @ sybmol from
* the tag)
* @param int $start The position in the word tokens where this element
* started.
* @param int $end The position in the word tokens where this element
* ended.
*
* @return void
* @throws Exception If the process method for the tag cannot be found.
*/
protected function parseTag($tag, $start, $end)
{
$tokens = array_slice($this->words, ($start + 1), ($end - $start));
 
$allowedTags = (self::$_tags + $this->getAllowedTags());
$allowedTagNames = array_keys($allowedTags);
if ($tag === 'comment' || in_array($tag, $allowedTagNames) === true) {
$method = 'parse'.$tag;
if (method_exists($this, $method) === false) {
$error = 'Method '.$method.' must be implemented to process '.$tag.' tags';
throw new Exception($error);
}
 
$this->previousElement = $this->$method($tokens);
} else {
$this->previousElement = new PHP_CodeSniffer_CommentParser_SingleElement(
$this->previousElement,
$tokens,
$tag,
$this->phpcsFile
);
}
 
$this->orders[] = $tag;
 
if ($this->previousElement === null
|| ($this->previousElement instanceof PHP_CodeSniffer_CommentParser_DocElement) === false
) {
throw new Exception('Parse method must return a DocElement');
}
 
}//end parseTag()
 
 
/**
* Returns a list of tags that this comment parser allows for it's comment.
*
* Each tag should indicate if only one entry of this tag can exist in the
* comment by specifying true as the array value, or false if more than one
* is allowed. Each tag should ommit the @ symbol. Only tags other than
* the standard tags should be returned.
*
* @return array(string => boolean)
*/
protected abstract function getAllowedTags();
 
 
/**
* Returns the tag orders (index => tagName).
*
* @return array
*/
public function getTagOrders()
{
return $this->orders;
 
}//end getTagOrders()
 
 
/**
* Returns the unknown tags.
*
* @return array
*/
public function getUnknown()
{
return $this->unknown;
 
}//end getUnknown()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/DocGenerators/HTML.php
New file
0,0 → 1,291
<?php
/**
* A doc generator that outputs documentation in one big HTML file.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: HTML.php,v 1.5 2008/12/07 21:40:02 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
require_once 'PHP/CodeSniffer/DocGenerators/Generator.php';
 
/**
* A doc generator that outputs documentation in one big HTML file.
*
* Output is in one large HTML file and is designed for you to style with
* your own stylesheet. It contains a table of contents at the top with anchors
* to each sniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_DocGenerators_HTML extends PHP_CodeSniffer_DocGenerators_Generator
{
 
 
/**
* Generates the documentation for a standard.
*
* @return void
* @see processSniff()
*/
public function generate()
{
ob_start();
$this->printHeader();
 
$standardFiles = $this->getStandardFiles();
$this->printToc($standardFiles);
 
foreach ($standardFiles as $standard) {
$doc = new DOMDocument();
$doc->load($standard);
$documentation = $doc->getElementsByTagName('documentation')->item(0);
$this->processSniff($documentation);
}
 
$this->printFooter();
 
$content = ob_get_contents();
ob_end_clean();
 
echo $content;
 
}//end generate()
 
 
/**
* Print the header of the HTML page.
*
* @return void
*/
protected function printHeader()
{
$standard = $this->getStandard();
echo '<html>'.PHP_EOL;
echo ' <head>'.PHP_EOL;
echo " <title>$standard Coding Standards</title>".PHP_EOL;
echo ' <style>
body {
background-color: #FFFFFF;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
color: #000000;
}
 
h1 {
color: #666666;
font-size: 20px;
font-weight: bold;
margin-top: 0px;
background-color: #E6E7E8;
padding: 20px;
border: 1px solid #BBBBBB;
}
 
h2 {
color: #00A5E3;
font-size: 16px;
font-weight: normal;
margin-top: 50px;
}
 
.code-comparison {
width: 100%;
}
 
.code-comparison td {
border: 1px solid #CCCCCC;
}
 
.code-comparison-title, .code-comparison-code {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #000000;
vertical-align: top;
padding: 4px;
width: 50%;
background-color: #F1F1F1;
line-height: 15px;
}
 
.code-comparison-code {
font-family: Courier;
background-color: #F9F9F9;
}
 
.code-comparison-highlight {
background-color: #DDF1F7;
border: 1px solid #00A5E3;
line-height: 15px;
}
 
.tag-line {
text-align: center;
width: 100%;
margin-top: 30px;
font-size: 12px;
}
 
.tag-line a {
color: #000000;
}
</style>'.PHP_EOL;
echo ' </head>'.PHP_EOL;
echo ' <body>'.PHP_EOL;
echo " <h1>$standard Coding Standards</h1>".PHP_EOL;
 
}//end printHeader()
 
 
/**
* Print the table of contents for the standard.
*
* The TOC is just an unordered list of bookmarks to sniffs on the page.
*
* @param array $standardFiles An array of paths to the XML standard files.
*
* @return void
*/
protected function printToc($standardFiles)
{
echo ' <h2>Table of Contents</h2>'.PHP_EOL;
echo ' <ul class="toc">'.PHP_EOL;
 
foreach ($standardFiles as $standard) {
$doc = new DOMDocument();
$doc->load($standard);
$documentation = $doc->getElementsByTagName('documentation')->item(0);
$title = $this->getTitle($documentation);
echo ' <li><a href="#'.str_replace(' ', '-', $title)."\">$title</a></li>".PHP_EOL;
}
 
echo ' </ul>'.PHP_EOL;
 
}//end printToc()
 
 
/**
* Print the footer of the HTML page.
*
* @return void
*/
protected function printFooter()
{
// Turn off strict errors so we don't get timezone warnings if people
// don't have their timezone set.
error_reporting(E_ALL);
echo ' <div class="tag-line">';
echo 'Documentation generated on '.date('r');
echo ' by <a href="http://pear.php.net/package/PHP_CodeSniffer">PHP_CodeSniffer 1.2.0RC1</a>';
echo '</div>'.PHP_EOL;
error_reporting(E_ALL | E_STRICT);
 
echo ' </body>'.PHP_EOL;
echo '</html>'.PHP_EOL;
 
}//end printFooter()
 
 
/**
* Process the documentation for a single sniff.
*
* @param DOMNode $doc The DOMNode object for the sniff.
* It represents the "documentation" tag in the XML
* standard file.
*
* @return void
*/
public function processSniff(DOMNode $doc)
{
$title = $this->getTitle($doc);
echo ' <a name="'.str_replace(' ', '-', $title).'" />'.PHP_EOL;
echo " <h2>$title</h2>".PHP_EOL;
 
foreach ($doc->childNodes as $node) {
if ($node->nodeName === 'standard') {
$this->printTextBlock($node);
} else if ($node->nodeName === 'code_comparison') {
$this->printCodeComparisonBlock($node);
}
}
 
}//end processSniff()
 
 
/**
* Print a text block found in a standard.
*
* @param DOMNode $node The DOMNode object for the text block.
*
* @return void
*/
protected function printTextBlock($node)
{
$content = trim($node->nodeValue);
$content = htmlspecialchars($content);
 
// Allow em tags only.
$content = str_replace('&lt;em&gt;', '<em>', $content);
$content = str_replace('&lt;/em&gt;', '</em>', $content);
 
echo " <p class=\"text\">$content</p>".PHP_EOL;
 
}//end printTextBlock()
 
 
/**
* Print a code comparison block found in a standard.
*
* @param DOMNode $node The DOMNode object for the code comparison block.
*
* @return void
*/
protected function printCodeComparisonBlock($node)
{
$codeBlocks = $node->getElementsByTagName('code');
 
$firstTitle = $codeBlocks->item(0)->getAttribute('title');
$first = trim($codeBlocks->item(0)->nodeValue);
$first = str_replace("\n", '</br>', $first);
$first = str_replace(' ', '&nbsp;', $first);
$first = str_replace('<em>', '<span class="code-comparison-highlight">', $first);
$first = str_replace('</em>', '</span>', $first);
 
$secondTitle = $codeBlocks->item(1)->getAttribute('title');
$second = trim($codeBlocks->item(1)->nodeValue);
$second = str_replace("\n", '</br>', $second);
$second = str_replace(' ', '&nbsp;', $second);
$second = str_replace('<em>', '<span class="code-comparison-highlight">', $second);
$second = str_replace('</em>', '</span>', $second);
 
echo ' <table class="code-comparison">'.PHP_EOL;
echo ' <tr>'.PHP_EOL;
echo " <td class=\"code-comparison-title\">$firstTitle</td>".PHP_EOL;
echo " <td class=\"code-comparison-title\">$secondTitle</td>".PHP_EOL;
echo ' </tr>'.PHP_EOL;
echo ' <tr>'.PHP_EOL;
echo " <td class=\"code-comparison-code\">$first</td>".PHP_EOL;
echo " <td class=\"code-comparison-code\">$second</td>".PHP_EOL;
echo ' </tr>'.PHP_EOL;
echo ' </table>'.PHP_EOL;
 
}//end printCodeComparisonBlock()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/DocGenerators/Text.php
New file
0,0 → 1,266
<?php
/**
* A doc generator that outputs text-based documentation.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: Text.php,v 1.3 2007/05/22 06:43:05 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
require_once 'PHP/CodeSniffer/DocGenerators/Generator.php';
 
/**
* A doc generator that outputs text-based documentation.
*
* Output is designed to be displayed in a terminal and is wrapped to 100 characters.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_DocGenerators_Text extends PHP_CodeSniffer_DocGenerators_Generator
{
 
 
/**
* Process the documentation for a single sniff.
*
* @param DOMNode $doc The DOMNode object for the sniff.
* It represents the "documentation" tag in the XML
* standard file.
*
* @return void
*/
public function processSniff(DOMNode $doc)
{
$this->printTitle($doc);
 
foreach ($doc->childNodes as $node) {
if ($node->nodeName === 'standard') {
$this->printTextBlock($node);
} else if ($node->nodeName === 'code_comparison') {
$this->printCodeComparisonBlock($node);
}
}
 
}//end processSniff()
 
 
/**
* Prints the title area for a single sniff.
*
* @param DOMNode $doc The DOMNode object for the sniff.
* It represents the "documentation" tag in the XML
* standard file.
*
* @return void
*/
protected function printTitle(DOMNode $doc)
{
$title = $this->getTitle($doc);
$standard = $this->getStandard();
 
echo PHP_EOL;
echo str_repeat('-', (strlen("$standard CODING STANDARD: $title") + 4));
echo strtoupper(PHP_EOL."| $standard CODING STANDARD: $title |".PHP_EOL);
echo str_repeat('-', (strlen("$standard CODING STANDARD: $title") + 4));
echo PHP_EOL.PHP_EOL;
 
}//end printTitle()
 
 
/**
* Print a text block found in a standard.
*
* @param DOMNode $node The DOMNode object for the text block.
*
* @return void
*/
protected function printTextBlock($node)
{
$text = trim($node->nodeValue);
$text = str_replace('<em>', '*', $text);
$text = str_replace('</em>', '*', $text);
 
$lines = array();
$tempLine = '';
$words = explode(' ', $text);
 
foreach ($words as $word) {
if (strlen($tempLine.$word) >= 99) {
if (strlen($tempLine.$word) === 99) {
// Adding the extra space will push us to the edge
// so we are done.
$lines[] = $tempLine.$word;
$tempLine = '';
} else if (strlen($tempLine.$word) === 100) {
// We are already at the edge, so we are done.
$lines[] = $tempLine.$word;
$tempLine = '';
} else {
$lines[] = rtrim($tempLine);
$tempLine = $word.' ';
}
} else {
$tempLine .= $word.' ';
}
}//end foreach
 
if ($tempLine !== '') {
$lines[] = rtrim($tempLine);
}
 
echo implode(PHP_EOL, $lines).PHP_EOL.PHP_EOL;
 
}//end printTextBlock()
 
 
/**
* Print a code comparison block found in a standard.
*
* @param DOMNode $node The DOMNode object for the code comparison block.
*
* @return void
*/
protected function printCodeComparisonBlock($node)
{
$codeBlocks = $node->getElementsByTagName('code');
$first = trim($codeBlocks->item(0)->nodeValue);
$firstTitle = $codeBlocks->item(0)->getAttribute('title');
 
$firstTitleLines = array();
$tempTitle = '';
$words = explode(' ', $firstTitle);
 
foreach ($words as $word) {
if (strlen($tempTitle.$word) >= 45) {
if (strlen($tempTitle.$word) === 45) {
// Adding the extra space will push us to the edge
// so we are done.
$firstTitleLines[] = $tempTitle.$word;
$tempTitle = '';
} else if (strlen($tempTitle.$word) === 46) {
// We are already at the edge, so we are done.
$firstTitleLines[] = $tempTitle.$word;
$tempTitle = '';
} else {
$firstTitleLines[] = $tempTitle;
$tempTitle = $word;
}
} else {
$tempTitle .= $word.' ';
}
}//end foreach
 
if ($tempTitle !== '') {
$firstTitleLines[] = $tempTitle;
}
 
$first = str_replace('<em>', '', $first);
$first = str_replace('</em>', '', $first);
$firstLines = explode("\n", $first);
 
$second = trim($codeBlocks->item(1)->nodeValue);
$secondTitle = $codeBlocks->item(1)->getAttribute('title');
 
$secondTitleLines = array();
$tempTitle = '';
$words = explode(' ', $secondTitle);
 
foreach ($words as $word) {
if (strlen($tempTitle.$word) >= 45) {
if (strlen($tempTitle.$word) === 45) {
// Adding the extra space will push us to the edge
// so we are done.
$secondTitleLines[] = $tempTitle.$word;
$tempTitle = '';
} else if (strlen($tempTitle.$word) === 46) {
// We are already at the edge, so we are done.
$secondTitleLines[] = $tempTitle.$word;
$tempTitle = '';
} else {
$secondTitleLines[] = $tempTitle;
$tempTitle = $word;
}
} else {
$tempTitle .= $word.' ';
}
}//end foreach
 
if ($tempTitle !== '') {
$secondTitleLines[] = $tempTitle;
}
 
$second = str_replace('<em>', '', $second);
$second = str_replace('</em>', '', $second);
$secondLines = explode("\n", $second);
 
$maxCodeLines = max(count($firstLines), count($secondLines));
$maxTitleLines = max(count($firstTitleLines), count($secondTitleLines));
 
echo str_repeat('-', 41);
echo ' CODE COMPARISON ';
echo str_repeat('-', 42).PHP_EOL;
 
for ($i = 0; $i < $maxTitleLines; $i++) {
if (isset($firstTitleLines[$i]) === true) {
$firstLineText = $firstTitleLines[$i];
} else {
$firstLineText = '';
}
 
if (isset($secondTitleLines[$i]) === true) {
$secondLineText = $secondTitleLines[$i];
} else {
$secondLineText = '';
}
 
echo '| ';
echo $firstLineText.str_repeat(' ', (46 - strlen($firstLineText)));
echo ' | ';
echo $secondLineText.str_repeat(' ', (47 - strlen($secondLineText)));
echo ' |'.PHP_EOL;
}//end for
 
echo str_repeat('-', 100).PHP_EOL;
 
for ($i = 0; $i < $maxCodeLines; $i++) {
if (isset($firstLines[$i]) === true) {
$firstLineText = $firstLines[$i];
} else {
$firstLineText = '';
}
 
if (isset($secondLines[$i]) === true) {
$secondLineText = $secondLines[$i];
} else {
$secondLineText = '';
}
 
echo '| ';
echo $firstLineText.str_repeat(' ', (47 - strlen($firstLineText)));
echo '| ';
echo $secondLineText.str_repeat(' ', (48 - strlen($secondLineText)));
echo '|'.PHP_EOL;
}//end for
 
echo str_repeat('-', 100).PHP_EOL.PHP_EOL;
 
}//end printCodeComparisonBlock()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer/DocGenerators/Generator.php
New file
0,0 → 1,196
<?php
/**
* The base class for all PHP_CodeSniffer documentation generators.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: Generator.php,v 1.4 2008/12/02 02:38:34 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
/**
* The base class for all PHP_CodeSniffer documentation generators.
*
* Documentation generators are used to print documentation about code sniffs
* in a standard.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: 1.2.0RC1
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_DocGenerators_Generator
{
 
/**
* The name of the coding standard we are generating docs for.
*
* @var string
*/
private $_standard = '';
 
/**
* An array of sniffs that we are limiting the generated docs to.
*
* If this array is empty, docs are generated for all sniffs in the
* supplied coding standard.
*
* @var string
*/
private $_sniffs = array();
 
 
/**
* Constructs a PHP_CodeSniffer_DocGenerators_Generator object.
*
* @param string $standard The name of the coding standard to generate
* docs for.
* @param array $sniffs An array of sniffs that we are limiting the
* generated docs to.
*
* @see generate()
*/
public function __construct($standard, array $sniffs=array())
{
$this->_standard = $standard;
$this->_sniffs = $sniffs;
 
}//end __construct()
 
 
/**
* Retrieves the title of the sniff from the DOMNode supplied.
*
* @param DOMNode $doc The DOMNode object for the sniff.
* It represents the "documentation" tag in the XML
* standard file.
*
* @return string
*/
protected function getTitle(DOMNode $doc)
{
return $doc->getAttribute('title');
 
}//end getTitle()
 
 
/**
* Retrieves the name of the standard we are generating docs for.
*
* @return string
*/
protected function getStandard()
{
return $this->_standard;
 
}//end getStandard()
 
 
/**
* Generates the documentation for a standard.
*
* It's probably wise for doc generators to override this method so they
* have control over how the docs are produced. Otherwise, the processSniff
* method should be overridden to output content for each sniff.
*
* @return void
* @see processSniff()
*/
public function generate()
{
$standardFiles = $this->getStandardFiles();
 
foreach ($standardFiles as $standard) {
$doc = new DOMDocument();
$doc->load($standard);
$documentation = $doc->getElementsByTagName('documentation')->item(0);
$this->processSniff($documentation);
}
 
}//end generate()
 
 
/**
* Returns a list of paths to XML standard files for all sniffs in a standard.
*
* Any sniffs that do not have an XML standard file are obviously not included
* in the returned array. If documentation is only being generated for some
* sniffs (ie. $this->_sniffs is not empty) then all others sniffs will
* be filtered from the results as well.
*
* @return array(string)
*/
protected function getStandardFiles()
{
if (is_dir($this->_standard) === true) {
// This is a custom standard.
$standardDir = $this->_standard;
$standard = basename($this->_standard);
} else {
$standardDir
= realpath(dirname(__FILE__).'/../Standards/'.$this->_standard);
$standard = $this->_standard;
}
 
$sniffs = PHP_CodeSniffer::getSniffFiles($standardDir, $standard);
 
$standardFiles = array();
foreach ($sniffs as $sniff) {
if (empty($this->_sniffs) === false) {
// We are limiting the docs to certain sniffs only, so filter
// out any unwanted sniffs.
$sniffName = substr($sniff, (strrpos($sniff, '/') + 1));
$sniffName = substr($sniffName, 0, -9);
if (in_array($sniffName, $this->_sniffs) === false) {
continue;
}
}
 
$standardFile= str_replace(
DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR.'Docs'.DIRECTORY_SEPARATOR,
$sniff
);
$standardFile = str_replace('Sniff.php', 'Standard.xml', $standardFile);
 
if (is_file($standardFile) === true) {
$standardFiles[] = $standardFile;
}
}
 
return $standardFiles;
 
}//end getStandardFiles()
 
 
/**
* Process the documentation for a single sniff.
*
* Doc generators should override this function to produce output.
*
* @param DOMNode $doc The DOMNode object for the sniff.
* It represents the "documentation" tag in the XML
* standard file.
*
* @return void
* @see generate()
*/
protected function processSniff(DOMNode $doc)
{
 
}//end processSniff()
 
 
}//end class
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/scripts/phpcs.bat
New file
0,0 → 1,16
@echo off
REM PHP_CodeSniffer tokenises PHP code and detects violations of a
REM defined set of coding standards.
REM
REM PHP version 5
REM
REM @category PHP
REM @package PHP_CodeSniffer
REM @author Greg Sherwood <gsherwood@squiz.net>
REM @author Marc McIntyre <mmcintyre@squiz.net>
REM @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
REM @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
REM @version CVS: $Id: phpcs.bat,v 1.3 2007/11/04 22:02:16 squiz Exp $
REM @link http://pear.php.net/package/PHP_CodeSniffer
 
"@php_bin@" -d auto_append_file="" -d auto_prepend_file="" -d include_path="@php_dir@" "@bin_dir@\phpcs" %*
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/scripts/phpcs-svn-pre-commit
New file
0,0 → 1,195
#!@php_bin@
<?php
/**
* A commit hook for SVN.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Jack Bates <ms419@freezone.co.uk>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: phpcs-svn-pre-commit,v 1.5 2009/01/14 02:44:18 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
if (is_file(dirname(__FILE__).'/../CodeSniffer/CLI.php') === true) {
include_once dirname(__FILE__).'/../CodeSniffer/CLI.php';
} else {
include_once 'PHP/CodeSniffer/CLI.php';
}
 
define('PHP_CODESNIFFER_SVNLOOK', '/usr/bin/svnlook');
 
 
/**
* A class to process command line options.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Jack Bates <ms419@freezone.co.uk>
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: @package_version@
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_SVN_Hook extends PHP_CodeSniffer_CLI
{
 
 
/**
* Get a list of default values for all possible command line arguments.
*
* @return array
*/
public function getDefaults()
{
$defaults = parent::getDefaults();
 
$defaults['svnArgs'] = array();
return $defaults;
 
}//end getDefaults()
 
 
/**
* Processes an unknown command line argument.
*
* All unkown args are sent to SVN commands.
*
* @param string $arg The command line argument.
* @param int $pos The position of the argument on the command line.
* @param array $values An array of values determined from CLI args.
*
* @return array The updated CLI values.
* @see getCommandLineValues()
*/
public function processUnknownArgument($arg, $pos, $values)
{
$values['svnArgs'][] = $arg;
return $values;
 
}//end processUnknownArgument()
 
 
/**
* Runs PHP_CodeSniffer over files are directories.
*
* @param array $values An array of values determined from CLI args.
*
* @return int The number of error and warning messages shown.
* @see getCommandLineValues()
*/
public function process($values=array())
{
if (empty($values) === true) {
$values = parent::getCommandLineValues();
}
 
// Get list of files in this transaction.
$command = PHP_CODESNIFFER_SVNLOOK.' changed '.implode(' ', $values['svnArgs']);
$handle = popen($command, 'r');
if ($handle === false) {
echo 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL;
exit(2);
}
 
$contents = stream_get_contents($handle);
fclose($handle);
 
// Do not check deleted paths.
$contents = preg_replace('/^D.*/m', null, $contents);
 
// Drop the four characters representing the action which precede the path on
// each line.
$contents = preg_replace('/^.{4}/m', null, $contents);
 
$values['standard'] = $this->validateStandard($values['standard']);
if (PHP_CodeSniffer::isInstalledStandard($values['standard']) === false) {
// They didn't select a valid coding standard, so help them
// out by letting them know which standards are installed.
echo 'ERROR: the "'.$values['standard'].'" coding standard is not installed. ';
$this->printInstalledStandards();
exit(2);
}
 
$phpcs = new PHP_CodeSniffer($values['verbosity'], $values['tabWidth']);
 
// Set file extensions if they were specified. Otherwise,
// let PHP_CodeSniffer decide on the defaults.
if (empty($values['extensions']) === false) {
$phpcs->setAllowedFileExtensions($values['extensions']);
}
 
// Set ignore patterns if they were specified.
if (empty($values['ignored']) === false) {
$phpcs->setIgnorePatterns($values['ignored']);
}
 
$phpcs->setTokenListeners($values['standard']);
 
foreach (preg_split('/\v/', $contents, -1, PREG_SPLIT_NO_EMPTY) as $path) {
// No need to process folders as each changed file is checked.
if (substr($path, -1) === '/') {
continue;
}
 
// Get the contents of each file, as it would be after this transaction.
$command = PHP_CODESNIFFER_SVNLOOK.' cat '.implode(' ', $values['svnArgs']).' '.$path;
$handle = popen($command, 'r');
if ($handle === false) {
echo 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL;
exit(2);
}
 
$contents = stream_get_contents($handle);
fclose($handle);
 
$phpcs->processFile($path, $contents);
}//end foreach
 
return parent::printErrorReport(
$phpcs,
$values['report'],
$values['showWarnings'],
$values['showSources'],
$values['reportFile']
);
 
}//end process()
 
 
/**
* Prints out the usage information for this script.
*
* @return void
*/
public function printUsage()
{
parent::printUsage();
 
echo PHP_EOL;
echo ' Each additional argument is passed to the `svnlook changed ...`'.PHP_EOL;
echo ' and `svnlook cat ...` commands. The report is printed on standard output,'.PHP_EOL;
echo ' however Subversion displays only standard error to the user, so in a'.PHP_EOL;
echo ' pre-commit hook, this script should be invoked as follows:'.PHP_EOL;
echo PHP_EOL;
echo ' '.basename($_SERVER['argv'][0]).' ... "$REPOS" -t "$TXN" >&2 || exit 1'.PHP_EOL;
 
}//end printUsage()
 
 
}//end class
 
$phpcs = new PHP_CodeSniffer_SVN_Hook();
$phpcs->checkRequirements();
 
$numErrors = $phpcs->process();
if ($numErrors !== 0) {
exit(1);
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/scripts/phpcs
New file
0,0 → 1,37
#!@php_bin@
<?php
/**
* PHP_CodeSniffer tokenises PHP code and detects violations of a
* defined set of coding standards.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: phpcs,v 1.40 2008/03/10 02:39:04 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
error_reporting(E_ALL | E_STRICT);
 
if (is_file(dirname(__FILE__).'/../CodeSniffer/CLI.php') === true) {
include_once dirname(__FILE__).'/../CodeSniffer/CLI.php';
} else {
include_once 'PHP/CodeSniffer/CLI.php';
}
 
$phpcs = new PHP_CodeSniffer_CLI();
$phpcs->checkRequirements();
 
$numErrors = $phpcs->process();
if ($numErrors === 0) {
exit(0);
} else {
exit(1);
}
 
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer.sample.conf
New file
0,0 → 1,6
<?php
$phpCodeSnifferConfig = array (
'zend_ca_path' => '/path/to/ZendStudio/bin/ZendCodeAnalyzer',
'default_standard' => 'Zend',
)
?>
/trunk/tests/PHP_CodeSniffer-1.2.0RC1/CodeSniffer.php
New file
0,0 → 1,1971
<?php
/**
* PHP_CodeSniffer tokenises PHP code and detects violations of a
* defined set of coding standards.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version CVS: $Id: CodeSniffer.php,v 1.88 2009/01/05 00:18:20 squiz Exp $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
 
spl_autoload_register(array('PHP_CodeSniffer', 'autoload'));
 
if (class_exists('PHP_CodeSniffer_Exception', true) === false) {
throw new Exception('Class PHP_CodeSniffer_Exception not found');
}
 
if (class_exists('PHP_CodeSniffer_File', true) === false) {
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_File not found');
}
 
if (class_exists('PHP_CodeSniffer_Tokens', true) === false) {
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Tokens not found');
}
 
if (interface_exists('PHP_CodeSniffer_Sniff', true) === false) {
throw new PHP_CodeSniffer_Exception('Interface PHP_CodeSniffer_Sniff not found');
}
 
if (interface_exists('PHP_CodeSniffer_MultiFileSniff', true) === false) {
throw new PHP_CodeSniffer_Exception('Interface PHP_CodeSniffer_MultiFileSniff not found');
}
 
/**
* PHP_CodeSniffer tokenises PHP code and detects violations of a
* defined set of coding standards.
*
* Standards are specified by classes that implement the PHP_CodeSniffer_Sniff
* interface. A sniff registers what token types it wishes to listen for, then
* PHP_CodeSniffer encounters that token, the sniff is invoked and passed
* information about where the token was found in the stack, and the token stack
* itself.
*
* Sniff files and their containing class must be prefixed with Sniff, and
* have an extension of .php.
*
* Multiple PHP_CodeSniffer operations can be performed by re-calling the
* process function with different parameters.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: @package_version@
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer
{
 
/**
* The file or directory that is currently being processed.
*
* @var string
*/
protected $file = array();
 
/**
* The directory to search for sniffs in.
*
* @var string
*/
protected $standardDir = '';
 
/**
* The files that have been processed.
*
* @var array(PHP_CodeSniffer_File)
*/
protected $files = array();
 
/**
* The listeners array.
*
* @var array(PHP_CodeSniffer_Sniff)
*/
protected $listeners = array();
 
/**
* The listeners array, indexed by token type.
*
* @var array()
*/
private $_tokenListeners = array(
'file' => array(),
'multifile' => array(),
);
 
/**
* An array of patterns to use for skipping files.
*
* @var array()
*/
protected $ignorePatterns = array();
 
/**
* An array of extensions for files we will check.
*
* @var array
*/
public $allowedFileExtensions = array(
'php' => 'PHP',
'inc' => 'PHP',
'js' => 'JS',
'css' => 'CSS',
);
 
/**
* An array of variable types for param/var we will check.
*
* @var array(string)
*/
public static $allowedTypes = array(
'array',
'boolean',
'float',
'integer',
'mixed',
'object',
'string',
);
 
 
/**
* Constructs a PHP_CodeSniffer object.
*
* @param int $verbosity The verbosity level.
* 1: Print progress information.
* 2: Print developer debug information.
* @param int $tabWidth The number of spaces each tab represents.
* If greater than zero, tabs will be replaced
* by spaces before testing each file.
*
* @see process()
*/
public function __construct($verbosity=0, $tabWidth=0)
{
define('PHP_CODESNIFFER_VERBOSITY', $verbosity);
define('PHP_CODESNIFFER_TAB_WIDTH', $tabWidth);
 
// Change into a directory that we know about to stop any
// relative path conflicts.
chdir(dirname(__FILE__).'/CodeSniffer/');
 
}//end __construct()
 
 
/**
* Autoload static method for loading classes and interfaces.
*
* @param string $className The name of the class or interface.
*
* @return void
*/
public static function autoload($className)
{
if (substr($className, 0, 4) === 'PHP_') {
$newClassName = substr($className, 4);
} else {
$newClassName = $className;
}
 
$path = str_replace('_', '/', $newClassName).'.php';
 
if (is_file(dirname(__FILE__).'/'.$path) === true) {
// Check standard file locations based on class name.
include dirname(__FILE__).'/'.$path;
} else if (is_file(dirname(__FILE__).'/CodeSniffer/Standards/'.$path) === true) {
// Check for included sniffs.
include dirname(__FILE__).'/CodeSniffer/Standards/'.$path;
} else {
// Everything else.
@include $path;
}
 
}//end autoload()
 
 
/**
* Sets an array of file extensions that we will allow checking of.
*
* If the extension is one of the defaults, a specific tokenizer
* will be used. Otherwise, the PHP tokenizer will be used for
* all extensions passed.
*
* @param array $extensions An array of file extensions.
*
* @return void
*/
public function setAllowedFileExtensions(array $extensions)
{
$newExtensions = array();
foreach ($extensions as $ext) {
if (isset($this->allowedFileExtensions[$ext]) === true) {
$newExtensions[$ext] = $this->allowedFileExtensions[$ext];
} else {
$newExtensions[$ext] = 'PHP';
}
}
 
$this->allowedFileExtensions = $newExtensions;
 
}//end setAllowedFileExtensions()
 
 
/**
* Sets an array of ignore patterns that we use to skip files and folders.
*
* Patterns are not case sensitive.
*
* @param array $patterns An array of ignore patterns.
*
* @return void
*/
public function setIgnorePatterns(array $patterns)
{
$this->ignorePatterns = $patterns;
 
}//end setIgnorePatterns()
 
 
/**
* Adds a file to the list of checked files.
*
* Checked files are used to generate error reports after the run.
*
* @param PHP_CodeSniffer_File $phpcsFile The file to add.
*
* @return void
*/
public function addFile(PHP_CodeSniffer_File $phpcsFile)
{
$this->files[] = $phpcsFile;
 
}//end addFile()
 
 
/**
* Processes the files/directories that PHP_CodeSniffer was constructed with.
*
* @param string|array $files The files and directories to process. For
* directories, each sub directory will also
* be traversed for source files.
* @param string $standard The set of code sniffs we are testing
* against.
* @param array $sniffs The sniff names to restrict the allowed
* listeners to.
* @param boolean $local If true, don't recurse into directories.
*
* @return void
* @throws PHP_CodeSniffer_Exception If files or standard are invalid.
*/
public function process($files, $standard, array $sniffs=array(), $local=false)
{
if (is_array($files) === false) {
if (is_string($files) === false || $files === null) {
throw new PHP_CodeSniffer_Exception('$file must be a string');
}
 
$files = array($files);
}
 
if (is_string($standard) === false || $standard === null) {
throw new PHP_CodeSniffer_Exception('$standard must be a string');
}
 
// Reset the members.
$this->listeners = array();
$this->files = array();
$this->_tokenListeners = array(
'file' => array(),
'multifile' => array(),
);
 
if (PHP_CODESNIFFER_VERBOSITY > 0) {
echo "Registering sniffs in $standard standard... ";
if (PHP_CODESNIFFER_VERBOSITY > 2) {
echo PHP_EOL;
}
}
 
$this->setTokenListeners($standard, $sniffs);
if (PHP_CODESNIFFER_VERBOSITY > 0) {
$numSniffs = count($this->listeners);
echo "DONE ($numSniffs sniffs registered)".PHP_EOL;
}
 
// Construct a list of listeners indexed by token being listened for.
foreach ($this->listeners as $listenerClass) {
$listener = new $listenerClass();
 
if (($listener instanceof PHP_CodeSniffer_Sniff) === true) {
$tokens = $listener->register();
if (is_array($tokens) === false) {
$msg = "Sniff $listenerClass register() method must return an array";
throw new PHP_CodeSniffer_Exception($msg);
}
 
foreach ($tokens as $token) {
if (isset($this->_tokenListeners['file'][$token]) === false) {
$this->_tokenListeners['file'][$token] = array();
}
 
if (in_array($listener, $this->_tokenListeners['file'][$token], true) === false) {
$this->_tokenListeners['file'][$token][] = $listener;
}
}
} else if (($listener instanceof PHP_CodeSniffer_MultiFileSniff) === true) {
$this->_tokenListeners['multifile'][] = $listener;
}
}//end foreach
 
foreach ($files as $file) {
$this->file = $file;
if (is_dir($this->file) === true) {
$this->processFiles($this->file, $local);
} else {
$this->processFile($this->file);
}
}
 
// Now process the multi-file sniffs, assuming there are
// multiple files being sniffed.
if (count($files) > 1) {
foreach ($this->_tokenListeners['multifile'] as $listener) {
// Set the name of the listener for error messages.
$activeListener = get_class($listener);
foreach ($this->files as $file) {
$file->setActiveListener($activeListener);
}
 
$listener->process($this->files);
}
}
 
}//end process()
 
 
/**
* Gets installed sniffs in the coding standard being used.
*
* Traverses the standard directory for classes that implement the
* PHP_CodeSniffer_Sniff interface asks them to register. Each of the
* sniff's class names must be exact as the basename of the sniff file.
*
* Returns an array of sniff class names.
*
* @param string $standard The name of the coding standard we are checking.
* @param array $sniffs The sniff names to restrict the allowed
* listeners to.
*
* @return array
* @throws PHP_CodeSniffer_Exception If any of the tests failed in the
* registration process.
*/
public function getTokenListeners($standard, array $sniffs=array())
{
if (is_dir($standard) === true) {
// This is a custom standard.
$this->standardDir = $standard;
$standard = basename($standard);
} else {
$this->standardDir = realpath(dirname(__FILE__).'/CodeSniffer/Standards/'.$standard);
}
 
$files = self::getSniffFiles($this->standardDir, $standard);
 
if (empty($sniffs) === false) {
// Convert the allowed sniffs to lower case so
// they are easier to check.
foreach ($sniffs as &$sniff) {
$sniff = strtolower($sniff);
}
}
 
$listeners = array();
 
foreach ($files as $file) {
// Work out where the position of /StandardName/Sniffs/... is
// so we can determine what the class will be called.
$sniffPos = strrpos($file, DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR);
if ($sniffPos === false) {
continue;
}
 
$slashPos = strrpos(substr($file, 0, $sniffPos), DIRECTORY_SEPARATOR);
if ($slashPos === false) {
continue;
}
 
$className = substr($file, ($slashPos + 1));
$className = substr($className, 0, -4);
$className = str_replace(DIRECTORY_SEPARATOR, '_', $className);
 
include_once $file;
 
// If they have specified a list of sniffs to restrict to, check
// to see if this sniff is allowed.
$allowed = in_array(strtolower($className), $sniffs);
if (empty($sniffs) === false && $allowed === false) {
continue;
}
 
$listeners[] = $className;
 
if (PHP_CODESNIFFER_VERBOSITY > 2) {
echo "\tRegistered $className".PHP_EOL;
}
}//end foreach
 
return $listeners;
 
}//end getTokenListeners()
 
 
/**
* Sets installed sniffs in the coding standard being used.
*
* @param string $standard The name of the coding standard we are checking.
* @param array $sniffs The sniff names to restrict the allowed
* listeners to.
*
* @return null
*/
public function setTokenListeners($standard, array $sniffs=array())
{
$this->listeners = $this->getTokenListeners($standard, $sniffs);
 
}//end setTokenListeners()
 
 
/**
* Return a list of sniffs that a coding standard has defined.
*
* Sniffs are found by recursing the standard directory and also by
* asking the standard for included sniffs.
*
* @param string $dir The directory where to look for the files.
* @param string $standard The name of the coding standard. If NULL, no
* included sniffs will be checked for.
*
* @return array
* @throws PHP_CodeSniffer_Exception If an included or excluded sniff does
* not exist.
*/
public static function getSniffFiles($dir, $standard=null)
{
$di = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
 
$ownSniffs = array();
$includedSniffs = array();
$excludedSniffs = array();
 
foreach ($di as $file) {
// Skip hidden files.
if (substr($file->getFilename(), 0, 1) === '.') {
continue;
}
 
// We are only interested in PHP and sniff files.
$fileParts = explode('.', $file);
if (array_pop($fileParts) !== 'php') {
continue;
}
 
$basename = basename($file, '.php');
if (substr($basename, -5) !== 'Sniff') {
continue;
}
 
$ownSniffs[] = $file->getPathname();
}//end foreach
 
// Load the standard class and ask it for a list of external
// sniffs to include in the standard.
if ($standard !== null
&& is_file("$dir/{$standard}CodingStandard.php") === true
) {
include_once "$dir/{$standard}CodingStandard.php";
$standardClassName = "PHP_CodeSniffer_Standards_{$standard}_{$standard}CodingStandard";
$standardClass = new $standardClassName;
 
$included = $standardClass->getIncludedSniffs();
foreach ($included as $sniff) {
if (is_dir($sniff) === true) {
// Trying to include from a custom standard.
$sniffDir = $sniff;
$sniff = basename($sniff);
} else if (is_file($sniff) === true) {
// Trying to include a custom sniff.
$sniffDir = $sniff;
} else {
$sniffDir = realpath(dirname(__FILE__)."/CodeSniffer/Standards/$sniff");
if ($sniffDir === false) {
$error = "Included sniff $sniff does not exist";
throw new PHP_CodeSniffer_Exception($error);
}
}
 
if (is_dir($sniffDir) === true) {
if (self::isInstalledStandard($sniff) === true) {
// We are including a whole coding standard.
$includedSniffs = array_merge($includedSniffs, self::getSniffFiles($sniffDir, $sniff));
} else {
// We are including a whole directory of sniffs.
$includedSniffs = array_merge($includedSniffs, self::getSniffFiles($sniffDir));
}
} else {
if (substr($sniffDir, -9) !== 'Sniff.php') {
$error = "Included sniff $sniff does not exist";
throw new PHP_CodeSniffer_Exception($error);
}
 
$includedSniffs[] = $sniffDir;
}
}//end foreach
 
$excluded = $standardClass->getExcludedSniffs();
foreach ($excluded as $sniff) {
if (is_dir($sniff) === true) {
// Trying to exclude from a custom standard.
$sniffDir = $sniff;
$sniff = basename($sniff);
} else if (is_file($sniff) === true) {
// Trying to exclude a custom sniff.
$sniffDir = $sniff;
} else {
$sniffDir = realpath(dirname(__FILE__)."/CodeSniffer/Standards/$sniff");
if ($sniffDir === false) {
$error = "Excluded sniff $sniff does not exist";
throw new PHP_CodeSniffer_Exception($error);
}
}
 
if (is_dir($sniffDir) === true) {
if (self::isInstalledStandard($sniff) === true) {
// We are excluding a whole coding standard.
$excludedSniffs = array_merge(
$excludedSniffs,
self::getSniffFiles($sniffDir, $sniff)
);
} else {
// We are excluding a whole directory of sniffs.
$excludedSniffs = array_merge(
$excludedSniffs,
self::getSniffFiles($sniffDir)
);
}
} else {
if (substr($sniffDir, -9) !== 'Sniff.php') {
$error = "Excluded sniff $sniff does not exist";
throw new PHP_CodeSniffer_Exception($error);
}
 
$excludedSniffs[] = $sniffDir;
}
}//end foreach
}//end if
 
// Merge our own sniff list with our exnternally included
// sniff list, but filter out any excluded sniffs.
$files = array();
foreach (array_merge($ownSniffs, $includedSniffs) as $sniff) {
if (in_array($sniff, $excludedSniffs) === true) {
continue;
} else {
$files[] = $sniff;
}
}
 
return $files;
 
}//end getSniffFiles()
 
 
/**
* Run the code sniffs over each file in a given directory.
*
* Recusively reads the specified directory and performs the PHP_CodeSniffer
* sniffs on each source file found within the directories.
*
* @param string $dir The directory to process.
* @param boolean $local If true, only process files in this directory, not
* sub directories.
*
* @return void
* @throws Exception If there was an error opening the directory.
*/
public function processFiles($dir, $local=false)
{
try {
if ($local === true) {
$di = new DirectoryIterator($dir);
} else {
$di = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
}
 
foreach ($di as $file) {
$filePath = realpath($file->getPathname());
 
if (is_dir($filePath) === true) {
continue;
}
 
// Check that the file's extension is one we are checking.
// Note that because we are doing a whole directory, we
// are strick about checking the extension and we don't
// let files with no extension through.
$fileParts = explode('.', $file);
$extension = array_pop($fileParts);
if ($extension === $file) {
continue;
}
 
if (isset($this->allowedFileExtensions[$extension]) === false) {
continue;
}
 
$this->processFile($filePath);
}//end foreach
} catch (Exception $e) {
$trace = $e->getTrace();
 
$filename = $trace[0]['args'][0];
if (is_numeric($filename) === true) {
// See if we can find the PHP_CodeSniffer_File object.
foreach ($trace as $data) {
if (isset($data['args'][0]) === true && ($data['args'][0] instanceof PHP_CodeSniffer_File) === true) {
$filename = $data['args'][0]->getFilename();
}
}
}
 
$error = 'An error occurred during processing; checking has been aborted. The error message was: '.$e->getMessage();
 
$phpcsFile = new PHP_CodeSniffer_File($filename, $this->listeners, $this->allowedFileExtensions);
$this->addFile($phpcsFile);
$phpcsFile->addError($error, null);
return;
}
 
}//end processFiles()
 
 
/**
* Run the code sniffs over a single given file.
*
* Processes the file and runs the PHP_CodeSniffer sniffs to verify that it
* conforms with the standard.
*
* @param string $file The file to process.
* @param string $contents The contents to parse. If NULL, the content
* is taken from the file system.
*
* @return void
* @throws PHP_CodeSniffer_Exception If the file could not be processed.
*/
public function processFile($file, $contents=null)
{
if ($contents === null && file_exists($file) === false) {
throw new PHP_CodeSniffer_Exception("Source file $file does not exist");
}
 
// If the file's path matches one of our ignore patterns, skip it.
foreach ($this->ignorePatterns as $pattern) {
$replacements = array(
'\\,' => ',',
'*' => '.*',
);
 
$pattern = strtr($pattern, $replacements);
if (preg_match("|{$pattern}|i", $file) === 1) {
return;
}
}
 
if (PHP_CODESNIFFER_VERBOSITY > 0) {
$startTime = time();
echo 'Processing '.basename($file).' ';
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo PHP_EOL;
}
}
 
$phpcsFile = new PHP_CodeSniffer_File(
$file,
$this->_tokenListeners['file'],
$this->allowedFileExtensions
);
$this->addFile($phpcsFile);
$phpcsFile->start($contents);
 
// Clean up the test if we can to save memory. This can't be done if
// we need to leave the files around for multi-file sniffs.
if (empty($this->_tokenListeners['multifile']) === true) {
$phpcsFile->cleanUp();
}
 
if (PHP_CODESNIFFER_VERBOSITY > 0) {
$timeTaken = (time() - $startTime);
if ($timeTaken === 0) {
echo 'DONE in < 1 second';
} else if ($timeTaken === 1) {
echo 'DONE in 1 second';
} else {
echo "DONE in $timeTaken seconds";
}
 
$errors = $phpcsFile->getErrorCount();
$warnings = $phpcsFile->getWarningCount();
echo " ($errors errors, $warnings warnings)".PHP_EOL;
}
 
}//end processFile()
 
 
/**
* Pre-process and package errors and warnings for all files.
*
* Used by error reports to get a packaged list of all errors and
* warnings in each file.
*
* @param boolean $showWarnings Show warnings as well as errors.
*
* @return array
*/
public function prepareErrorReport($showWarnings=true)
{
$report = array(
'totals' => array(
'warnings' => 0,
'errors' => 0,
),
'files' => array(),
);
 
foreach ($this->files as $file) {
$warnings = $file->getWarnings();
$errors = $file->getErrors();
$numWarnings = $file->getWarningCount();
$numErrors = $file->getErrorCount();
$filename = $file->getFilename();
 
$report['files'][$filename] = array(
'errors' => 0,
'warnings' => 0,
'messages' => array(),
);
 
if ($numErrors === 0 && $numWarnings === 0) {
// Prefect score!
continue;
}
 
if ($numErrors === 0 && $showWarnings === false) {
// Prefect score (sort of).
continue;
}
 
$report['files'][$filename]['errors'] = $numErrors;
if ($showWarnings === true) {
$report['files'][$filename]['warnings'] = $numWarnings;
} else {
$report['files'][$filename]['warnings'] = 0;
}
 
$report['totals']['errors'] += $numErrors;
if ($showWarnings === true) {
$report['totals']['warnings'] += $numWarnings;
}
 
// Merge errors and warnings.
foreach ($errors as $line => $lineErrors) {
foreach ($lineErrors as $column => $colErrors) {
$newErrors = array();
foreach ($colErrors as $data) {
$newErrors[] = array(
'message' => $data['message'],
'source' => $data['source'],
'type' => 'ERROR',
);
}
 
$errors[$line][$column] = $newErrors;
}
}//end foreach
 
if ($showWarnings === true) {
foreach ($warnings as $line => $lineWarnings) {
foreach ($lineWarnings as $column => $colWarnings) {
$newWarnings = array();
foreach ($colWarnings as $data) {
$newWarnings[] = array(
'message' => $data['message'],
'source' => $data['source'],
'type' => 'WARNING',
);
}
 
if (isset($errors[$line]) === false) {
$errors[$line] = array();
}
 
if (isset($errors[$line][$column]) === true) {
$errors[$line][$column] = array_merge(
$newWarnings,
$errors[$line][$column]
);
} else {
$errors[$line][$column] = $newWarnings;
}
}
}//end foreach
}//end if
 
ksort($errors);
 
$report['files'][$filename]['messages'] = $errors;
}//end foreach
 
return $report;
 
}//end prepareErrorReport()
 
 
/**
* Prints all errors and warnings for each file processed, in an XML format.
*
* Errors and warnings are displayed together, grouped by file.
*
* @param boolean $showWarnings Show warnings as well as errors.
*
* @return int The number of error and warning messages shown.
*/
public function printXMLErrorReport($showWarnings=true)
{
echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
echo '<phpcs version="@package_version@">'.PHP_EOL;
 
$errorsShown = 0;
 
$report = $this->prepareErrorReport($showWarnings);
foreach ($report['files'] as $filename => $file) {
if (empty($file['messages']) === true) {
continue;
}
 
echo ' <file name="'.$filename.'" errors="'.$file['errors'].'" warnings="'.$file['warnings'].'">'.PHP_EOL;
 
foreach ($file['messages'] as $line => $lineErrors) {
foreach ($lineErrors as $column => $colErrors) {
foreach ($colErrors as $error) {
$error['type'] = strtolower($error['type']);
echo ' <'.$error['type'].' line="'.$line.'" column="'.$column.'" source="'.$error['source'].'">';
echo htmlspecialchars($error['message']).'</'.$error['type'].'>'.PHP_EOL;
$errorsShown++;
}
}
}//end foreach
 
echo ' </file>'.PHP_EOL;
}//end foreach
 
echo '</phpcs>'.PHP_EOL;
 
return $errorsShown;
 
}//end printXMLErrorReport()
 
 
/**
* Prints all errors and warnings for processed files, in a Checkstyle format.
*
* Errors and warnings are displayed together, grouped by file.
*
* @param boolean $showWarnings Show warnings as well as errors.
*
* @return int The number of error and warning messages shown.
*/
public function printCheckstyleErrorReport($showWarnings=true)
{
echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
echo '<checkstyle version="@package_version@">'.PHP_EOL;
 
$errorsShown = 0;
 
$report = $this->prepareErrorReport($showWarnings);
foreach ($report['files'] as $filename => $file) {
echo ' <file name="'.$filename.'">'.PHP_EOL;
 
foreach ($file['messages'] as $line => $lineErrors) {
foreach ($lineErrors as $column => $colErrors) {
foreach ($colErrors as $error) {
$error['type'] = strtolower($error['type']);
echo ' <error';
echo ' line="'.$line.'" column="'.$column.'"';
echo ' severity="'.$error['type'].'"';
$message = utf8_encode(htmlspecialchars($error['message']));
echo ' message="'.$message.'"';
echo ' source="'.$error['source'].'"';
echo '/>'.PHP_EOL;
$errorsShown++;
}
}
}//end foreach
 
echo ' </file>'.PHP_EOL;
}//end foreach
 
echo '</checkstyle>'.PHP_EOL;
 
return $errorsShown;
 
}//end printCheckstyleErrorReport()
 
 
/**
* Prints all errors and warnings for each file processed, in a CSV format.
*
* @param boolean $showWarnings Show warnings as well as errors.
*
* @return int The number of error and warning messages shown.
*/
public function printCSVErrorReport($showWarnings=true)
{
echo 'File,Line,Column,Severity,Message,Source'.PHP_EOL;
 
$errorsShown = 0;
 
$report = $this->prepareErrorReport($showWarnings);
foreach ($report['files'] as $filename => $file) {
foreach ($file['messages'] as $line => $lineErrors) {
foreach ($lineErrors as $column => $colErrors) {
foreach ($colErrors as $error) {
$filename = str_replace('"', '\"', $filename);
$message = str_replace('"', '\"', $error['message']);
$type = strtolower($error['type']);
$source = $error['source'];
echo "\"$filename\",$line,$column,$type,\"$message\",$source".PHP_EOL;
$errorsShown++;
}
}
}//end foreach
}//end foreach
 
return $errorsShown;
 
}//end printCSVErrorReport()
 
 
/**
* Prints all errors and warnings for each file processed, in a format for emacs.
*
* @param boolean $showWarnings Show warnings as well as errors.
*
* @return int The number of error and warning messages shown.
*/
public function printEmacsErrorReport($showWarnings=true)
{
$errorsShown = 0;
 
$report = $this->prepareErrorReport($showWarnings);
foreach ($report['files'] as $filename => $file) {
foreach ($file['messages'] as $line => $lineErrors) {
foreach ($lineErrors as $column => $colErrors) {
foreach ($colErrors as $error) {
$message = $error['message'];
$type = strtolower($error['type']);
echo "$filename:$line:$column: $type - $message".PHP_EOL;
$errorsShown++;
}
}
}//end foreach
}//end foreach
 
return $errorsShown;
 
}//end printEmacsErrorReport()
 
 
/**
* Prints all errors and warnings for each file processed.
*
* Errors and warnings are displayed together, grouped by file.
*
* @param boolean $showWarnings Show warnings as well as errors.
* @param boolean $showSources Show error sources in report.
*
* @return int The number of error and warning messages shown.
*/
public function printErrorReport($showWarnings=true, $showSources=false)
{
$errorsShown = 0;
 
$report = $this->prepareErrorReport($showWarnings);
foreach ($report['files'] as $filename => $file) {
if (empty($file['messages']) === true) {
continue;
}
 
echo PHP_EOL.'FILE: ';
if (strlen($filename) <= 71) {
echo $filename;
} else {
echo '...'.substr($filename, (strlen($filename) - 71));
}
 
echo PHP_EOL;
echo str_repeat('-', 80).PHP_EOL;
 
echo 'FOUND '.$file['errors'].' ERROR(S) ';
 
if ($showWarnings === true) {
echo 'AND '.$file['warnings'].' WARNING(S) ';
}
 
echo 'AFFECTING '.count($file['messages']).' LINE(S)'.PHP_EOL;
echo str_repeat('-', 80).PHP_EOL;
 
// Work out the max line number for formatting.
$maxLine = 0;
foreach ($file['messages'] as $line => $lineErrors) {
if ($line > $maxLine) {
$maxLine = $line;
}
}
 
$maxLineLength = strlen($maxLine);
 
// The length of the word ERROR or WARNING; used for padding.
if ($showWarnings === true && $file['warnings'] > 0) {
$typeLength = 7;
} else {
$typeLength = 5;
}
 
// The padding that all lines will require that are
// printing an error message overflow.
$paddingLine2 = str_repeat(' ', ($maxLineLength + 1));
$paddingLine2 .= ' | ';
$paddingLine2 .= str_repeat(' ', $typeLength);
$paddingLine2 .= ' | ';
 
// The maxium amount of space an error message can use.
$maxErrorSpace = (79 - strlen($paddingLine2));
 
foreach ($file['messages'] as $line => $lineErrors) {
foreach ($lineErrors as $column => $colErrors) {
foreach ($colErrors as $error) {
$message = $error['message'];
if ($showSources === true) {
$message .= ' ('.substr($error['source'], 0, -5).')';
}
 
// The padding that goes on the front of the line.
$padding = ($maxLineLength - strlen($line));
$errorMsg = wordwrap(
$message,
$maxErrorSpace,
PHP_EOL."$paddingLine2"
);
 
echo ' '.str_repeat(' ', $padding).$line.' | '.$error['type'];
if ($error['type'] === 'ERROR') {
if ($showWarnings === true && $file['warnings'] > 0) {
echo ' ';
}
}
 
echo ' | '.$errorMsg.PHP_EOL;
$errorsShown++;
}//end foreach
}//end foreach
}//end foreach
 
echo str_repeat('-', 80).PHP_EOL.PHP_EOL;
}//end foreach
 
return $errorsShown;
 
}//end printErrorReport()
 
 
/**
* Prints a summary of errors and warnings for each file processed.
*
* If verbose output is enabled, results are shown for all files, even if
* they have no errors or warnings. If verbose output is disabled, we only
* show files that have at least one warning or error.
*
* @param boolean $showWarnings Show warnings as well as errors.
* @param boolean $showSources Show error sources in report.
*
* @return int The number of error and warning messages shown.
*/
public function printErrorReportSummary($showWarnings=true, $showSources=false)
{
$errorFiles = array();
 
foreach ($this->files as $file) {
$numWarnings = $file->getWarningCount();
$numErrors = $file->getErrorCount();
$filename = $file->getFilename();
 
// If verbose output is enabled, we show the results for all files,
// but if not, we only show files that had errors or warnings.
if (PHP_CODESNIFFER_VERBOSITY > 0
|| $numErrors > 0
|| ($numWarnings > 0
&& $showWarnings === true)
) {
$errorFiles[$filename] = array(
'warnings' => $numWarnings,
'errors' => $numErrors,
);
}//end if
}//end foreach
 
if (empty($errorFiles) === true) {
// Nothing to print.
return 0;
}
 
echo PHP_EOL.'PHP CODE SNIFFER REPORT SUMMARY'.PHP_EOL;
echo str_repeat('-', 80).PHP_EOL;
if ($showWarnings === true) {
echo 'FILE'.str_repeat(' ', 60).'ERRORS WARNINGS'.PHP_EOL;
} else {
echo 'FILE'.str_repeat(' ', 70).'ERRORS'.PHP_EOL;
}
 
echo str_repeat('-', 80).PHP_EOL;
 
$totalErrors = 0;
$totalWarnings = 0;
$totalFiles = 0;
 
foreach ($errorFiles as $file => $errors) {
if ($showWarnings === true) {
$padding = (62 - strlen($file));
} else {
$padding = (72 - strlen($file));
}
 
if ($padding < 0) {
$file = '...'.substr($file, (($padding * -1) + 3));
$padding = 0;
}
 
echo $file.str_repeat(' ', $padding).' ';
echo $errors['errors'];
if ($showWarnings === true) {
echo str_repeat(' ', (8 - strlen((string) $errors['errors'])));
echo $errors['warnings'];
}
 
echo PHP_EOL;
 
$totalErrors += $errors['errors'];
$totalWarnings += $errors['warnings'];
$totalFiles++;
}//end foreach
 
echo str_repeat('-', 80).PHP_EOL;
echo "A TOTAL OF $totalErrors ERROR(S) ";
if ($showWarnings === true) {
echo "AND $totalWarnings WARNING(S) ";
}
 
echo "WERE FOUND IN $totalFiles FILE(S)".PHP_EOL;
echo str_repeat('-', 80).PHP_EOL.PHP_EOL;
 
if ($showSources === true) {
$this->printSourceReport($showWarnings, true);
}
 
return ($totalErrors + $totalWarnings);
 
}//end printErrorReportSummary()
 
 
/**
* Prints the source of all errors and warnings.
*
* @param boolean $showWarnings Show warnings as well as errors.
* @param boolean $showSources Show error sources in report.
*
* @return int The number of error and warning messages shown.
*/
public function printSourceReport($showWarnings=true, $showSources=false)
{
$sources = array();
 
$errorsShown = 0;
 
$report = $this->prepareErrorReport($showWarnings);
foreach ($report['files'] as $filename => $file) {
foreach ($file['messages'] as $line => $lineErrors) {
foreach ($lineErrors as $column => $colErrors) {
foreach ($colErrors as $error) {
$errorsShown++;
 
$source = $error['source'];
if (isset($sources[$source]) === false) {
$sources[$source] = 1;
} else {
$sources[$source]++;
}
}
}
}//end foreach
}//end foreach
 
if ($errorsShown === 0) {
// Nothing to show.
return 0;
}
 
asort($sources);
$sources = array_reverse($sources);
 
echo PHP_EOL.'PHP CODE SNIFFER VIOLATION SOURCE SUMMARY'.PHP_EOL;
echo str_repeat('-', 80).PHP_EOL;
if ($showSources === true) {
echo 'SOURCE'.str_repeat(' ', 69).'COUNT'.PHP_EOL;
echo str_repeat('-', 80).PHP_EOL;
} else {
echo 'STANDARD CATEGORY SNIFF'.str_repeat(' ', 38).'COUNT'.PHP_EOL;
echo str_repeat('-', 80).PHP_EOL;
}
 
foreach ($sources as $source => $count) {
if ($showSources === true) {
$source = substr($source, 0, -5);
echo $source.str_repeat(' ', (75 - strlen($source)));
} else {
$parts = explode('.', $source);
 
if (strlen($parts[0]) > 10) {
$parts[0] = substr($parts[0], 0, ((strlen($parts[0]) -10) * -1));
}
echo $parts[0].str_repeat(' ', (12 - strlen($parts[0])));
 
$category = $this->makeFriendlyName($parts[1]);
if (strlen($category) > 18) {
$category = substr($category, 0, ((strlen($category) -18) * -1));
}
echo $category.str_repeat(' ', (20 - strlen($category)));
 
$sniff = substr($parts[2], 0, -5);
$sniff = $this->makeFriendlyName($sniff);
if (strlen($sniff) > 41) {
$sniff = substr($sniff, 0, ((strlen($sniff) - 41) * -1));
}
echo $sniff.str_repeat(' ', (43 - strlen($sniff)));
}
 
echo $count.PHP_EOL;
}//end foreach
 
echo str_repeat('-', 80).PHP_EOL;
echo "A TOTAL OF $errorsShown SNIFF VIOLATION(S) ";
echo 'WERE FOUND IN '.count($sources).' SOURCE(S)'.PHP_EOL;
echo str_repeat('-', 80).PHP_EOL.PHP_EOL;
 
return $errorsShown;
 
}//end printSourceReport()
 
 
/**
* Converts a camel caps name into a readable string.
*
* @param string $name The camel caps name to convert.
*
* @return string
*/
public function makeFriendlyName($name)
{
$friendlyName = '';
$length = strlen($name);
 
$lastWasUpper = false;
$lastWasNumeric = false;
for ($i = 0; $i < $length; $i++) {
if (is_numeric($name[$i]) === true) {
if ($lastWasNumeric === false) {
$friendlyName .= ' ';
}
 
$lastWasUpper = false;
$lastWasNumeric = true;
} else {
$lastWasNumeric = false;
 
$char = strtolower($name[$i]);
if ($char === $name[$i]) {
// Lowercase.
$lastWasUpper = false;
} else {
// Uppercase.
if ($lastWasUpper === false) {
$friendlyName .= ' ';
$next = $name[($i + 1)];
if (strtolower($next) === $next) {
// Next char is lowercase so it is a word boundary.
$name[$i] = strtolower($name[$i]);
}
}
 
$lastWasUpper = true;
}
}//end if
 
$friendlyName .= $name[$i];
}//end for
 
$friendlyName = trim($friendlyName);
$friendlyName[0] = strtoupper($friendlyName[0]);
 
return $friendlyName;
 
}//end makeFriendlyName()
 
 
/**
* Generates documentation for a coding standard.
*
* @param string $standard The standard to generate docs for
* @param array $sniffs A list of sniffs to limit the docs to.
* @param string $generator The name of the generator class to use.
*
* @return void
*/
public function generateDocs($standard, array $sniffs=array(), $generator='Text')
{
include_once 'PHP/CodeSniffer/DocGenerators/'.$generator.'.php';
 
$class = "PHP_CodeSniffer_DocGenerators_$generator";
$generator = new $class($standard, $sniffs);
 
$generator->generate();
 
}//end generateDocs()
 
 
/**
* Returns the PHP_CodeSniffer file objects.
*
* @return array(PHP_CodeSniffer_File)
*/
public function getFiles()
{
return $this->files;
 
}//end getFiles()
 
 
/**
* Gets the array of PHP_CodeSniffer_Sniff's.
*
* @return array(PHP_CodeSniffer_Sniff)
*/
public function getSniffs()
{
return $this->listeners;
 
}//end getSniffs()
 
 
/**
* Gets the array of PHP_CodeSniffer_Sniff's indexed by token type.
*
* @return array()
*/
public function getTokenSniffs()
{
return $this->_tokenListeners;
 
}//end getTokenSniffs()
 
 
/**
* Takes a token produced from <code>token_get_all()</code> and produces a
* more uniform token.
*
* Note that this method also resolves T_STRING tokens into more descrete
* types, therefore there is no need to call resolveTstringToken()
*
* @param string|array $token The token to convert.
*
* @return array The new token.
*/
public static function standardiseToken($token)
{
if (is_array($token) === false) {
$newToken = self::resolveSimpleToken($token);
} else {
switch ($token[0]) {
case T_STRING:
// Some T_STRING tokens can be more specific.
$newToken = self::resolveTstringToken($token);
break;
case T_CURLY_OPEN:
$newToken = array();
$newToken['code'] = T_OPEN_CURLY_BRACKET;
$newToken['content'] = $token[1];
$newToken['type'] = 'T_OPEN_CURLY_BRACKET';
break;
default:
$newToken = array();
$newToken['code'] = $token[0];
$newToken['content'] = $token[1];
$newToken['type'] = token_name($token[0]);
break;
}//end switch
}//end if
 
return $newToken;
 
}//end standardiseToken()
 
 
/**
* Converts T_STRING tokens into more usable token names.
*
* The token should be produced using the token_get_all() function.
* Currently, not all T_STRING tokens are converted.
*
* @param string|array $token The T_STRING token to convert as constructed
* by token_get_all().
*
* @return array The new token.
*/
public static function resolveTstringToken(array $token)
{
$newToken = array();
switch (strtolower($token[1])) {
case 'false':
$newToken['type'] = 'T_FALSE';
break;
case 'true':
$newToken['type'] = 'T_TRUE';
break;
case 'null':
$newToken['type'] = 'T_NULL';
break;
case 'self':
$newToken['type'] = 'T_SELF';
break;
case 'parent':
$newToken['type'] = 'T_PARENT';
break;
default:
$newToken['type'] = 'T_STRING';
break;
}
 
$newToken['code'] = constant($newToken['type']);
$newToken['content'] = $token[1];
 
return $newToken;
 
}//end resolveTstringToken()
 
 
/**
* Converts simple tokens into a format that conforms to complex tokens
* produced by token_get_all().
*
* Simple tokens are tokens that are not in array form when produced from
* token_get_all().
*
* @param string $token The simple token to convert.
*
* @return array The new token in array format.
*/
public static function resolveSimpleToken($token)
{
$newToken = array();
 
switch ($token) {
case '{':
$newToken['type'] = 'T_OPEN_CURLY_BRACKET';
break;
case '}':
$newToken['type'] = 'T_CLOSE_CURLY_BRACKET';
break;
case '[':
$newToken['type'] = 'T_OPEN_SQUARE_BRACKET';
break;
case ']':
$newToken['type'] = 'T_CLOSE_SQUARE_BRACKET';
break;
case '(':
$newToken['type'] = 'T_OPEN_PARENTHESIS';
break;
case ')':
$newToken['type'] = 'T_CLOSE_PARENTHESIS';
break;
case ':':
$newToken['type'] = 'T_COLON';
break;
case '.':
$newToken['type'] = 'T_STRING_CONCAT';
break;
case '?':
$newToken['type'] = 'T_INLINE_THEN';
break;
case ';':
$newToken['type'] = 'T_SEMICOLON';
break;
case '=':
$newToken['type'] = 'T_EQUAL';
break;
case '*':
$newToken['type'] = 'T_MULTIPLY';
break;
case '/':
$newToken['type'] = 'T_DIVIDE';
break;
case '+':
$newToken['type'] = 'T_PLUS';
break;
case '-':
$newToken['type'] = 'T_MINUS';
break;
case '%':
$newToken['type'] = 'T_MODULUS';
break;
case '^':
$newToken['type'] = 'T_POWER';
break;
case '&':
$newToken['type'] = 'T_BITWISE_AND';
break;
case '|':
$newToken['type'] = 'T_BITWISE_OR';
break;
case '<':
$newToken['type'] = 'T_LESS_THAN';
break;
case '>':
$newToken['type'] = 'T_GREATER_THAN';
break;
case '!':
$newToken['type'] = 'T_BOOLEAN_NOT';
break;
case ',':
$newToken['type'] = 'T_COMMA';
break;
case '@':
$newToken['type'] = 'T_ASPERAND';
break;
default:
$newToken['type'] = 'T_NONE';
break;
}//end switch
 
$newToken['code'] = constant($newToken['type']);
$newToken['content'] = $token;
 
return $newToken;
 
}//end resolveSimpleToken()
 
 
/**
* Returns true if the specified string is in the camel caps format.
*
* @param string $string The string the verify.
* @param boolean $classFormat If true, check to see if the string is in the
* class format. Class format strings must start
* with a capital letter and contain no
* underscores.
* @param boolean $public If true, the first character in the string
* must be an a-z character. If false, the
* character must be an underscore. This
* argument is only applicable if $classFormat
* is false.
* @param boolean $strict If true, the string must not have two captial
* letters next to each other. If false, a
* relaxed camel caps policy is used to allow
* for acronyms.
*
* @return boolean
*/
public static function isCamelCaps(
$string,
$classFormat=false,
$public=true,
$strict=true
) {
// Check the first character first.
if ($classFormat === false) {
if ($public === false) {
$legalFirstChar = '[_][a-z]';
} else {
$legalFirstChar = '[a-z]';
}
} else {
$legalFirstChar = '[A-Z]';
}
 
if (preg_match("|^$legalFirstChar|", $string) === 0) {
return false;
}
 
// Check that the name only contains legal characters.
if ($classFormat === false) {
$legalChars = 'a-zA-Z0-9';
} else {
$legalChars = 'a-zA-Z';
}
 
if (preg_match("|[^$legalChars]|", substr($string, 1)) > 0) {
return false;
}
 
if ($strict === true) {
// Check that there are not two captial letters next to each other.
$length = strlen($string);
$lastCharWasCaps = $classFormat;
 
for ($i = 1; $i < $length; $i++) {
$ascii = ord($string{$i});
if ($ascii >= 48 && $ascii <= 57) {
// The character is a number, so it cant be a captial.
$isCaps = false;
} else {
if (strtoupper($string{$i}) === $string{$i}) {
$isCaps = true;
} else {
$isCaps = false;
}
}
 
if ($isCaps === true && $lastCharWasCaps === true) {
return false;
}
 
$lastCharWasCaps = $isCaps;
}
}//end if
 
return true;
 
}//end isCamelCaps()
 
 
/**
* Returns true if the specified string is in the underscore caps format.
*
* @param string $string The string to verify.
*
* @return boolean
*/
public static function isUnderscoreName($string)
{
// If there are space in the name, it can't be valid.
if (strpos($string, ' ') !== false) {
return false;
}
 
$validName = true;
$nameBits = explode('_', $string);
 
if (preg_match('|^[A-Z]|', $string) === 0) {
// Name does not begin with a capital letter.
$validName = false;
} else {
foreach ($nameBits as $bit) {
if ($bit{0} !== strtoupper($bit{0})) {
$validName = false;
break;
}
}
}
 
return $validName;
 
}//end isUnderscoreName()
 
 
/**
* Returns a valid variable type for param/var tag.
*
* If type is not one of the standard type, it must be a custom type.
* Returns the correct type name suggestion if type name is invalid.
*
* @param string $varType The variable type to process.
*
* @return string
*/
public static function suggestType($varType)
{
if ($varType === '') {
return '';
}
 
if (in_array($varType, self::$allowedTypes) === true) {
return $varType;
} else {
$lowerVarType = strtolower($varType);
switch ($lowerVarType) {
case 'bool':
return 'boolean';
case 'double':
case 'real':
return 'float';
case 'int':
return 'integer';
case 'array()':
return 'array';
}//end switch
 
if (strpos($lowerVarType, 'array(') !== false) {
// Valid array declaration:
// array, array(type), array(type1 => type2).
$matches = array();
$pattern = '/^array\(\s*([^\s^=^>]*)(\s*=>\s*(.*))?\s*\)/i';
if (preg_match($pattern, $varType, $matches) !== 0) {
$type1 = '';
if (isset($matches[1]) === true) {
$type1 = $matches[1];
}
 
$type2 = '';
if (isset($matches[3]) === true) {
$type2 = $matches[3];
}
 
$type1 = self::suggestType($type1);
$type2 = self::suggestType($type2);
if ($type2 !== '') {
$type2 = ' => '.$type2;
}
 
return "array($type1$type2)";
} else {
return 'array';
}//end if
} else if (in_array($lowerVarType, self::$allowedTypes) === true) {
// A valid type, but not lower cased.
return $lowerVarType;
} else {
// Must be a custom type name.
return $varType;
}//end if
}//end if
 
}//end suggestType()
 
 
/**
* Get a list of all coding standards installed.
*
* Coding standards are directories located in the
* CodeSniffer/Standards directory. Valid coding standards
* include a Sniffs subdirectory.
*
* @param boolean $includeGeneric If true, the special "Generic"
* coding standard will be included
* if installed.
* @param string $standardsDir A specific directory to look for standards
* in. If not specified, PHP_CodeSniffer will
* look in its default location.
*
* @return array
* @see isInstalledStandard()
*/
public static function getInstalledStandards(
$includeGeneric=false,
$standardsDir=''
) {
$installedStandards = array();
 
if ($standardsDir === '') {
$standardsDir = dirname(__FILE__).'/CodeSniffer/Standards';
}
 
$di = new DirectoryIterator($standardsDir);
foreach ($di as $file) {
if ($file->isDir() === true && $file->isDot() === false) {
$filename = $file->getFilename();
 
// Ignore the special "Generic" standard.
if ($includeGeneric === false && $filename === 'Generic') {
continue;
}
 
// Valid coding standard dirs include a standard class.
$csFile = $file->getPathname()."/{$filename}CodingStandard.php";
if (is_file($csFile) === true) {
// We found a coding standard directory.
$installedStandards[] = $filename;
}
}
}
 
return $installedStandards;
 
}//end getInstalledStandards()
 
 
/**
* Determine if a standard is installed.
*
* Coding standards are directories located in the
* CodeSniffer/Standards directory. Valid coding standards
* include a Sniffs subdirectory.
*
* @param string $standard The name of the coding standard.
*
* @return boolean
* @see getInstalledStandards()
*/
public static function isInstalledStandard($standard)
{
$standardDir = dirname(__FILE__);
$standardDir .= '/CodeSniffer/Standards/'.$standard;
if (is_file("$standardDir/{$standard}CodingStandard.php") === true) {
return true;
} else {
// This could be a custom standard, installed outside our
// standards directory.
$standardFile = rtrim($standard, ' /\\').DIRECTORY_SEPARATOR.basename($standard).'CodingStandard.php';
return (is_file($standardFile) === true);
}
 
}//end isInstalledStandard()
 
 
/**
* Get a single config value.
*
* Config data is stored in the data dir, in a file called
* CodeSniffer.conf. It is a simple PHP array.
*
* @param string $key The name of the config value.
*
* @return string
* @see setConfigData()
* @see getAllConfigData()
*/
public static function getConfigData($key)
{
$phpCodeSnifferConfig = self::getAllConfigData();
 
if ($phpCodeSnifferConfig === null) {
return null;
}
 
if (isset($phpCodeSnifferConfig[$key]) === false) {
return null;
}
 
return $phpCodeSnifferConfig[$key];
 
}//end getConfigData()
 
 
/**
* Set a single config value.
*
* Config data is stored in the data dir, in a file called
* CodeSniffer.conf. It is a simple PHP array.
*
* @param string $key The name of the config value.
* @param string|null $value The value to set. If null, the config
* entry is deleted, reverting it to the
* default value.
* @param boolean $temp Set this config data temporarily for this
* script run. This will not write the config
* data to the config file.
*
* @return boolean
* @see getConfigData()
* @throws PHP_CodeSniffer_Exception If the config file can not be written.
*/
public static function setConfigData($key, $value, $temp=false)
{
if ($temp === false) {
$configFile = dirname(__FILE__).'/CodeSniffer.conf';
if (is_file($configFile) === false) {
$configFile = '@data_dir@/PHP_CodeSniffer/CodeSniffer.conf';
}
 
if (is_file($configFile) === true
&& is_writable($configFile) === false
) {
$error = "Config file $configFile is not writable";
throw new PHP_CodeSniffer_Exception($error);
}
}
 
$phpCodeSnifferConfig = self::getAllConfigData();
 
if ($value === null) {
if (isset($phpCodeSnifferConfig[$key]) === true) {
unset($phpCodeSnifferConfig[$key]);
}
} else {
$phpCodeSnifferConfig[$key] = $value;
}
 
if ($temp === false) {
$output = '<'.'?php'."\n".' $phpCodeSnifferConfig = ';
$output .= var_export($phpCodeSnifferConfig, true);
$output .= "\n?".'>';
 
if (file_put_contents($configFile, $output) === false) {
return false;
}
}
 
$GLOBALS['PHP_CODESNIFFER_CONFIG_DATA'] = $phpCodeSnifferConfig;
 
return true;
 
}//end setConfigData()
 
 
/**
* Get all config data in an array.
*
* @return string
* @see getConfigData()
*/
public static function getAllConfigData()
{
if (isset($GLOBALS['PHP_CODESNIFFER_CONFIG_DATA']) === true) {
return $GLOBALS['PHP_CODESNIFFER_CONFIG_DATA'];
}
 
$configFile = dirname(__FILE__).'/CodeSniffer.conf';
if (is_file($configFile) === false) {
$configFile = '@data_dir@/PHP_CodeSniffer/CodeSniffer.conf';
}
 
if (is_file($configFile) === false) {
return null;
}
 
include $configFile;
$GLOBALS['PHP_CODESNIFFER_CONFIG_DATA'] = $phpCodeSnifferConfig;
return $GLOBALS['PHP_CODESNIFFER_CONFIG_DATA'];
 
}//end getAllConfigData()
 
 
}//end class
 
?>
/trunk/verif_code.txt
New file
0,0 → 1,2
Commande pour lancer la vérification
/opt/lampp/bin/php phpcs --standard=PEAR -v -n /home/aurelien/web/framework/file.php
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/trunk/.project
New file
0,0 → 1,17
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>framework</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>net.sourceforge.phpeclipse.parserbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>net.sourceforge.phpeclipse.phpnature</nature>
</natures>
</projectDescription>
/trunk/doc/eFlore/Debogage/_bibliotheque---Chronometre.php.html
New file
0,0 → 1,93
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs for page Chronometre.php</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../../classtrees_eFlore.html">Class
Tree: eFlore</a> ] [ <a href="../../elementindex_eFlore.html">Index:
eFlore</a> ] [ <a href="../../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">eFlore</div>
<div id="packageTitle">eFlore</div>
<div id="elementPath">Debogage &middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../../li_default.html">default</a></p>
<p><a href="../../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
subpackage <b>Debogage</b><br>
<a href="../../eFlore/Debogage/_bibliotheque---Chronometre.php.html">
Chronometre.php </a><br>
<a
href="../../eFlore/Debogage/_bibliotheque---GestionnaireErreur.php.html">
GestionnaireErreur.php </a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<b>Debogage</b><br>
<a href="../../eFlore/Debogage/Chronometre.html"> Chronometre </a><br>
<a href="../../eFlore/Debogage/GestionnaireErreur.html">
GestionnaireErreur </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Procedural File: Chronometre.php</h1>
<p style="margin: 0px;">Source Location:
/bibliotheque/Chronometre.php</p>
 
<br>
<br>
 
<div class="contents">
<h2>Classes:</h2>
<dl>
<dt><a href="../../eFlore/Debogage/Chronometre.html">Chronometre</a></dt>
<dd>Classe Chronometre() - Permet de stocker et d'afficher les
temps d'éxécution de script.</dd>
</dl>
</div>
 
<h2>Page Details:</h2>
<p align="center"><strong>Classe permettant de mesurer le
temps d'execution d'un script. </strong></p>
<p>Contient des méthodes permettant d'évaluer la vitesse d'exécution
d'un script.</p>
<h4>Tags:</h4>
<ul>
<li><b>author</b> - aucun</li>
<li><b>author</b> - Jean-Pascal MILCENT &lt;<a
href="mailto:jpm@tela-botanica.org">jpm@tela-botanica.org</a>&gt;</li>
<li><b>version</b> - $Revision: 1.1 $ $Date: 2007-01-12 13:16:09 $</li>
<li><b>copyright</b> - Tela-Botanica 2000-2005</li>
</ul>
<hr>
<hr>
<div id="global"></div>
<hr>
<div id="define"></div>
<hr>
<div id="function"></div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/eFlore/Debogage/Chronometre.html
New file
0,0 → 1,242
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs For Class Chronometre</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../../classtrees_eFlore.html">Class
Tree: eFlore</a> ] [ <a href="../../elementindex_eFlore.html">Index:
eFlore</a> ] [ <a href="../../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">eFlore</div>
<div id="packageTitle">eFlore</div>
<div id="elementPath">Debogage &middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../../li_default.html">default</a></p>
<p><a href="../../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
subpackage <b>Debogage</b><br>
<a href="../../eFlore/Debogage/_bibliotheque---Chronometre.php.html">
Chronometre.php </a><br>
<a
href="../../eFlore/Debogage/_bibliotheque---GestionnaireErreur.php.html">
GestionnaireErreur.php </a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<b>Debogage</b><br>
<a href="../../eFlore/Debogage/Chronometre.html"> Chronometre </a><br>
<a href="../../eFlore/Debogage/GestionnaireErreur.html">
GestionnaireErreur </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Class: Chronometre</h1>
<p style="margin: 0px;">Source Location:
/bibliotheque/Chronometre.php</p>
 
 
<div class="leftcol">
<h3><a href="#class_details">Class Overview</a> <span
class="smalllinenumber">[line 57]</span></h3>
<div id="classTree"><pre></pre></div>
<div class="small">
<p>Classe Chronometre() - Permet de stocker et d'afficher les temps
d'éxécution de script.</p>
<h4>Author(s):</h4>
<ul>
<li>Jean-Pascal MILCENT &lt;<a href="mailto:jpm@tela-botanica.org">jpm@tela-botanica.org</a>&gt;</li>
</ul>
<h4>Version:</h4>
<ul>
</ul>
 
<h4>Copyright:</h4>
<ul>
</li>
</div>
</div>
 
<div class="middlecol">
<h3><a href="#class_vars">Variables</a></h3>
<ul class="small">
</ul>
<h3><a href="#class_consts">Constants</a></h3>
<ul class="small">
</ul>
</div>
<div class="rightcol">
<h3><a href="#class_methods">Methods</a></h3>
<ul class="small">
<li><a
href="../../eFlore/Debogage/Chronometre.html#method__construct">__construct</a></li>
<li><a
href="../../eFlore/Debogage/Chronometre.html#methodafficherChrono">afficherChrono</a></li>
<li><a
href="../../eFlore/Debogage/Chronometre.html#methodgetTemps">getTemps</a></li>
<li><a
href="../../eFlore/Debogage/Chronometre.html#methodsetTemps">setTemps</a></li>
</ul>
</div>
 
<div id="content">
<hr>
<div class="contents"></div>
 
<div class="leftCol">
<h2>Inherited Variables</h2>
<h2>Inherited Constants</h2>
</div>
 
<div class="rightCol">
<h2>Inherited Methods</h2>
</div>
<br clear="all">
<hr>
 
<a name="class_details"></a>
<h2>Class Details</h2>
<p align="center"><strong>Classe Chronometre() - Permet de
stocker et d'afficher les temps d'éxécution de script. </strong></p>
<p>Cette classe permet de réaliser un ensemble de mesure de temps
prises à différents endroits d'un script. Ces mesures peuvent ensuite
être affichées au sein d'un tableau XHTML.</p>
<h4>Tags:</h4>
<ul>
<li><b>author</b> - Jean-Pascal MILCENT &lt;<a
href="mailto:jpm@tela-botanica.org">jpm@tela-botanica.org</a>&gt;</li>
</ul>
<p class="small" style="color: #334B66;">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_vars"></a>
<h2>Class Variables</h2>
 
<hr>
<a name="class_methods"></a>
<h2>Class Methods</h2>
 
<a name="method__construct"></a>
<p></p>
<h3>__construct</h3>
<div class="indent">
<p><code>Chronometre __construct( )</code></p>
 
<p class="linenumber">[line 63]</p>
<p align="center"><strong>* Constructeur : ** </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodafficherChrono"></a>
<p></p>
<h3>afficherChrono</h3>
<div class="indent">
<p><code>string afficherChrono( [int $indentation_origine =
8], [int $indentation = 4])</code></p>
 
<p class="linenumber">[line 98]</p>
<p align="center"><strong>Méthode afficherChrono() - Permet
d'afficher les temps d'éxécution de différentes parties d'un script. </strong></p>
<p>Cette fonction permet d'afficher un ensemble de mesure de temps
prises à différents endroits d'un script. Ces mesures sont affichées au
sein d'un tableau XHTML dont on peut controler l'indentation des
balises. Pour un site en production, il suffit d'ajouter un style
#chrono {display:none;} dans la css. De cette façon, le tableau ne
s'affichera pas. Le webmaster lui pourra rajouter sa propre feuille de
style affichant le tableau. Le développeur initial de cette fonction est
Loic d'Anterroches. Elle a été modifiée par Jean-Pascal Milcent. Elle
utilise une variable gobale : $_CHRONO_</p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - la chaine XHTML de mesure des temps.</li>
<li><b>author</b> - Loic d'Anterroches</li>
<li><b>author</b> - Jean-Pascal MILCENT &lt;<a
href="mailto:jpm@tela-botanica.org">jpm@tela-botanica.org</a>&gt;</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">int</span> <b>$indentation_origine</b> -
l'indentation de base pour le code html du tableau.</li>
<li><span class="type">int</span> <b>$indentation</b> - le pas
d'indentation pour le code html du tableau.</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetTemps"></a>
<p></p>
<h3>getTemps</h3>
<div class="indent">
<p><code>void getTemps( [ $cle = NULL])</code></p>
 
<p class="linenumber">[line 69]</p>
<p align="center"><strong>* Accesseurs : ** </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type"></span> <b>$cle</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetTemps"></a>
<p></p>
<h3>setTemps</h3>
<div class="indent">
<p><code>void setTemps( [ $moment = array()])</code></p>
 
<p class="linenumber">[line 77]</p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type"></span> <b>$moment</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_consts"></a>
<h2>Class Constants</h2>
</div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/eFlore/Debogage/_bibliotheque---GestionnaireErreur.php.html
New file
0,0 → 1,89
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs for page GestionnaireErreur.php</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../../classtrees_eFlore.html">Class
Tree: eFlore</a> ] [ <a href="../../elementindex_eFlore.html">Index:
eFlore</a> ] [ <a href="../../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">eFlore</div>
<div id="packageTitle">eFlore</div>
<div id="elementPath">Debogage &middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../../li_default.html">default</a></p>
<p><a href="../../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
subpackage <b>Debogage</b><br>
<a href="../../eFlore/Debogage/_bibliotheque---Chronometre.php.html">
Chronometre.php </a><br>
<a
href="../../eFlore/Debogage/_bibliotheque---GestionnaireErreur.php.html">
GestionnaireErreur.php </a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<b>Debogage</b><br>
<a href="../../eFlore/Debogage/Chronometre.html"> Chronometre </a><br>
<a href="../../eFlore/Debogage/GestionnaireErreur.html">
GestionnaireErreur </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Procedural File: GestionnaireErreur.php</h1>
<p style="margin: 0px;">Source Location:
/bibliotheque/GestionnaireErreur.php</p>
 
<br>
<br>
 
<div class="contents">
<h2>Classes:</h2>
<dl>
<dt><a href="../../eFlore/Debogage/GestionnaireErreur.html">GestionnaireErreur</a></dt>
<dd>Classe GestionnaireErreur</dd>
</dl>
</div>
 
<h2>Page Details:</h2>
<p align="center"><strong>Classe de gestion des erreurs. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>author</b> - aucun</li>
<li><b>author</b> - Jean-Pascal MILCENT &lt;<a
href="mailto:jpm@tela-botanica.org">jpm@tela-botanica.org</a>&gt;</li>
<li><b>version</b> - $Revision: 1.6 $ $Date: 2007-07-09 18:54:43 $</li>
<li><b>copyright</b> - Tela-Botanica 2000-2005</li>
</ul>
<hr>
<hr>
<div id="global"></div>
<hr>
<div id="define"></div>
<hr>
<div id="function"></div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/eFlore/Debogage/GestionnaireErreur.html
New file
0,0 → 1,391
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs For Class GestionnaireErreur</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../../classtrees_eFlore.html">Class
Tree: eFlore</a> ] [ <a href="../../elementindex_eFlore.html">Index:
eFlore</a> ] [ <a href="../../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">eFlore</div>
<div id="packageTitle">eFlore</div>
<div id="elementPath">Debogage &middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../../li_default.html">default</a></p>
<p><a href="../../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
subpackage <b>Debogage</b><br>
<a href="../../eFlore/Debogage/_bibliotheque---Chronometre.php.html">
Chronometre.php </a><br>
<a
href="../../eFlore/Debogage/_bibliotheque---GestionnaireErreur.php.html">
GestionnaireErreur.php </a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<b>Debogage</b><br>
<a href="../../eFlore/Debogage/Chronometre.html"> Chronometre </a><br>
<a href="../../eFlore/Debogage/GestionnaireErreur.html">
GestionnaireErreur </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Class: GestionnaireErreur</h1>
<p style="margin: 0px;">Source Location:
/bibliotheque/GestionnaireErreur.php</p>
 
 
<div class="leftcol">
<h3><a href="#class_details">Class Overview</a> <span
class="smalllinenumber">[line 56]</span></h3>
<div id="classTree"><pre></pre></div>
<div class="small">
<p>Classe GestionnaireErreur</p>
<h4>Author(s):</h4>
<ul>
</ul>
<h4>Version:</h4>
<ul>
</ul>
 
<h4>Copyright:</h4>
<ul>
</li>
</div>
</div>
 
<div class="middlecol">
<h3><a href="#class_vars">Variables</a></h3>
<ul class="small">
</ul>
<h3><a href="#class_consts">Constants</a></h3>
<ul class="small">
</ul>
</div>
<div class="rightcol">
<h3><a href="#class_methods">Methods</a></h3>
<ul class="small">
<li><a
href="../../eFlore/Debogage/GestionnaireErreur.html#methodgererErreur">gererErreur</a></li>
<li><a
href="../../eFlore/Debogage/GestionnaireErreur.html#methodgetContexte">getContexte</a></li>
<li><a
href="../../eFlore/Debogage/GestionnaireErreur.html#methodgetErreur">getErreur</a></li>
<li><a
href="../../eFlore/Debogage/GestionnaireErreur.html#methodgetInstance">getInstance</a></li>
<li><a
href="../../eFlore/Debogage/GestionnaireErreur.html#methodgetNiveauErreurCourant">getNiveauErreurCourant</a></li>
<li><a
href="../../eFlore/Debogage/GestionnaireErreur.html#methodretournerErreur">retournerErreur</a></li>
<li><a
href="../../eFlore/Debogage/GestionnaireErreur.html#methodretournerErreurSql">retournerErreurSql</a></li>
<li><a
href="../../eFlore/Debogage/GestionnaireErreur.html#methodsetActive">setActive</a></li>
<li><a
href="../../eFlore/Debogage/GestionnaireErreur.html#methodsetContexte">setContexte</a></li>
<li><a
href="../../eFlore/Debogage/GestionnaireErreur.html#methodsetErreur">setErreur</a></li>
<li><a
href="../../eFlore/Debogage/GestionnaireErreur.html#methodsetNiveauErreurCourant">setNiveauErreurCourant</a></li>
</ul>
</div>
 
<div id="content">
<hr>
<div class="contents"></div>
 
<div class="leftCol">
<h2>Inherited Variables</h2>
<h2>Inherited Constants</h2>
</div>
 
<div class="rightCol">
<h2>Inherited Methods</h2>
</div>
<br clear="all">
<hr>
 
<a name="class_details"></a>
<h2>Class Details</h2>
<p align="center"><strong>Classe GestionnaireErreur </strong></p>
<p>Gérer les erreurs PHP et SQL.</p>
<p class="small" style="color: #334B66;">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_vars"></a>
<h2>Class Variables</h2>
 
<hr>
<a name="class_methods"></a>
<h2>Class Methods</h2>
<a name="methodgetInstance"></a>
<p></p>
<h3>static getInstance</h3>
<div class="indent">
<p><code>static <a
href="../../eFlore/Debogage/GestionnaireErreur.html">GestionnaireErreur</a>
getInstance( )</code></p>
 
<p class="linenumber">[line 112]</p>
<p align="center"><strong>Fonction d'accès au singleton </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - le gestionnaire d'erreurs courant</li>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodretournerErreurSql"></a>
<p></p>
<h3>static retournerErreurSql</h3>
<div class="indent">
<p><code>static string retournerErreurSql( string $fichier,
int $methode, string $message, [string $requete = null], [string $autres
= null])</code></p>
 
<p class="linenumber">[line 323]</p>
<p align="center"><strong>Retourne l'erreur SQL formatée en
XHTML. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$fichier</b> - fichier</li>
<li><span class="type">int</span> <b>$methode</b> - ligne</li>
<li><span class="type">string</span> <b>$message</b> - message</li>
<li><span class="type">string</span> <b>$requete</b> - requete</li>
<li><span class="type">string</span> <b>$autres</b> - autres</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
 
<a name="methodgererErreur"></a>
<p></p>
<h3>gererErreur</h3>
<div class="indent">
<p><code>void gererErreur( int $niveau, string $message,
string $fichier, int $ligne, boolean $contexte)</code></p>
 
<p class="linenumber">[line 209]</p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">int</span> <b>$niveau</b> - niveau</li>
<li><span class="type">string</span> <b>$message</b> - message</li>
<li><span class="type">string</span> <b>$fichier</b> - fichier</li>
<li><span class="type">int</span> <b>$ligne</b> - ligne</li>
<li><span class="type">boolean</span> <b>$contexte</b> - contexte</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetContexte"></a>
<p></p>
<h3>getContexte</h3>
<div class="indent">
<p><code>boolean getContexte( )</code></p>
 
<p class="linenumber">[line 149]</p>
<p align="center"><strong>Récupère la valeur du contexte. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetErreur"></a>
<p></p>
<h3>getErreur</h3>
<div class="indent">
<p><code>array getErreur( )</code></p>
 
<p class="linenumber">[line 128]</p>
<p align="center"><strong>Récupère le tableau des erreurs.
</strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetNiveauErreurCourant"></a>
<p></p>
<h3>getNiveauErreurCourant</h3>
<div class="indent">
<p><code>int getNiveauErreurCourant( )</code></p>
 
<p class="linenumber">[line 170]</p>
<p align="center"><strong>Récupère le niveau d'erreur
courrant. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - le niveau d'erreur courrant.</li>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodretournerErreur"></a>
<p></p>
<h3>retournerErreur</h3>
<div class="indent">
<p><code>string retournerErreur( )</code></p>
 
<p class="linenumber">[line 252]</p>
<p align="center"><strong>Retourne l'erreur PHP formatée en
XHTML. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetActive"></a>
<p></p>
<h3>setActive</h3>
<div class="indent">
<p><code>void setActive( int $niveau)</code></p>
 
<p class="linenumber">[line 192]</p>
<p align="center"><strong>Définit le niveau d'erreur
courrant (synonyme fonction precedente) </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">int</span> <b>$niveau</b> - un niveau
d'erreur.</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetContexte"></a>
<p></p>
<h3>setContexte</h3>
<div class="indent">
<p><code>void setContexte( boolean $un_contexte)</code></p>
 
<p class="linenumber">[line 160]</p>
<p align="center"><strong>Définit si oui ou non le contexte
sera affiché. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">boolean</span> <b>$un_contexte</b> -
un_contexte</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetErreur"></a>
<p></p>
<h3>setErreur</h3>
<div class="indent">
<p><code>void setErreur( array $une_erreur)</code></p>
 
<p class="linenumber">[line 139]</p>
<p align="center"><strong>Ajoute une erreur à la liste. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">array</span> <b>$une_erreur</b> -
une_erreur</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetNiveauErreurCourant"></a>
<p></p>
<h3>setNiveauErreurCourant</h3>
<div class="indent">
<p><code>void setNiveauErreurCourant( [int $niveau = 2048])</code></p>
 
<p class="linenumber">[line 181]</p>
<p align="center"><strong>Définit le niveau d'erreur
courrant. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">int</span> <b>$niveau</b> - un niveau
d'erreur.</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_consts"></a>
<h2>Class Constants</h2>
</div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/classtrees_default.html
New file
0,0 → 1,91
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Class Trees for Package default</title>
<link rel="stylesheet" type="text/css" id="layout"
href="media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="classtrees_default.html">Class
Tree: default</a> ] [ <a href="elementindex_default.html">Index: default</a>
] [ <a href="elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="li_default.html">default</a></p>
<p><a href="li_eFlore.html">eFlore</a></p>
</div>
 
</div>
 
<div id="body">
<h1>Class Trees for Package default</h1>
<hr />
<div class="classtree">Root class Controleur</div>
<br />
<ul>
<li><a href="default/Controleur.html">Controleur</a>
<ul>
<li><a href="default/AdminAdministrateur.html">AdminAdministrateur</a></li>
</ul>
</li>
</ul>
 
<hr />
<div class="classtree">Root class GestionnaireException</div>
<br />
<ul>
<li><a href="default/GestionnaireException.html">GestionnaireException</a></li>
</ul>
 
<hr />
<div class="classtree">Root class Modele</div>
<br />
<ul>
<li><a href="default/Modele.html">Modele</a>
<ul>
<li><a href="default/listeAdmin.html">listeAdmin</a></li>
</ul>
</li>
</ul>
 
<hr />
<div class="classtree">Root class Net_URL</div>
<br />
<ul>
<li><a href="default/Net_URL.html">Net_URL</a></li>
</ul>
 
<hr />
<div class="classtree">Root class Net_URL2</div>
<br />
<ul>
<li><a href="default/Net_URL2.html">Net_URL2</a></li>
</ul>
 
<hr />
<div class="classtree">Root class Registre</div>
<br />
<ul>
<li><a href="default/Registre.html">Registre</a></li>
</ul>
 
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/errors.html
New file
0,0 → 1,175
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>phpDocumentor Parser Errors and Warnings</title>
<link rel="stylesheet" type="text/css" id="layout"
href="media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="classtrees_default.html">Class
Tree: default</a> ] [ <a href="elementindex_default.html">Index: default</a>
] [ <a href="elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="li_default.html">default</a></p>
<p><a href="li_eFlore.html">eFlore</a></p>
</div>
 
</div>
 
<div id="body"><a href="#Post-parsing">Post-parsing</a><br>
<a href="#admin_administrateur.php">admin_administrateur.php</a><br>
<a href="#autoload.inc.php">autoload.inc.php</a><br>
<a href="#Chronometre.php">Chronometre.php</a><br>
<a href="#config.inc.php">config.inc.php</a><br>
<a href="#config_chemin.inc.php">config_chemin.inc.php</a><br>
<a href="#Controleur.php">Controleur.php</a><br>
<a href="#GestionnaireErreur.php">GestionnaireErreur.php</a><br>
<a href="#GestionnaireException.php">GestionnaireException.php</a><br>
<a href="#index.php">index.php</a><br>
<a href="#ListeAdmin.php">ListeAdmin.php</a><br>
<a href="#Modele.php">Modele.php</a><br>
<a href="#Net_URL.php">Net_URL.php</a><br>
<a href="#Net_URL2.php">Net_URL2.php</a><br>
<a href="#Registre.php">Registre.php</a><br>
<a name="AdminAdministrateur.php"></a>
<h1>AdminAdministrateur.php</h1>
<h2>Warnings:</h2>
<br>
<b>Warning on line 5</b> - no @package tag was used in a DocBlock for
class AdminAdministrateur<br>
<b>Warning on line 36</b> - Unknown tag "@id" used<br>
<b>Warning on line 195</b> - File
"/home/aurelien/web/framework/controleurs/AdminAdministrateur.php" has
no page-level DocBlock, use @package in the first DocBlock to create one<br>
<a name="admin_administrateur.php"></a>
<h1>admin_administrateur.php</h1>
<h2>Warnings:</h2>
<br>
<b>Warning on line 98</b> - File
"/home/aurelien/web/framework/admin_administrateur.php" has no
page-level DocBlock, use @package in the first DocBlock to create one<br>
<a name="autoload.inc.php"></a>
<h1>autoload.inc.php</h1>
<h2>Warnings:</h2>
<br>
<b>Warning on line 37</b> - File
"/home/aurelien/web/framework/autoload.inc.php" has no page-level
DocBlock, use @package in the first DocBlock to create one<br>
<a name="Chronometre.php"></a>
<h1>Chronometre.php</h1>
<h2>Warnings:</h2>
<br>
<b>Warning on line 57</b> - no @package tag was used in a DocBlock for
class Chronometre<br>
<a name="config.inc.php"></a>
<h1>config.inc.php</h1>
<h2>Warnings:</h2>
<br>
<b>Warning on line 36</b> - File
"/home/aurelien/web/framework/configuration/config.inc.php" has no
page-level DocBlock, use @package in the first DocBlock to create one<br>
<a name="config_chemin.inc.php"></a>
<h1>config_chemin.inc.php</h1>
<h2>Warnings:</h2>
<br>
<b>Warning on line 10</b> - File
"/home/aurelien/web/framework/configuration/config_chemin.inc.php" has
no page-level DocBlock, use @package in the first DocBlock to create one<br>
<a name="Controleur.php"></a>
<h1>Controleur.php</h1>
<h2>Warnings:</h2>
<br>
<b>Warning on line 6</b> - no @package tag was used in a DocBlock for
class Controleur<br>
<b>Warning on line 108</b> - File
"/home/aurelien/web/framework/bibliotheque/Controleur.php" has no
page-level DocBlock, use @package in the first DocBlock to create one<br>
<a name="GestionnaireErreur.php"></a>
<h1>GestionnaireErreur.php</h1>
<h2>Warnings:</h2>
<br>
<b>Warning on line 56</b> - no @package tag was used in a DocBlock for
class GestionnaireErreur<br>
<a name="GestionnaireException.php"></a>
<h1>GestionnaireException.php</h1>
<h2>Warnings:</h2>
<br>
<b>Warning on line 11</b> - no @package tag was used in a DocBlock for
class GestionnaireException<br>
<b>Warning on line 121</b> - File
"/home/aurelien/web/framework/bibliotheque/GestionnaireException.php"
has no page-level DocBlock, use @package in the first DocBlock to create
one<br>
<a name="index.php"></a>
<h1>index.php</h1>
<h2>Warnings:</h2>
<br>
<b>Warning on line 8</b> - File "/home/aurelien/web/framework/index.php"
has no page-level DocBlock, use @package in the first DocBlock to create
one<br>
<a name="ListeAdmin.php"></a>
<h1>ListeAdmin.php</h1>
<h2>Warnings:</h2>
<br>
<b>Warning on line 6</b> - no @package tag was used in a DocBlock for
class listeAdmin<br>
<b>Warning on line 249</b> - File
"/home/aurelien/web/framework/modeles/ListeAdmin.php" has no page-level
DocBlock, use @package in the first DocBlock to create one<br>
<a name="Modele.php"></a>
<h1>Modele.php</h1>
<h2>Warnings:</h2>
<br>
<b>Warning on line 7</b> - no @package tag was used in a DocBlock for
class Modele<br>
<b>Warning on line 121</b> - File
"/home/aurelien/web/framework/bibliotheque/Modele.php" has no page-level
DocBlock, use @package in the first DocBlock to create one<br>
<a name="Net_URL.php"></a>
<h1>Net_URL.php</h1>
<h2>Warnings:</h2>
<br>
<b>Warning on line 40</b> - no @package tag was used in a DocBlock for
class Net_URL<br>
<b>Warning on line 489</b> - File
"/home/aurelien/web/framework/bibliotheque/Net_URL.php" has no
page-level DocBlock, use @package in the first DocBlock to create one<br>
<a name="Net_URL2.php"></a>
<h1>Net_URL2.php</h1>
<h2>Warnings:</h2>
<br>
<b>Warning on line 43</b> - no @package tag was used in a DocBlock for
class Net_URL2<br>
<b>Warning on line 816</b> - File
"/home/aurelien/web/framework/bibliotheque/Net_URL2.php" has no
page-level DocBlock, use @package in the first DocBlock to create one<br>
<a name="Registre.php"></a>
<h1>Registre.php</h1>
<h2>Warnings:</h2>
<br>
<b>Warning on line 5</b> - no @package tag was used in a DocBlock for
class Registre<br>
<b>Warning on line 87</b> - File
"/home/aurelien/web/framework/bibliotheque/Registre.php" has no
page-level DocBlock, use @package in the first DocBlock to create one<br>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/media/layout.cs
New file
0,0 → 1,81
#header {
z-index: 100;
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 5%;
}
#nav {
z-index: 200;
position: absolute;
top: 5%;
left: 0px;
width: 15%;
height: 1600px;
clip: auto;
overflow: auto;
}
#body {
position: absolute;
top: 6%;
left: 17%;
width: 82%;
}
#content {
clear: both;
top: -1px;
}
#packagePosition {
position: absolute;
right: 5px;
top: 0px;
width: 35%;
height: 100%;
}
#packageTitle {
position: absolute;
right: 0px;
}
#packageTitle2 {
position: absolute;
right: -3px;
top: -2px;
}
#elementPath {
position: absolute;
right: 0px;
bottom: 0px;
}
#navLinks {
position: absolute;
top: 0px;
left: 10px;
height: 100%;
 
}
.leftCol {
width: auto;
float: left;
}
.middleCol {
width: auto;
float: left;
}
.rightCol {
width: auto;
float: left;
}
#credit {
margin-top: 20px;
margin-bottom: 50px;
}
 
/** Fixed layout for nav on mozilla */
head:first-child+body div#header {
position: fixed;
}
head:first-child+body div#nav {
position: fixed;
height: 94%
}
/trunk/doc/media/style.cs
New file
0,0 → 1,236
BODY {
background: #FFFFFF;
font-family: Arial;
margin: 0px;
padding: 0px;
}
A {
color: #CC4400;
font-weight: bold;
}
A:Hover {
color: white;
background-color: #334B66;
font-weight: bold;
text-decoration: none;
}
#packageTitle {
font-size: 160%;
font-weight: bold;
text-align: right;
color: #CC6633;
}
#packageTitle2 {
font-size: 160%;
font-weight: bold;
text-align: right;
color: #334B66;
background-color: #6699CC;
}
#packageLinks {
background-color: #6699CC;
}
#header {
background-color: #6699CC;
border-bottom: solid #334B66 4px;
}
#nav {
background-color: #6699CC;
padding: 4px;
border-right: solid #334B66 4px;
}
#index {
padding: 18px;
}
hr {
width: 80%;
background-color: #6699CC;
color: #6699CC;
margin-top: 15px;
margin-bottom: 15px;
clear: both;
}
.links {
text-align: left;
width: 98%;
margin: auto;
}
UL {
margin: 0px;
padding: 0px;
padding-left: 5px;
list-style-type: none;
}
li {
text-indent: -15px;
padding-bottom: 2px;
padding-left: 14px;
}
dd {
margin-bottom: .5em;
}
.small {
font-size: 80%;
}
h3 {
}
.middleCol {
margin-left: -1px;
border-right: dotted gray 1px;
border-left: dotted gray 1px;
padding: 5px;
}
.leftCol {
border-right: dotted gray 1px;
padding: 5px;
}
.rightCol {
margin-left: -1px;
border-left: dotted gray 1px;
padding: 5px;
}
#elementPath {
font-size: 14px;
font-weight: bold;
color: #334B66;
}
.constructor {
/*border: dashed #334B66 1px;*/
font-weight: bold;
}
#credit {
text-align: center;
color: #334B66;
font-weight: bold;
}
div.contents {
border: solid #334B66 1px;
padding: 3px;
margin-bottom: 5px;
clear: all;
}
H1 {
margin: 0px;
}
H2 {
margin: 0px;
margin-bottom: 2px;
}
H3 {
margin: 0px;
}
H4 {
margin: 0px;
}
#classTree {
padding: 0px;
margin: 0px;
}
div.indent {
margin-left: 15px;
}
.warning {
color: red;
background-color: #334B66;
font-weight: bold;
}
code {
font-family: fixed;
padding: 3px;
color: #334B66;
background-color: #dddddd;
}
.type {
color: #334B66;
}
.value {
color: #334B66;
border: dotted #334B66 1px;
}
.top {
color: #334B66;
border-bottom: dotted #334B66 1px;
padding-bottom: 4px;
}
.php-src, .php, .listing {
font-family: fixed;
padding: 3px;
color: #334B66;
background-color: #dddddd;
font-family: 'Courier New', Courier, monospace; font-weight: normal;
}
DIV#nav DL {
margin: 0px;
padding: 0px;
list-style-type: none;
}
div.classtree {
font-size: 130%;
font-weight: bold;
background-color: #CC6633;
border: dotted #334B66 2px;
}
span.linenumber,p.linenumber {
font-weight: bold,italic;
}
span.smalllinenumber {
font-weight: bold,italic;
font-size: 9pt;
}
ul {
margin-left: 0px;
padding-left: 8px;
}
/* Syntax highlighting */
 
.src-code { background-color: #f5f5f5; border: 1px solid #ccc9a4; padding: 0px; margin : 0px}
.src-line { font-family: 'Courier New', Courier, monospace; font-weight: normal; }
/*.src-code pre { }*/
 
.src-comm { color: green; }
.src-id { }
.src-inc { color: #0000FF; }
.src-key { color: #0000FF; }
.src-num { color: #CC0000; }
.src-str { color: #66cccc; }
.src-sym { font-weight: bold; }
.src-var { }
 
.src-php { font-weight: bold; }
 
.src-doc { color: #009999 }
.src-doc-close-template { color: #0000FF }
.src-doc-coretag { color: #0099FF; font-weight: bold }
.src-doc-inlinetag { color: #0099FF }
.src-doc-internal { color: #6699cc }
.src-doc-tag { color: #0080CC }
.src-doc-template { color: #0000FF }
.src-doc-type { font-style: italic }
.src-doc-var { font-style: italic }
 
.tute-tag { color: #009999 }
.tute-attribute-name { color: #0000FF }
.tute-attribute-value { color: #0099FF }
.tute-entity { font-weight: bold; }
.tute-comment { font-style: italic }
.tute-inline-tag { color: #636311; font-weight: bold }
 
/* tutorial */
 
.authors { }
.author { font-style: italic; font-weight: bold }
.author-blurb { margin: .5em 0em .5em 2em; font-size: 85%; font-weight: normal; font-style: normal }
.example { border: 1px dashed #999999; background-color: #EEEEEE; padding: .5em; }
.listing { border: 1px dashed #999999; background-color: #EEEEEE; padding: .5em; white-space: nowrap; }
.release-info { font-size: 85%; font-style: italic; margin: 1em 0em }
.ref-title-box { }
.ref-title { }
.ref-purpose { font-style: italic; color: #666666 }
.ref-synopsis { }
.title { font-weight: bold; margin: 1em 0em 0em 0em; padding: .25em;
border: 2px solid #CC6633; background-color: #6699CC }
.cmd-synopsis { margin: 1em 0em }
.cmd-title { font-weight: bold }
.toc { margin-left: 2em; padding-left: 0em }
 
/trunk/doc/media/print.cs
New file
0,0 → 1,25
BODY {
margin: 1em;
}
#header {
}
#nav {
display: none;
}
#packagePosition {
text-align: right;
}
#packageTitle {
display: inline;
margin: 5px;
}
#packageTitle2 {
display: none;
}
#elementPath {
display: inline;
margin: 5px;
}
#navLinks {
display: none;
}
/trunk/doc/elementindex_eFlore.html
New file
0,0 → 1,7
<br />
<b>Warning</b>
: Smarty error: unable to read resource: "pkgelementindex.tpl" in
<b>/home/aurelien/web/PhpDocumentor-1.4.2/phpDocumentor/Smarty-2.6.0/libs/Smarty.class.php</b>
on line
<b>1144</b>
<br />
/trunk/doc/li_eFlore.html
New file
0,0 → 1,63
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Generated Documentation</title>
<link rel="stylesheet" type="text/css" id="layout"
href="media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="classtrees_eFlore.html">Class
Tree: eFlore</a> ] [ <a href="elementindex_eFlore.html">Index: eFlore</a> ]
[ <a href="elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">eFlore</div>
<div id="packageTitle">eFlore</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="li_default.html">default</a></p>
<p><a href="li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
subpackage <b>Debogage</b><br>
<a href="eFlore/Debogage/_bibliotheque---Chronometre.php.html">
Chronometre.php </a><br>
<a href="eFlore/Debogage/_bibliotheque---GestionnaireErreur.php.html">
GestionnaireErreur.php </a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<b>Debogage</b><br>
<a href="eFlore/Debogage/Chronometre.html"> Chronometre </a><br>
<a href="eFlore/Debogage/GestionnaireErreur.html">
GestionnaireErreur </a><br>
</div>
</div>
</div>
 
<div id="body">
<div align="center">
<h1>Generated Documentation</h1>
</div>
<b>Welcome to eFlore!</b><br />
<br />
This documentation was generated by <a href="http://www.phpdoc.org">phpDocumentor
v1.4.1</a><br />
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/_bibliotheque---Net_URL2.php.html
New file
0,0 → 1,100
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs for page Net_URL2.php</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Procedural File: Net_URL2.php</h1>
<p style="margin: 0px;">Source Location: /bibliotheque/Net_URL2.php</p>
 
<br>
<br>
 
<div class="contents">
<h2>Classes:</h2>
<dl>
<dt><a href="../default/Net_URL2.html">Net_URL2</a></dt>
<dd></dd>
</dl>
</div>
 
<h2>Page Details:</h2>
<hr>
<hr>
<div id="global"></div>
<hr>
<div id="define"></div>
<hr>
<div id="function"></div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/_configuration---config_chemin.inc.php.html
New file
0,0 → 1,135
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs for page config_chemin.inc.php</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Procedural File: config_chemin.inc.php</h1>
<p style="margin: 0px;">Source Location:
/configuration/config_chemin.inc.php</p>
 
<br>
<br>
 
<div class="contents">
<h2>Classes:</h2>
<dl>
</dl>
</div>
 
<h2>Page Details:</h2>
<hr>
<hr>
<div id="global"></div>
<hr>
<div id="define"><a name="defineCHEMIN_BIBLIO"></a>
<h3>CHEMIN_BIBLIO</h3>
<div class="indent">
<p class="linenumber">[line 4]</p>
<p><code>CHEMIN_BIBLIO = CHEMIN_APPLI.'bibliotheque'</code></p>
<p align="center"><strong>Constante stockant le chemin vers
le dossier bibliothèque, contenant les classes systèmes * </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="defineDOSSIER_CONTROLEURS"></a>
<h3>DOSSIER_CONTROLEURS</h3>
<div class="indent">
<p class="linenumber">[line 6]</p>
<p><code>DOSSIER_CONTROLEURS = CHEMIN_APPLI.'controleurs'</code></p>
<p align="center"><strong>Constante stockant le chemin vers
le dossier controleurs. </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="defineDOSSIER_MODELES"></a>
<h3>DOSSIER_MODELES</h3>
<div class="indent">
<p class="linenumber">[line 8]</p>
<p><code>DOSSIER_MODELES = CHEMIN_APPLI.'modeles'</code></p>
<p align="center"><strong>Constante stockant le chemin vers
le dossier modèles. </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="defineDOSSIER_SQUELETTES"></a>
<h3>DOSSIER_SQUELETTES</h3>
<div class="indent">
<p class="linenumber">[line 10]</p>
<p><code>DOSSIER_SQUELETTES = CHEMIN_APPLI.'squelettes'</code></p>
<p align="center"><strong>Constante stockant le chemin vers
le dossier squelettes. </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
</div>
<hr>
<div id="function"></div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/Registre.html
New file
0,0 → 1,260
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs For Class Registre</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Class: Registre</h1>
<p style="margin: 0px;">Source Location: /bibliotheque/Registre.php</p>
 
 
<div class="leftcol">
<h3><a href="#class_details">Class Overview</a> <span
class="smalllinenumber">[line 6]</span></h3>
<div id="classTree"><pre></pre></div>
<div class="small">
<p>Classe registre, qui permet un accès à différentes variables à
travers les autres classes.</p>
<h4>Author(s):</h4>
<ul>
</ul>
<h4>Version:</h4>
<ul>
</ul>
 
<h4>Copyright:</h4>
<ul>
</li>
</div>
</div>
 
<div class="middlecol">
<h3><a href="#class_vars">Variables</a></h3>
<ul class="small">
</ul>
<h3><a href="#class_consts">Constants</a></h3>
<ul class="small">
</ul>
</div>
<div class="rightcol">
<h3><a href="#class_methods">Methods</a></h3>
<ul class="small">
<li><a href="../default/Registre.html#methoddetruire">detruire</a></li>
<li><a href="../default/Registre.html#methodetrePresent">etrePresent</a></li>
<li><a href="../default/Registre.html#methodget">get</a></li>
<li><a href="../default/Registre.html#methodgetInstance">getInstance</a></li>
<li><a href="../default/Registre.html#methodset">set</a></li>
</ul>
</div>
 
<div id="content">
<hr>
<div class="contents"></div>
 
<div class="leftCol">
<h2>Inherited Variables</h2>
<h2>Inherited Constants</h2>
</div>
 
<div class="rightCol">
<h2>Inherited Methods</h2>
</div>
<br clear="all">
<hr>
 
<a name="class_details"></a>
<h2>Class Details</h2>
<p align="center"><strong>Classe registre, qui permet un
accès à différentes variables à travers les autres classes. </strong></p>
<p>C'est un singleton</p>
<p class="small" style="color: #334B66;">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_vars"></a>
<h2>Class Variables</h2>
 
<hr>
<a name="class_methods"></a>
<h2>Class Methods</h2>
<a name="methodgetInstance"></a>
<p></p>
<h3>static getInstance</h3>
<div class="indent">
<p><code>static void getInstance( )</code></p>
 
<p class="linenumber">[line 29]</p>
<p align="center"><strong>Fonction qui renvoie l'instance
de classe en assurant son unicité, c'est l'unique méthode qui doit être
</strong></p>
<p>utilisé pour récupérer l'objet Registre</p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
 
<a name="methoddetruire"></a>
<p></p>
<h3>detruire</h3>
<div class="indent">
<p><code>void detruire( $intitule)</code></p>
 
<p class="linenumber">[line 69]</p>
<p align="center"><strong>Détruit l'objet associé à
l'intitulé, n'a pas d'effet si il n'y a pas d'objet associé </strong></p>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type"></span> <b>$intitule</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodetrePresent"></a>
<p></p>
<h3>etrePresent</h3>
<div class="indent">
<p><code>boolean etrePresent( $intitule)</code></p>
 
<p class="linenumber">[line 80]</p>
<p align="center"><strong>Teste si un objet est présent
sous un intitulé donné </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - true si un objet associé à cet intitulé est
présent, false sinon</li>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type"></span> <b>$intitule</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodget"></a>
<p></p>
<h3>get</h3>
<div class="indent">
<p><code>mixed get( $intitule)</code></p>
 
<p class="linenumber">[line 58]</p>
<p align="center"><strong>Renvoie l'objet associé à
l'intitulé donné en paramètre </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - l'objet associé à l'intitulé ou null s'il
n'est pas présent</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type"></span> <b>$intitule</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodset"></a>
<p></p>
<h3>set</h3>
<div class="indent">
<p><code>void set( string $intitule, mixed $objet)</code></p>
 
<p class="linenumber">[line 43]</p>
<p align="center"><strong>Ajoute un objet au tableau selon
un intitulé donné </strong></p>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$intitule</b> - l'intitulé
sous lequel l'objet sera conservé</li>
<li><span class="type">mixed</span> <b>$objet</b> - l'objet à
conserver</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_consts"></a>
<h2>Class Constants</h2>
</div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/_bibliotheque---Controleur.php.html
New file
0,0 → 1,103
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs for page Controleur.php</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Procedural File: Controleur.php</h1>
<p style="margin: 0px;">Source Location:
/bibliotheque/Controleur.php</p>
 
<br>
<br>
 
<div class="contents">
<h2>Classes:</h2>
<dl>
<dt><a href="../default/Controleur.html">Controleur</a></dt>
<dd>Classe controlleur, coeur d'une application, c'est normalement
la seule classe d'une application qui devrait être appelée de
l'extérieur.</dd>
</dl>
</div>
 
<h2>Page Details:</h2>
<hr>
<hr>
<div id="global"></div>
<hr>
<div id="define"></div>
<hr>
<div id="function"></div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/_admin_administrateur.php.html
New file
0,0 → 1,137
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs for page admin_administrateur.php</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Procedural File: admin_administrateur.php</h1>
<p style="margin: 0px;">Source Location: /admin_administrateur.php</p>
 
<br>
<br>
 
<div class="contents">
<h2>Classes:</h2>
<dl>
</dl>
</div>
 
<h2>Page Details:</h2>
<hr>
Includes:<br>
require_once(<a href="../default/_autoload.inc.php.html">'autoload.inc.php'</a>)
<span class="linenumber">[line 8]</span> <br />
<p align="center"><strong>Ceci est un exemple d'application
qui permet d'illustrer le fonctionnement du framework, il montre comment
une application </strong></p>
<p>peut être dans papyrus, ou bien utilisée en stand alone</p>
<hr>
<div id="global"></div>
<hr>
<div id="define"></div>
<hr>
<div id="function"><a name="functionafficherContenuCorps"></a>
<h3>afficherContenuCorps</h3>
<div class="indent"><code>void afficherContenuCorps( )</code>
<p class="linenumber">[line 13]</p>
<p align="center"><strong>Fonction d'affichage de Papyrus,
pour le corps de page </strong></p>
 
<h4>Parameters</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="functionafficherContenuPied"></a>
<h3>afficherContenuPied</h3>
<div class="indent"><code>void afficherContenuPied( )</code>
<p class="linenumber">[line 79]</p>
 
<h4>Parameters</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="functionafficherContenuTete"></a>
<h3>afficherContenuTete</h3>
<div class="indent"><code>void afficherContenuTete( )</code>
<p class="linenumber">[line 74]</p>
 
<h4>Parameters</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
</div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/listeAdmin.html
New file
0,0 → 1,347
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs For Class listeAdmin</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Class: listeAdmin</h1>
<p style="margin: 0px;">Source Location: /modeles/ListeAdmin.php</p>
 
 
<div class="leftcol">
<h3><a href="#class_details">Class Overview</a> <span
class="smalllinenumber">[line 7]</span></h3>
<div id="classTree"><pre><a href="../default/Modele.html">Modele</a>
|
--listeAdmin</pre></div>
<div class="small">
<p>Modèle d'accès à la base de données des administrateurs</p>
<h4>Author(s):</h4>
<ul>
</ul>
<h4>Version:</h4>
<ul>
</ul>
 
<h4>Copyright:</h4>
<ul>
</li>
</div>
</div>
 
<div class="middlecol">
<h3><a href="#class_vars">Variables</a></h3>
<ul class="small">
<li><a href="../default/listeAdmin.html#var$config">$config</a></li>
</ul>
<h3><a href="#class_consts">Constants</a></h3>
<ul class="small">
</ul>
</div>
<div class="rightcol">
<h3><a href="#class_methods">Methods</a></h3>
<ul class="small">
<li><a href="../default/listeAdmin.html#methodajoutAdmin">ajoutAdmin</a></li>
<li><a href="../default/listeAdmin.html#methodchargerAdmin">chargerAdmin</a></li>
<li><a href="../default/listeAdmin.html#methodloadDetailsAdmin">loadDetailsAdmin</a></li>
<li><a href="../default/listeAdmin.html#methodmodifDetailsAdmin">modifDetailsAdmin</a></li>
<li><a href="../default/listeAdmin.html#methodsuppAdmin">suppAdmin</a></li>
<li><a href="../default/listeAdmin.html#methodvaliderMail">validerMail</a></li>
</ul>
</div>
 
<div id="content">
<hr>
<div class="contents"></div>
 
<div class="leftCol">
<h2>Inherited Variables</h2>
<h2>Inherited Constants</h2>
</div>
 
<div class="rightCol">
<h2>Inherited Methods</h2>
<div class="indent">
<h3>Class: <a href="../default/Modele.html">Modele</a></h3>
<dl class="small">
<dt><a href="../default/Modele.html#method__construct">Modele::__construct()</a>
</dt>
<dd>Constructeur par défaut, appelé à l'initialisation</dd>
<dt><a href="../default/Modele.html#methodproteger">Modele::proteger()</a>
</dt>
<dd>protège une chaine de caractères avant l'insertion dans la
base de données</dd>
<dt><a href="../default/Modele.html#methodrequete">Modele::requete()</a>
</dt>
<dd>Fonction qui appelle la bonne fonction de requete suivant le
type de bdd</dd>
<dt><a href="../default/Modele.html#method__destruct">Modele::__destruct()</a>
</dt>
<dd>Destructeur de classe, se contente de fermer explicitement la
connexion</dd>
</dl>
</div>
</div>
<br clear="all">
<hr>
 
<a name="class_details"></a>
<h2>Class Details</h2>
<p align="center"><strong>Modèle d'accès à la base de
données des administrateurs </strong></p>
<p>de papyrus</p>
<p class="small" style="color: #334B66;">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_vars"></a>
<h2>Class Variables</h2>
<a name="var$config"></a>
<p></p>
<h4>$config = <span class="value">array()</span></h4>
<div class="indent">
<p class="linenumber">[line 9]</p>
<p><b>Type:</b> mixed</p>
<p><b>Overrides:</b></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_methods"></a>
<h2>Class Methods</h2>
 
<a name="methodajoutAdmin"></a>
<p></p>
<h3>ajoutAdmin</h3>
<div class="indent">
<p><code>array ajoutAdmin( string $nom, string $prenom,
string $mail, string $lang, string $pass, string $pass_conf)</code></p>
 
<p class="linenumber">[line 160]</p>
<p align="center"><strong>Ajoute un administrateur dans la
base de données </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - un tableau contenant les erreurs s'il y en a,
vide sinon</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$nom</b> - nom</li>
<li><span class="type">string</span> <b>$prenom</b> - prenom</li>
<li><span class="type">string</span> <b>$mail</b> - le mail</li>
<li><span class="type">string</span> <b>$lang</b> - le code de
langue</li>
<li><span class="type">string</span> <b>$pass</b> - le mot de
passe</li>
<li><span class="type">string</span> <b>$pass_conf</b> - la
confirmation du mot de passe</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodchargerAdmin"></a>
<p></p>
<h3>chargerAdmin</h3>
<div class="indent">
<p><code>array chargerAdmin( )</code></p>
 
<p class="linenumber">[line 16]</p>
<p align="center"><strong>Charge la liste complète des
administrateurs </strong></p>
<p>return array un tableau contenant des objets d'informations sur
les administrateurs</p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - un tableau d'objets contenant la liste des
administrateurs</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodloadDetailsAdmin"></a>
<p></p>
<h3>loadDetailsAdmin</h3>
<div class="indent">
<p><code>object un loadDetailsAdmin( int $id)</code></p>
 
<p class="linenumber">[line 37]</p>
<p align="center"><strong>Charge les informations liées à
un administrateur </strong></p>
<p>grâce à son id</p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - object contenant les informations de
l'administrateur demandé</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">int</span> <b>$id</b> - l'identifiant de
l'administrateur.</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodmodifDetailsAdmin"></a>
<p></p>
<h3>modifDetailsAdmin</h3>
<div class="indent">
<p><code>array modifDetailsAdmin( int $id, string $nom,
string $prenom, string $mail, string $lang, [string $pass = ''], [string
$pass_conf = ''])</code></p>
 
<p class="linenumber">[line 62]</p>
<p align="center"><strong>Modifie les informations liées à
un administrateur dans la base de données </strong></p>
<p>Si le mot de passe n'est pas renseigné, il n'est pas changé</p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - un tableau contenant les erreurs s'il y en a,
vide sinon</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">int</span> <b>$id</b> - identifiant de
l'admiistrateur</li>
<li><span class="type">string</span> <b>$nom</b> - nom</li>
<li><span class="type">string</span> <b>$prenom</b> - prenom</li>
<li><span class="type">string</span> <b>$mail</b> - le mail</li>
<li><span class="type">string</span> <b>$lang</b> - le code de
langue</li>
<li><span class="type">string</span> <b>$pass</b> - le mot de
passe (optionnel)</li>
<li><span class="type">string</span> <b>$pass_conf</b> - la
confirmation du mot de passe (optionnel)</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsuppAdmin"></a>
<p></p>
<h3>suppAdmin</h3>
<div class="indent">
<p><code>array suppAdmin( int $id)</code></p>
 
<p class="linenumber">[line 121]</p>
<p align="center"><strong>Supprime un administrateur ayant
un id donnée </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - un tableau contenant les erreurs s'il y en a,
vide sinon</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">int</span> <b>$id</b> - l'identifiant de
l'administrateur</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodvaliderMail"></a>
<p></p>
<h3>validerMail</h3>
<div class="indent">
<p><code>bool validerMail( string $mail)</code></p>
 
<p class="linenumber">[line 226]</p>
<p align="center"><strong>Fonction qui prend une chaine en
paramètre et renvoie vrai si elle constitue un email syntaxiquement
valide, faux sinon. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - true si le mail est valide, false sinon</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$mail</b> - le mail à
valider</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_consts"></a>
<h2>Class Constants</h2>
</div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/Net_URL2.html
New file
0,0 → 1,940
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs For Class Net_URL2</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Class: Net_URL2</h1>
<p style="margin: 0px;">Source Location: /bibliotheque/Net_URL2.php</p>
 
 
<div class="leftcol">
<h3><a href="#class_details">Class Overview</a> <span
class="smalllinenumber">[line 43]</span></h3>
<div id="classTree"><pre></pre></div>
<div class="small">
<p></p>
<h4>Author(s):</h4>
<ul>
</ul>
<h4>Version:</h4>
<ul>
</ul>
 
<h4>Copyright:</h4>
<ul>
</li>
</div>
</div>
 
<div class="middlecol">
<h3><a href="#class_vars">Variables</a></h3>
<ul class="small">
</ul>
<h3><a href="#class_consts">Constants</a></h3>
<ul class="small">
<li><a href="../default/Net_URL2.html#constOPTION_ENCODE_KEYS">OPTION_ENCODE_KEYS</a></li>
<li><a href="../default/Net_URL2.html#constOPTION_SEPARATOR_INPUT">OPTION_SEPARATOR_INPUT</a></li>
<li><a
href="../default/Net_URL2.html#constOPTION_SEPARATOR_OUTPUT">OPTION_SEPARATOR_OUTPUT</a></li>
<li><a href="../default/Net_URL2.html#constOPTION_STRICT">OPTION_STRICT</a></li>
<li><a href="../default/Net_URL2.html#constOPTION_USE_BRACKETS">OPTION_USE_BRACKETS</a></li>
</ul>
</div>
<div class="rightcol">
<h3><a href="#class_methods">Methods</a></h3>
<ul class="small">
<li><a href="../default/Net_URL2.html#method__construct">__construct</a></li>
<li><a href="../default/Net_URL2.html#methodgetAuthority">getAuthority</a></li>
<li><a href="../default/Net_URL2.html#methodgetCanonical">getCanonical</a></li>
<li><a href="../default/Net_URL2.html#methodgetFragment">getFragment</a></li>
<li><a href="../default/Net_URL2.html#methodgetHost">getHost</a></li>
<li><a href="../default/Net_URL2.html#methodgetNormalizedURL">getNormalizedURL</a></li>
<li><a href="../default/Net_URL2.html#methodgetOption">getOption</a></li>
<li><a href="../default/Net_URL2.html#methodgetPassword">getPassword</a></li>
<li><a href="../default/Net_URL2.html#methodgetPath">getPath</a></li>
<li><a href="../default/Net_URL2.html#methodgetPort">getPort</a></li>
<li><a href="../default/Net_URL2.html#methodgetQuery">getQuery</a></li>
<li><a href="../default/Net_URL2.html#methodgetQueryVariables">getQueryVariables</a></li>
<li><a href="../default/Net_URL2.html#methodgetRequested">getRequested</a></li>
<li><a href="../default/Net_URL2.html#methodgetRequestedURL">getRequestedURL</a></li>
<li><a href="../default/Net_URL2.html#methodgetScheme">getScheme</a></li>
<li><a href="../default/Net_URL2.html#methodgetURL">getURL</a></li>
<li><a href="../default/Net_URL2.html#methodgetUser">getUser</a></li>
<li><a href="../default/Net_URL2.html#methodgetUserinfo">getUserinfo</a></li>
<li><a href="../default/Net_URL2.html#methodisAbsolute">isAbsolute</a></li>
<li><a href="../default/Net_URL2.html#methodnormalize">normalize</a></li>
<li><a href="../default/Net_URL2.html#methodresolve">resolve</a></li>
<li><a href="../default/Net_URL2.html#methodsetAuthority">setAuthority</a></li>
<li><a href="../default/Net_URL2.html#methodsetFragment">setFragment</a></li>
<li><a href="../default/Net_URL2.html#methodsetHost">setHost</a></li>
<li><a href="../default/Net_URL2.html#methodsetOption">setOption</a></li>
<li><a href="../default/Net_URL2.html#methodsetPath">setPath</a></li>
<li><a href="../default/Net_URL2.html#methodsetPort">setPort</a></li>
<li><a href="../default/Net_URL2.html#methodsetQuery">setQuery</a></li>
<li><a href="../default/Net_URL2.html#methodsetQueryVariable">setQueryVariable</a></li>
<li><a href="../default/Net_URL2.html#methodsetQueryVariables">setQueryVariables</a></li>
<li><a href="../default/Net_URL2.html#methodsetScheme">setScheme</a></li>
<li><a href="../default/Net_URL2.html#methodsetUserinfo">setUserinfo</a></li>
<li><a href="../default/Net_URL2.html#methodunsetQueryVariable">unsetQueryVariable</a></li>
<li><a href="../default/Net_URL2.html#method__toString">__toString</a></li>
</ul>
</div>
 
<div id="content">
<hr>
<div class="contents"></div>
 
<div class="leftCol">
<h2>Inherited Variables</h2>
<h2>Inherited Constants</h2>
</div>
 
<div class="rightCol">
<h2>Inherited Methods</h2>
</div>
<br clear="all">
<hr>
 
<a name="class_details"></a>
<h2>Class Details</h2>
<h4>Tags:</h4>
<ul>
<li><b>license</b> - BSD</li>
</ul>
<p class="small" style="color: #334B66;">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_vars"></a>
<h2>Class Variables</h2>
 
<hr>
<a name="class_methods"></a>
<h2>Class Methods</h2>
<a name="methodgetCanonical"></a>
<p></p>
<h3>static getCanonical</h3>
<div class="indent">
<p><code>static string getCanonical( )</code></p>
 
<p class="linenumber">[line 731]</p>
<p align="center"><strong>Returns a Net_URL2 instance
representing the canonical URL of the currently executing PHP script. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetRequested"></a>
<p></p>
<h3>static getRequested</h3>
<div class="indent">
<p><code>static <a href="../default/Net_URL2.html">Net_URL2</a>
getRequested( )</code></p>
 
<p class="linenumber">[line 767]</p>
<p align="center"><strong>Returns a Net_URL2 instance
representing the URL used to retrieve the current request. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetRequestedURL"></a>
<p></p>
<h3>static getRequestedURL</h3>
<div class="indent">
<p><code>static string getRequestedURL( )</code></p>
 
<p class="linenumber">[line 756]</p>
<p align="center"><strong>Returns the URL used to retrieve
the current request. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
 
<a name="method__construct"></a>
<p></p>
<h3>__construct</h3>
<div class="indent">
<p><code>Net_URL2 __construct( string $url, [array $options =
null])</code></p>
 
<p class="linenumber">[line 125]</p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$url</b> - an absolute or
relative URL</li>
<li><span class="type">array</span> <b>$options</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetAuthority"></a>
<p></p>
<h3>getAuthority</h3>
<div class="indent">
<p><code>string|bool getAuthority( )</code></p>
 
<p class="linenumber">[line 283]</p>
<p align="center"><strong>Returns the authority part, i.e.
[ userinfo &quot;@&quot; ] host [ &quot;:&quot; port ], or false if
there is no authority none. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetFragment"></a>
<p></p>
<h3>getFragment</h3>
<div class="indent">
<p><code>string|bool getFragment( )</code></p>
 
<p class="linenumber">[line 375]</p>
<p align="center"><strong>Returns the fragment name, or
false if &quot;#&quot; isn't present in the URL. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetHost"></a>
<p></p>
<h3>getHost</h3>
<div class="indent">
<p><code>string|bool getHost( )</code></p>
 
<p class="linenumber">[line 241]</p>
<p align="center"><strong>Returns the host part, or false
if there is no authority part, e.g. </strong></p>
<p>relative URLs.</p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetNormalizedURL"></a>
<p></p>
<h3>getNormalizedURL</h3>
<div class="indent">
<p><code>string getNormalizedURL( )</code></p>
 
<p class="linenumber">[line 541]</p>
<p align="center"><strong>Returns a normalized string
representation of this URL. This is useful for comparison of URLs. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetOption"></a>
<p></p>
<h3>getOption</h3>
<div class="indent">
<p><code>mixed getOption( string $optionName)</code></p>
 
<p class="linenumber">[line 808]</p>
<p align="center"><strong>Returns the value of the
specified option. </strong></p>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$optionName</b> - The name
of the option to retrieve</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetPassword"></a>
<p></p>
<h3>getPassword</h3>
<div class="indent">
<p><code>string|bool getPassword( )</code></p>
 
<p class="linenumber">[line 202]</p>
<p align="center"><strong>Returns the password part of the
userinfo part (the part after the first &quot;:&quot;), or false if
there is no userinfo part (i.e. the URL does not contain &quot;@&quot;
in front of the hostname) or the userinfo part does not contain
&quot;:&quot;. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetPath"></a>
<p></p>
<h3>getPath</h3>
<div class="indent">
<p><code>string getPath( )</code></p>
 
<p class="linenumber">[line 332]</p>
<p align="center"><strong>Returns the path part (possibly
an empty string). </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetPort"></a>
<p></p>
<h3>getPort</h3>
<div class="indent">
<p><code>int|bool getPort( )</code></p>
 
<p class="linenumber">[line 262]</p>
<p align="center"><strong>Returns the port number, or false
if there is no port number specified, i.e. if the default port is to be
used. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetQuery"></a>
<p></p>
<h3>getQuery</h3>
<div class="indent">
<p><code>string|bool getQuery( )</code></p>
 
<p class="linenumber">[line 354]</p>
<p align="center"><strong>Returns the query string
(excluding the leading &quot;?&quot;), or false if &quot;?&quot; isn't
present in the URL. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>see</b> - self::getQueryVariables()</li>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetQueryVariables"></a>
<p></p>
<h3>getQueryVariables</h3>
<div class="indent">
<p><code>array getQueryVariables( )</code></p>
 
<p class="linenumber">[line 396]</p>
<p align="center"><strong>Returns the query string like an
array as the variables would appear in $_GET in a PHP script. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetScheme"></a>
<p></p>
<h3>getScheme</h3>
<div class="indent">
<p><code>string|bool getScheme( )</code></p>
 
<p class="linenumber">[line 167]</p>
<p align="center"><strong>Returns the scheme, e.g.
&quot;http&quot; or &quot;urn&quot;, or false if there is no scheme
specified, i.e. if this is a relative URL. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetURL"></a>
<p></p>
<h3>getURL</h3>
<div class="indent">
<p><code>string getURL( )</code></p>
 
<p class="linenumber">[line 509]</p>
<p align="center"><strong>Returns a string representation
of this URL. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetUser"></a>
<p></p>
<h3>getUser</h3>
<div class="indent">
<p><code>string|bool getUser( )</code></p>
 
<p class="linenumber">[line 189]</p>
<p align="center"><strong>Returns the user part of the
userinfo part (the part preceding the first &quot;:&quot;), or false if
there is no userinfo part. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetUserinfo"></a>
<p></p>
<h3>getUserinfo</h3>
<div class="indent">
<p><code>string|bool getUserinfo( )</code></p>
 
<p class="linenumber">[line 213]</p>
<p align="center"><strong>Returns the userinfo part, or
false if there is none, i.e. if the authority part does not contain
&quot;@&quot;. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodisAbsolute"></a>
<p></p>
<h3>isAbsolute</h3>
<div class="indent">
<p><code>bool isAbsolute( )</code></p>
 
<p class="linenumber">[line 596]</p>
<p align="center"><strong>Returns whether this instance
represents an absolute URL. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodnormalize"></a>
<p></p>
<h3>normalize</h3>
<div class="indent">
<p><code><a href="../default/Net_URL2.html">Net_URL2</a>
normalize( )</code></p>
 
<p class="linenumber">[line 553]</p>
<p align="center"><strong>Returns a normalized Net_URL2
instance. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodresolve"></a>
<p></p>
<h3>resolve</h3>
<div class="indent">
<p><code><a href="../default/Net_URL2.html">Net_URL2</a>
resolve( <a href="../default/Net_URL2.html">Net_URL2</a>|string
$reference)</code></p>
 
<p class="linenumber">[line 609]</p>
<p align="center"><strong>Returns an Net_URL2 instance
representing an absolute URL relative to this URL. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type"><a href="../default/Net_URL2.html">Net_URL2</a>|string</span>
<b>$reference</b> - relative URL</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetAuthority"></a>
<p></p>
<h3>setAuthority</h3>
<div class="indent">
<p><code>void setAuthority( string|false $authority)</code></p>
 
<p class="linenumber">[line 309]</p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string|false</span> <b>$authority</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetFragment"></a>
<p></p>
<h3>setFragment</h3>
<div class="indent">
<p><code>void setFragment( string|bool $fragment)</code></p>
 
<p class="linenumber">[line 385]</p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string|bool</span> <b>$fragment</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetHost"></a>
<p></p>
<h3>setHost</h3>
<div class="indent">
<p><code>void setHost( string|bool $host)</code></p>
 
<p class="linenumber">[line 251]</p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string|bool</span> <b>$host</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetOption"></a>
<p></p>
<h3>setOption</h3>
<div class="indent">
<p><code>void setOption( string $optionName, mixed $value)</code></p>
 
<p class="linenumber">[line 793]</p>
<p align="center"><strong>Sets the specified option. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>see</b> - self::OPTION_ENCODE_KEYS</li>
<li><b>see</b> - self::OPTION_USE_BRACKETS</li>
<li><b>see</b> - self::OPTION_STRICT</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$optionName</b> - a
self::OPTION_ constant</li>
<li><span class="type">mixed</span> <b>$value</b> - option value</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetPath"></a>
<p></p>
<h3>setPath</h3>
<div class="indent">
<p><code>void setPath( string $path)</code></p>
 
<p class="linenumber">[line 342]</p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$path</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetPort"></a>
<p></p>
<h3>setPort</h3>
<div class="indent">
<p><code>void setPort( int|bool $port)</code></p>
 
<p class="linenumber">[line 272]</p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">int|bool</span> <b>$port</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetQuery"></a>
<p></p>
<h3>setQuery</h3>
<div class="indent">
<p><code>void setQuery( string|bool $query)</code></p>
 
<p class="linenumber">[line 365]</p>
<h4>Tags:</h4>
<ul>
<li><b>see</b> - self::setQueryVariables()</li>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string|bool</span> <b>$query</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetQueryVariable"></a>
<p></p>
<h3>setQueryVariable</h3>
<div class="indent">
<p><code>array setQueryVariable( string $name, mixed $value)</code>
</p>
 
<p class="linenumber">[line 485]</p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$name</b> -</li>
<li><span class="type">mixed</span> <b>$value</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetQueryVariables"></a>
<p></p>
<h3>setQueryVariables</h3>
<div class="indent">
<p><code>void setQueryVariables( $array)</code></p>
 
<p class="linenumber">[line 452]</p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">array</span> <b>$array</b> - (name =&gt;
value) array</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetScheme"></a>
<p></p>
<h3>setScheme</h3>
<div class="indent">
<p><code>void setScheme( string|bool $scheme)</code></p>
 
<p class="linenumber">[line 178]</p>
<h4>Tags:</h4>
<ul>
<li><b>see</b> - <a
href="../default/Net_URL2.html#methodgetScheme">Net_URL2::getScheme()</a></li>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string|bool</span> <b>$scheme</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetUserinfo"></a>
<p></p>
<h3>setUserinfo</h3>
<div class="indent">
<p><code>void setUserinfo( string|bool $userinfo,
[string|bool $password = false])</code></p>
 
<p class="linenumber">[line 227]</p>
<p align="center"><strong>Sets the userinfo part. If two
arguments are passed, they are combined in the userinfo part as username
&quot;:&quot; password. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string|bool</span> <b>$userinfo</b> -
userinfo or username</li>
<li><span class="type">string|bool</span> <b>$password</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodunsetQueryVariable"></a>
<p></p>
<h3>unsetQueryVariable</h3>
<div class="indent">
<p><code>void unsetQueryVariable( string $name)</code></p>
 
<p class="linenumber">[line 497]</p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$name</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="method__toString"></a>
<p></p>
<h3>__toString</h3>
<div class="indent">
<p><code>void __toString( )</code></p>
 
<p class="linenumber">[line 814]</p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_consts"></a>
<h2>Class Constants</h2>
<a name="constOPTION_ENCODE_KEYS"></a>
<p></p>
<h4>OPTION_ENCODE_KEYS = <span class="value">&nbsp;'encode_keys'</span></h4>
<div class="indent">
<p class="linenumber">[line 59]</p>
<p align="center"><strong>URL-encode query variable keys.
Default is true. </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="constOPTION_SEPARATOR_INPUT"></a>
<p></p>
<h4>OPTION_SEPARATOR_INPUT = <span class="value">&nbsp;'input_separator'</span></h4>
<div class="indent">
<p class="linenumber">[line 66]</p>
<p align="center"><strong>Query variable separators when
parsing the query string. Every character is considered a separator.
Default is specified by the arg_separator.input php.ini setting (this
defaults to &quot;&amp;&quot;). </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="constOPTION_SEPARATOR_OUTPUT"></a>
<p></p>
<h4>OPTION_SEPARATOR_OUTPUT = <span class="value">&nbsp;'output_separator'</span></h4>
<div class="indent">
<p class="linenumber">[line 73]</p>
<p align="center"><strong>Query variable separator used
when generating the query string. Default is specified by the
arg_separator.output php.ini setting (this defaults to
&quot;&amp;&quot;). </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="constOPTION_STRICT"></a>
<p></p>
<h4>OPTION_STRICT = <span class="value">&nbsp;'strict'</span></h4>
<div class="indent">
<p class="linenumber">[line 49]</p>
<p align="center"><strong>Do strict parsing in resolve()
(see RFC 3986, section 5.2.2). Default is true. </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="constOPTION_USE_BRACKETS"></a>
<p></p>
<h4>OPTION_USE_BRACKETS = <span class="value">&nbsp;'use_brackets'</span></h4>
<div class="indent">
<p class="linenumber">[line 54]</p>
<p align="center"><strong>Represent arrays in query using
PHP's [] notation. Default is true. </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
</div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/_index.php.html
New file
0,0 → 1,98
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs for page index.php</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Procedural File: index.php</h1>
<p style="margin: 0px;">Source Location: /index.php</p>
 
<br>
<br>
 
<div class="contents">
<h2>Classes:</h2>
<dl>
</dl>
</div>
 
<h2>Page Details:</h2>
<hr>
<hr>
<div id="global"></div>
<hr>
<div id="define"></div>
<hr>
<div id="function"></div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/Controleur.html
New file
0,0 → 1,236
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs For Class Controleur</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Class: Controleur</h1>
<p style="margin: 0px;">Source Location:
/bibliotheque/Controleur.php</p>
 
 
<div class="leftcol">
<h3><a href="#class_details">Class Overview</a> <span
class="smalllinenumber">[line 7]</span></h3>
<div id="classTree"><pre></pre></div>
<div class="small">
<p>Classe controlleur, coeur d'une application, c'est normalement la
seule classe d'une application qui devrait être appelée de l'extérieur.</p>
<h4>Author(s):</h4>
<ul>
</ul>
<h4>Version:</h4>
<ul>
</ul>
 
<h4>Copyright:</h4>
<ul>
</li>
</div>
</div>
 
<div class="middlecol">
<h3><a href="#class_vars">Variables</a></h3>
<ul class="small">
</ul>
<h3><a href="#class_consts">Constants</a></h3>
<ul class="small">
</ul>
</div>
<div class="rightcol">
<h3><a href="#class_methods">Methods</a></h3>
<ul class="small">
<li><a href="../default/Controleur.html#method__construct">__construct</a></li>
<li><a href="../default/Controleur.html#methodchargerModele">chargerModele</a></li>
<li><a href="../default/Controleur.html#methodchargerVue">chargerVue</a></li>
</ul>
</div>
 
<div id="content">
<hr>
<div class="contents">
<h2>Child classes:</h2>
<dl>
<dt><a href="../default/AdminAdministrateur.html">AdminAdministrateur</a></dt>
<dd>Classe controleur pour l'application administration des
administrateurs</dd>
</dl>
</p>
</div>
 
<div class="leftCol">
<h2>Inherited Variables</h2>
<h2>Inherited Constants</h2>
</div>
 
<div class="rightCol">
<h2>Inherited Methods</h2>
</div>
<br clear="all">
<hr>
 
<a name="class_details"></a>
<h2>Class Details</h2>
<p align="center"><strong>Classe controlleur, coeur d'une
application, c'est normalement la seule classe d'une application qui
devrait être appelée de l'extérieur. </strong></p>
<p>Elle est abstraite donc doit obligatoirement être étendue</p>
<h4>Tags:</h4>
<ul>
<li><b>abstract</b> -</li>
</ul>
<p class="small" style="color: #334B66;">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_vars"></a>
<h2>Class Variables</h2>
 
<hr>
<a name="class_methods"></a>
<h2>Class Methods</h2>
 
<a name="method__construct"></a>
<p></p>
<h3>__construct</h3>
<div class="indent">
<p><code>Controleur __construct( )</code></p>
 
<p class="linenumber">[line 25]</p>
<p align="center"><strong>Constructeur par défaut </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodchargerModele"></a>
<p></p>
<h3>chargerModele</h3>
<div class="indent">
<p><code>void chargerModele( $nom_modele $nom_modele)</code></p>
 
<p class="linenumber">[line 50]</p>
<p align="center"><strong>Charge un modele donné et le rend
disponible sous la forme $this-&gt;nom_modele </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - protected</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">$nom_modele</span> <b>$nom_modele</b> - le
nom du modèle à charger</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodchargerVue"></a>
<p></p>
<h3>chargerVue</h3>
<div class="indent">
<p><code>void chargerVue( String $nom_squelette, Array
$donnees)</code></p>
 
<p class="linenumber">[line 75]</p>
<p align="center"><strong>Fonction prenant en paramètre le
nom d'un squelette et un tableau associatif de données, en extrait les
variables, charge le squelette et cree une variable de classe contenant
les deux combinés. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - protected</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">String</span> <b>$nom_squelette</b> - le
nom du squelette</li>
<li><span class="type">Array</span> <b>$donnees</b> - un tableau
associatif contenant les variables a injecter dans la vue</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_consts"></a>
<h2>Class Constants</h2>
</div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/_bibliotheque---Modele.php.html
New file
0,0 → 1,101
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs for page Modele.php</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Procedural File: Modele.php</h1>
<p style="margin: 0px;">Source Location: /bibliotheque/Modele.php</p>
 
<br>
<br>
 
<div class="contents">
<h2>Classes:</h2>
<dl>
<dt><a href="../default/Modele.html">Modele</a></dt>
<dd>Classe modèle, donc d'accès au données, elle ne devrait pas
être appelée de l'extérieur.</dd>
</dl>
</div>
 
<h2>Page Details:</h2>
<hr>
<hr>
<div id="global"></div>
<hr>
<div id="define"></div>
<hr>
<div id="function"></div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/_modeles---ListeAdmin.php.html
New file
0,0 → 1,100
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs for page ListeAdmin.php</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Procedural File: ListeAdmin.php</h1>
<p style="margin: 0px;">Source Location: /modeles/ListeAdmin.php</p>
 
<br>
<br>
 
<div class="contents">
<h2>Classes:</h2>
<dl>
<dt><a href="../default/listeAdmin.html">listeAdmin</a></dt>
<dd>Modèle d'accès à la base de données des administrateurs</dd>
</dl>
</div>
 
<h2>Page Details:</h2>
<hr>
<hr>
<div id="global"></div>
<hr>
<div id="define"></div>
<hr>
<div id="function"></div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/_bibliotheque---GestionnaireException.php.html
New file
0,0 → 1,101
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs for page GestionnaireException.php</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Procedural File: GestionnaireException.php</h1>
<p style="margin: 0px;">Source Location:
/bibliotheque/GestionnaireException.php</p>
 
<br>
<br>
 
<div class="contents">
<h2>Classes:</h2>
<dl>
<dt><a href="../default/GestionnaireException.html">GestionnaireException</a></dt>
<dd>Classe GestionnaireException, gère les exceptions</dd>
</dl>
</div>
 
<h2>Page Details:</h2>
<hr>
<hr>
<div id="global"></div>
<hr>
<div id="define"></div>
<hr>
<div id="function"></div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/_controleurs---AdminAdministrateur.php.html
New file
0,0 → 1,102
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs for page AdminAdministrateur.php</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Procedural File: AdminAdministrateur.php</h1>
<p style="margin: 0px;">Source Location:
/controleurs/AdminAdministrateur.php</p>
 
<br>
<br>
 
<div class="contents">
<h2>Classes:</h2>
<dl>
<dt><a href="../default/AdminAdministrateur.html">AdminAdministrateur</a></dt>
<dd>Classe controleur pour l'application administration des
administrateurs</dd>
</dl>
</div>
 
<h2>Page Details:</h2>
<hr>
<hr>
<div id="global"></div>
<hr>
<div id="define"></div>
<hr>
<div id="function"></div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/_configuration---config.inc.php.html
New file
0,0 → 1,200
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs for page config.inc.php</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Procedural File: config.inc.php</h1>
<p style="margin: 0px;">Source Location:
/configuration/config.inc.php</p>
 
<br>
<br>
 
<div class="contents">
<h2>Classes:</h2>
<dl>
</dl>
</div>
 
<h2>Page Details:</h2>
<hr>
<hr>
<div id="global"></div>
<hr>
<div id="define"><a name="defineBDD_MOT_DE_PASSE"></a>
<h3>BDD_MOT_DE_PASSE</h3>
<div class="indent">
<p class="linenumber">[line 34]</p>
<p><code>BDD_MOT_DE_PASSE = 'Canard123$'</code></p>
<p align="center"><strong>Constante stockant le mot de
passse de l'utilisateur de la base de données. </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="defineBDD_NOM_PRINCIPALE"></a>
<h3>BDD_NOM_PRINCIPALE</h3>
<div class="indent">
<p class="linenumber">[line 36]</p>
<p><code>BDD_NOM_PRINCIPALE = 'papyrus_bp'</code></p>
<p align="center"><strong>Constante stockant le nom de la
base de données principale. </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="defineBDD_PROTOCOLE"></a>
<h3>BDD_PROTOCOLE</h3>
<div class="indent">
<p class="linenumber">[line 28]</p>
<p><code>BDD_PROTOCOLE = 'mysql'</code></p>
<p align="center"><strong>Constante stockant le protocole
de la base de données. </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="defineBDD_SERVEUR"></a>
<h3>BDD_SERVEUR</h3>
<div class="indent">
<p class="linenumber">[line 30]</p>
<p><code>BDD_SERVEUR = 'localhost'</code></p>
<p align="center"><strong>Constante stockant le nom du
serveur de bases de données. </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="defineBDD_UTILISATEUR"></a>
<h3>BDD_UTILISATEUR</h3>
<div class="indent">
<p class="linenumber">[line 32]</p>
<p><code>BDD_UTILISATEUR = 'root'</code></p>
<p align="center"><strong>Constante stockant le nom de
l'utilisateur de la base de données. </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="defineSC_DEBOGAGE"></a>
<h3>SC_DEBOGAGE</h3>
<div class="indent">
<p class="linenumber">[line 16]</p>
<p><code>SC_DEBOGAGE = true</code></p>
<p align="center"><strong>Constante stockant si oui ou non
on veut afficher le débogage. </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="defineSC_DEBOGAGE_CHRONO"></a>
<h3>SC_DEBOGAGE_CHRONO</h3>
<div class="indent">
<p class="linenumber">[line 22]</p>
<p><code>SC_DEBOGAGE_CHRONO = true</code></p>
<p align="center"><strong>Constante stockant si oui ou nom
on veut afficher le tableau de chronométrage de l'application. </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="defineSC_DEBOGAGE_CONTEXTE"></a>
<h3>SC_DEBOGAGE_CONTEXTE</h3>
<div class="indent">
<p class="linenumber">[line 18]</p>
<p><code>SC_DEBOGAGE_CONTEXTE = false</code></p>
<p align="center"><strong>Constante stockant si oui ou non
on veut afficher le contexte de débogage. </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="defineSC_DEBOGAGE_NIVEAU"></a>
<h3>SC_DEBOGAGE_NIVEAU</h3>
<div class="indent">
<p class="linenumber">[line 20]</p>
<p><code>SC_DEBOGAGE_NIVEAU = 2048</code></p>
<p align="center"><strong>Constante stockant une valeur
correspondant au niveau d'erreur à employer pour le code PHP. </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="defineURL_BASE"></a>
<h3>URL_BASE</h3>
<div class="indent">
<p class="linenumber">[line 7]</p>
<p><code>URL_BASE = ''</code></p>
<p align="center"><strong>Constante URL de base de
l'application, si elle est laissée vide, l'application fonctionnera en
Stand-alone </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="defineVAR_IDENT"></a>
<h3>VAR_IDENT</h3>
<div class="indent">
<p class="linenumber">[line 11]</p>
<p><code>VAR_IDENT = true</code></p>
<p align="center"><strong>Variable à tester pour
l'identification, mettre à true si l'application ne nécessite pas de
s'identifier * </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
</div>
<hr>
<div id="function"></div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/_bibliotheque---Net_URL.php.html
New file
0,0 → 1,100
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs for page Net_URL.php</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Procedural File: Net_URL.php</h1>
<p style="margin: 0px;">Source Location: /bibliotheque/Net_URL.php</p>
 
<br>
<br>
 
<div class="contents">
<h2>Classes:</h2>
<dl>
<dt><a href="../default/Net_URL.html">Net_URL</a></dt>
<dd></dd>
</dl>
</div>
 
<h2>Page Details:</h2>
<hr>
<hr>
<div id="global"></div>
<hr>
<div id="define"></div>
<hr>
<div id="function"></div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/AdminAdministrateur.html
New file
0,0 → 1,413
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs For Class AdminAdministrateur</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Class: AdminAdministrateur</h1>
<p style="margin: 0px;">Source Location:
/controleurs/AdminAdministrateur.php</p>
 
 
<div class="leftcol">
<h3><a href="#class_details">Class Overview</a> <span
class="smalllinenumber">[line 6]</span></h3>
<div id="classTree"><pre><a
href="../default/Controleur.html">Controleur</a>
|
--AdminAdministrateur</pre></div>
<div class="small">
<p>Classe controleur pour l'application administration des
administrateurs</p>
<h4>Author(s):</h4>
<ul>
</ul>
<h4>Version:</h4>
<ul>
</ul>
 
<h4>Copyright:</h4>
<ul>
</li>
</div>
</div>
 
<div class="middlecol">
<h3><a href="#class_vars">Variables</a></h3>
<ul class="small">
</ul>
<h3><a href="#class_consts">Constants</a></h3>
<ul class="small">
</ul>
</div>
<div class="rightcol">
<h3><a href="#class_methods">Methods</a></h3>
<ul class="small">
<li><a href="../default/AdminAdministrateur.html#methodadminPied">adminPied</a></li>
<li><a href="../default/AdminAdministrateur.html#methodadminTete">adminTete</a></li>
<li><a href="../default/AdminAdministrateur.html#methodajoutAdmin">ajoutAdmin</a></li>
<li><a
href="../default/AdminAdministrateur.html#methodajoutAdminVa">ajoutAdminVa</a></li>
<li><a
href="../default/AdminAdministrateur.html#methodchargerAdmin">chargerAdmin</a></li>
<li><a
href="../default/AdminAdministrateur.html#methoddemanderIdent">demanderIdent</a></li>
<li><a href="../default/AdminAdministrateur.html#methodindex">index</a></li>
<li><a href="../default/AdminAdministrateur.html#methodmodifAdmin">modifAdmin</a></li>
<li><a
href="../default/AdminAdministrateur.html#methodmodifAdminVa">modifAdminVa</a></li>
<li><a href="../default/AdminAdministrateur.html#methodsupprAdmin">supprAdmin</a></li>
</ul>
</div>
 
<div id="content">
<hr>
<div class="contents"></div>
 
<div class="leftCol">
<h2>Inherited Variables</h2>
<h2>Inherited Constants</h2>
</div>
 
<div class="rightCol">
<h2>Inherited Methods</h2>
<div class="indent">
<h3>Class: <a href="../default/Controleur.html">Controleur</a></h3>
<dl class="small">
<dt><a href="../default/Controleur.html#method__construct">Controleur::__construct()</a>
</dt>
<dd>Constructeur par défaut</dd>
<dt><a href="../default/Controleur.html#methodchargerModele">Controleur::chargerModele()</a>
</dt>
<dd>Charge un modele donné et le rend disponible sous la forme
$this-&gt;nom_modele</dd>
<dt><a href="../default/Controleur.html#methodchargerVue">Controleur::chargerVue()</a>
</dt>
<dd>Fonction prenant en paramètre le nom d'un squelette et un
tableau associatif de données, en extrait les variables, charge le
squelette et cree une variable de classe contenant les deux combinés.</dd>
</dl>
</div>
</div>
<br clear="all">
<hr>
 
<a name="class_details"></a>
<h2>Class Details</h2>
<p align="center"><strong>Classe controleur pour
l'application administration des administrateurs </strong></p>
<p class="small" style="color: #334B66;">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_vars"></a>
<h2>Class Variables</h2>
 
<hr>
<a name="class_methods"></a>
<h2>Class Methods</h2>
 
<a name="methodadminPied"></a>
<p></p>
<h3>adminPied</h3>
<div class="indent">
<p><code>string adminPied( )</code></p>
 
<p class="linenumber">[line 188]</p>
<p align="center"><strong>Renvoie le pied de page de
l'application </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - le pied de page de l'application</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodadminTete"></a>
<p></p>
<h3>adminTete</h3>
<div class="indent">
<p><code>string adminTete( )</code></p>
 
<p class="linenumber">[line 177]</p>
<p align="center"><strong>Renvoie la tête de page de
l'application </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - la tete de page de l'application</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodajoutAdmin"></a>
<p></p>
<h3>ajoutAdmin</h3>
<div class="indent">
<p><code>string ajoutAdmin( )</code></p>
 
<p class="linenumber">[line 106]</p>
<p align="center"><strong>Appelle la vue contenant le
formulaire d'ajout d'un administrateur </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - la vue contenant le formulaire d'ajout</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodajoutAdminVa"></a>
<p></p>
<h3>ajoutAdminVa</h3>
<div class="indent">
<p><code>string ajoutAdminVa( string $nom, string $prenom,
string $mail, string $lang, string $pass, $pass_conf)</code></p>
 
<p class="linenumber">[line 131]</p>
<p align="center"><strong>Fonction appelée lors de la
validation du formulaire d'ajout d'un administrateur. </strong></p>
<p>Elle ajoute celui-ci les dans la base de données S'il y a une
erreur et rappelle la formulaire et notifie l'erreur, sinon elle charge
la liste des administrateurs</p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - la vue correspondante</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$nom</b> - le nom</li>
<li><span class="type">string</span> <b>$prenom</b> - le prénom</li>
<li><span class="type">string</span> <b>$mail</b> - le mail</li>
<li><span class="type">string</span> <b>$lang</b> - le mot de
passe</li>
<li><span class="type">string</span> <b>$pass</b> - la
confirmation du mot de passe</li>
<li><span class="type"></span> <b>$pass_conf</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodchargerAdmin"></a>
<p></p>
<h3>chargerAdmin</h3>
<div class="indent">
<p><code>string chargerAdmin( [array $erreurs = array()])</code></p>
 
<p class="linenumber">[line 21]</p>
<p align="center"><strong>Charge la liste des
administrateurs et l'envoie à la vue </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - la vue correspondante</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">array</span> <b>$erreurs</b> - un tableau
contenant les erreurs à afficher s'il y en a</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methoddemanderIdent"></a>
<p></p>
<h3>demanderIdent</h3>
<div class="indent">
<p><code>string demanderIdent( )</code></p>
 
<p class="linenumber">[line 167]</p>
<p align="center"><strong>Apelle le formulaire
d'identification (dans le cas où l'utilisateur n'est pas identifié) </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - la vue permettant de s'identifier</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodindex"></a>
<p></p>
<h3>index</h3>
<div class="indent">
<p><code>void index( )</code></p>
 
<p class="linenumber">[line 11]</p>
<p align="center"><strong>Fonction d'affichage par défaut,
elle appelle la liste des administrateurs </strong></p>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodmodifAdmin"></a>
<p></p>
<h3>modifAdmin</h3>
<div class="indent">
<p><code>string modifAdmin( $id)</code></p>
 
<p class="linenumber">[line 37]</p>
<p align="center"><strong>Charge les détails d'un
administrateur demandé et l'envoi à la </strong></p>
<p>vue qui permet de les modifier</p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - la vue correspondante</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type"></span> <b>$id</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodmodifAdminVa"></a>
<p></p>
<h3>modifAdminVa</h3>
<div class="indent">
<p><code>string modifAdminVa( string $id, string $nom, string
$prenom, string $mail, string $lang, string $pass, $pass_conf)</code></p>
 
<p class="linenumber">[line 60]</p>
<p align="center"><strong>Fonction appelée lors de la
validation du formulaire de modification </strong></p>
<p>des détails d'un administrateurs. Elle modifie les détails dans
la base de données. S'il y a une erreur et rappelle la formulaire et
notifie l'erreur, sinon elle charge la liste des administrateurs</p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - la vue correspondante</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$id</b> - l'identifiant de
l'administrateur*</li>
<li><span class="type">string</span> <b>$nom</b> - le nom</li>
<li><span class="type">string</span> <b>$prenom</b> - le prénom</li>
<li><span class="type">string</span> <b>$mail</b> - le mail</li>
<li><span class="type">string</span> <b>$lang</b> - le mot de
passe</li>
<li><span class="type">string</span> <b>$pass</b> - la
confirmation du mot de passe</li>
<li><span class="type"></span> <b>$pass_conf</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsupprAdmin"></a>
<p></p>
<h3>supprAdmin</h3>
<div class="indent">
<p><code>string supprAdmin( $id)</code></p>
 
<p class="linenumber">[line 90]</p>
<p align="center"><strong>Supprime un administrateur dans
la base de données, renvoie la liste des administrateurs, en affichant
des erreurs s'il y en a. </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - la vue contenant la liste des administrateurs</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type"></span> <b>$id</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_consts"></a>
<h2>Class Constants</h2>
</div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/Modele.html
New file
0,0 → 1,252
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs For Class Modele</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Class: Modele</h1>
<p style="margin: 0px;">Source Location: /bibliotheque/Modele.php</p>
 
 
<div class="leftcol">
<h3><a href="#class_details">Class Overview</a> <span
class="smalllinenumber">[line 8]</span></h3>
<div id="classTree"><pre></pre></div>
<div class="small">
<p>Classe modèle, donc d'accès au données, elle ne devrait pas être
appelée de l'extérieur.</p>
<h4>Author(s):</h4>
<ul>
</ul>
<h4>Version:</h4>
<ul>
</ul>
 
<h4>Copyright:</h4>
<ul>
</li>
</div>
</div>
 
<div class="middlecol">
<h3><a href="#class_vars">Variables</a></h3>
<ul class="small">
</ul>
<h3><a href="#class_consts">Constants</a></h3>
<ul class="small">
</ul>
</div>
<div class="rightcol">
<h3><a href="#class_methods">Methods</a></h3>
<ul class="small">
<li><a href="../default/Modele.html#method__construct">__construct</a></li>
<li><a href="../default/Modele.html#method__destruct">__destruct</a></li>
<li><a href="../default/Modele.html#methodproteger">proteger</a></li>
<li><a href="../default/Modele.html#methodrequete">requete</a></li>
</ul>
</div>
 
<div id="content">
<hr>
<div class="contents">
<h2>Child classes:</h2>
<dl>
<dt><a href="../default/listeAdmin.html">listeAdmin</a></dt>
<dd>Modèle d'accès à la base de données des administrateurs</dd>
</dl>
</p>
</div>
 
<div class="leftCol">
<h2>Inherited Variables</h2>
<h2>Inherited Constants</h2>
</div>
 
<div class="rightCol">
<h2>Inherited Methods</h2>
</div>
<br clear="all">
<hr>
 
<a name="class_details"></a>
<h2>Class Details</h2>
<p align="center"><strong>Classe modèle, donc d'accès au
données, elle ne devrait pas être appelée de l'extérieur. </strong></p>
<p>Elle fait office d'abstraction légère de base de données en
utilisant les objects PDO natifs de PHP Elle est abstraite donc doit
obligatoirement être étendue.</p>
<h4>Tags:</h4>
<ul>
<li><b>abstract</b> -</li>
</ul>
<p class="small" style="color: #334B66;">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_vars"></a>
<h2>Class Variables</h2>
 
<hr>
<a name="class_methods"></a>
<h2>Class Methods</h2>
 
<a name="method__construct"></a>
<p></p>
<h3>__construct</h3>
<div class="indent">
<p><code>Modele __construct( )</code></p>
 
<p class="linenumber">[line 54]</p>
<p align="center"><strong>Constructeur par défaut, appelé à
l'initialisation </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="method__destruct"></a>
<p></p>
<h3>__destruct</h3>
<div class="indent">
<p><code>void __destruct( )</code></p>
 
<p class="linenumber">[line 115]</p>
<p align="center"><strong>Destructeur de classe, se
contente de fermer explicitement la connexion </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodproteger"></a>
<p></p>
<h3>proteger</h3>
<div class="indent">
<p><code>void proteger( $chaine)</code></p>
 
<p class="linenumber">[line 102]</p>
<p align="center"><strong>protège une chaine de caractères
avant l'insertion dans la base de données </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - protected</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type"></span> <b>$chaine</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodrequete"></a>
<p></p>
<h3>requete</h3>
<div class="indent">
<p><code>PDOStatement requete( string $requete)</code></p>
 
<p class="linenumber">[line 73]</p>
<p align="center"><strong>Fonction qui appelle la bonne
fonction de requete suivant le type de bdd </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - un objet contenant le résultat de la requête</li>
<li><b>access</b> - protected</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$requete</b> - la requete
à effectuer</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_consts"></a>
<h2>Class Constants</h2>
</div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/_autoload.inc.php.html
New file
0,0 → 1,136
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs for page autoload.inc.php</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Procedural File: autoload.inc.php</h1>
<p style="margin: 0px;">Source Location: /autoload.inc.php</p>
 
<br>
<br>
 
<div class="contents">
<h2>Classes:</h2>
<dl>
</dl>
</div>
 
<h2>Page Details:</h2>
<hr>
Includes:<br>
require_once(<a
href="../default/_configuration---config_chemin.inc.php.html">'configuration/config_chemin.inc.php'</a>)
<span class="linenumber">[line 15]</span> <br />
require_once(<a href="../default/_configuration---config.inc.php.html">'configuration/config.inc.php'</a>)
<span class="linenumber">[line 13]</span> <br />
<hr>
<div id="global"></div>
<hr>
<div id="define"><a name="defineCHEMIN_APPLI"></a>
<h3>CHEMIN_APPLI</h3>
<div class="indent">
<p class="linenumber">[line 9]</p>
<p><code>CHEMIN_APPLI = dirname(__FILE__).DIRECTORY_SEPARATOR</code></p>
<p align="center"><strong>Fichier contenant la fonction de
chargement automatique de classes, il doit toujours rester à la racine
du framework car il initialise le chemin de l'application en se basant
sur son propre emplacement. </strong></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
</div>
<hr>
<div id="function"><a name="function__autoload"></a>
<h3>__autoload</h3>
<div class="indent"><code>void __autoload( string $classe)</code>
<p class="linenumber">[line 24]</p>
<p align="center"><strong>La fonction __autoload() charge
dynamiquement les classes trouvées dans le code. </strong></p>
<p>Cette fonction est appelée par php5 quand il trouve une
instanciation de classe dans le code.</p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - le fichier contenant la classe doit être inclu
par la fonction.</li>
</ul>
 
<h4>Parameters</h4>
<ul>
<li><span class="type">string</span> <b>$classe</b> - le nom de la
classe appelée.</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
</div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/GestionnaireException.html
New file
0,0 → 1,291
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs For Class GestionnaireException</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Class: GestionnaireException</h1>
<p style="margin: 0px;">Source Location:
/bibliotheque/GestionnaireException.php</p>
 
 
<div class="leftcol">
<h3><a href="#class_details">Class Overview</a> <span
class="smalllinenumber">[line 12]</span></h3>
<div id="classTree"><pre></pre></div>
<div class="small">
<p>Classe GestionnaireException, gère les exceptions</p>
<h4>Author(s):</h4>
<ul>
</ul>
<h4>Version:</h4>
<ul>
</ul>
 
<h4>Copyright:</h4>
<ul>
</li>
</div>
</div>
 
<div class="middlecol">
<h3><a href="#class_vars">Variables</a></h3>
<ul class="small">
</ul>
<h3><a href="#class_consts">Constants</a></h3>
<ul class="small">
</ul>
</div>
<div class="rightcol">
<h3><a href="#class_methods">Methods</a></h3>
<ul class="small">
<li><a
href="../default/GestionnaireException.html#method__construct">__construct</a></li>
<li><a
href="../default/GestionnaireException.html#methodgererException">gererException</a></li>
<li><a
href="../default/GestionnaireException.html#methodgetContexte">getContexte</a></li>
<li><a
href="../default/GestionnaireException.html#methodgetExceptions">getExceptions</a></li>
<li><a
href="../default/GestionnaireException.html#methodgetInstance">getInstance</a></li>
<li><a
href="../default/GestionnaireException.html#methodsetContexte">setContexte</a></li>
</ul>
</div>
 
<div id="content">
<hr>
<div class="contents"></div>
 
<div class="leftCol">
<h2>Inherited Variables</h2>
<h2>Inherited Constants</h2>
</div>
 
<div class="rightCol">
<h2>Inherited Methods</h2>
</div>
<br clear="all">
<hr>
 
<a name="class_details"></a>
<h2>Class Details</h2>
<p align="center"><strong>Classe GestionnaireException,
gère les exceptions </strong></p>
<p class="small" style="color: #334B66;">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_vars"></a>
<h2>Class Variables</h2>
 
<hr>
<a name="class_methods"></a>
<h2>Class Methods</h2>
<a name="methodgererException"></a>
<p></p>
<h3>static gererException</h3>
<div class="indent">
<p><code>static void gererException( $e)</code></p>
 
<p class="linenumber">[line 77]</p>
<p align="center"><strong>Fonction de gestion des
exceptions, remplace le handler par défaut </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">Exception</span> <b>$e</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetInstance"></a>
<p></p>
<h3>static getInstance</h3>
<div class="indent">
<p><code>static <a
href="../eFlore/Debogage/GestionnaireErreur.html">GestionnaireErreur</a>
getInstance( )</code></p>
 
<p class="linenumber">[line 65]</p>
<p align="center"><strong>Fonction d'accès au singleton </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - le gestionnaire d'exceptions courant</li>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
 
<a name="method__construct"></a>
<p></p>
<h3>__construct</h3>
<div class="indent">
<p><code>GestionnaireException __construct( [bool $contexte =
false])</code></p>
 
<p class="linenumber">[line 39]</p>
<p align="center"><strong>Constructeur avec paramètres
optionnel </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">bool</span> <b>$contexte</b> - indique si
l'on veut afficher ou non le contexte des exceptions (i.e. la trace)</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetContexte"></a>
<p></p>
<h3>getContexte</h3>
<div class="indent">
<p><code>void getContexte( )</code></p>
 
<p class="linenumber">[line 50]</p>
<p align="center"><strong>Renvoie le booleen définissant si
l'on affiche le contexte ou non </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetExceptions"></a>
<p></p>
<h3>getExceptions</h3>
<div class="indent">
<p><code>void getExceptions( )</code></p>
 
<p class="linenumber">[line 87]</p>
<p align="center"><strong>Renvoie les exceptions au format
(X)HTML </strong></p>
<p>ou bien au format texte suivant le mode d'utilisation de PHP</p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetContexte"></a>
<p></p>
<h3>setContexte</h3>
<div class="indent">
<p><code>void setContexte( bool $contexte)</code></p>
 
<p class="linenumber">[line 58]</p>
<p align="center"><strong>Definit si l'on veut afficher le
contexte ou non </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">bool</span> <b>$contexte</b> - true si on
veut afficher le contexte, false sinon, par défaut vaut false</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_consts"></a>
<h2>Class Constants</h2>
</div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/Net_URL.html
New file
0,0 → 1,582
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs For Class Net_URL</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Class: Net_URL</h1>
<p style="margin: 0px;">Source Location: /bibliotheque/Net_URL.php</p>
 
 
<div class="leftcol">
<h3><a href="#class_details">Class Overview</a> <span
class="smalllinenumber">[line 40]</span></h3>
<div id="classTree"><pre></pre></div>
<div class="small">
<p></p>
<h4>Author(s):</h4>
<ul>
</ul>
<h4>Version:</h4>
<ul>
</ul>
 
<h4>Copyright:</h4>
<ul>
</li>
</div>
</div>
 
<div class="middlecol">
<h3><a href="#class_vars">Variables</a></h3>
<ul class="small">
<li><a href="../default/Net_URL.html#var$anchor">$anchor</a></li>
<li><a href="../default/Net_URL.html#var$host">$host</a></li>
<li><a href="../default/Net_URL.html#var$options">$options</a></li>
<li><a href="../default/Net_URL.html#var$password">$password</a></li>
<li><a href="../default/Net_URL.html#var$path">$path</a></li>
<li><a href="../default/Net_URL.html#var$port">$port</a></li>
<li><a href="../default/Net_URL.html#var$protocol">$protocol</a></li>
<li><a href="../default/Net_URL.html#var$querystring">$querystring</a></li>
<li><a href="../default/Net_URL.html#var$url">$url</a></li>
<li><a href="../default/Net_URL.html#var$useBrackets">$useBrackets</a></li>
<li><a href="../default/Net_URL.html#var$username">$username</a></li>
</ul>
<h3><a href="#class_consts">Constants</a></h3>
<ul class="small">
</ul>
</div>
<div class="rightcol">
<h3><a href="#class_methods">Methods</a></h3>
<ul class="small">
<li><a href="../default/Net_URL.html#method__construct">__construct</a></li>
<li><a href="../default/Net_URL.html#methodNet_URL">Net_URL</a></li>
<li><a href="../default/Net_URL.html#methodaddQueryString">addQueryString</a></li>
<li><a href="../default/Net_URL.html#methodaddRawQueryString">addRawQueryString</a></li>
<li><a href="../default/Net_URL.html#methodgetOption">getOption</a></li>
<li><a href="../default/Net_URL.html#methodgetQueryString">getQueryString</a></li>
<li><a href="../default/Net_URL.html#methodgetStandardPort">getStandardPort</a></li>
<li><a href="../default/Net_URL.html#methodgetURL">getURL</a></li>
<li><a href="../default/Net_URL.html#methodinitialize">initialize</a></li>
<li><a href="../default/Net_URL.html#methodremoveQueryString">removeQueryString</a></li>
<li><a href="../default/Net_URL.html#methodresolvePath">resolvePath</a></li>
<li><a href="../default/Net_URL.html#methodsetOption">setOption</a></li>
<li><a href="../default/Net_URL.html#methodsetProtocol">setProtocol</a></li>
<li><a href="../default/Net_URL.html#method__toString">__toString</a></li>
</ul>
</div>
 
<div id="content">
<hr>
<div class="contents"></div>
 
<div class="leftCol">
<h2>Inherited Variables</h2>
<h2>Inherited Constants</h2>
</div>
 
<div class="rightCol">
<h2>Inherited Methods</h2>
</div>
<br clear="all">
<hr>
 
<a name="class_details"></a>
<h2>Class Details</h2>
<p class="small" style="color: #334B66;">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_vars"></a>
<h2>Class Variables</h2>
<a name="var$anchor"></a>
<p></p>
<h4>$anchor</h4>
<div class="indent">
<p class="linenumber">[line 95]</p>
<p align="center"><strong>Anchor </strong></p>
<p><b>Type:</b> string</p>
<p><b>Overrides:</b></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="var$host"></a>
<p></p>
<h4>$host</h4>
<div class="indent">
<p class="linenumber">[line 71]</p>
<p align="center"><strong>Host </strong></p>
<p><b>Type:</b> string</p>
<p><b>Overrides:</b></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="var$options"></a>
<p></p>
<h4>$options = <span class="value">array('encode_query_keys'&nbsp;=&gt;&nbsp;false)</span></h4>
<div class="indent">
<p class="linenumber">[line 42]</p>
<p><b>Type:</b> mixed</p>
<p><b>Overrides:</b></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="var$password"></a>
<p></p>
<h4>$password</h4>
<div class="indent">
<p class="linenumber">[line 65]</p>
<p align="center"><strong>Password </strong></p>
<p><b>Type:</b> string</p>
<p><b>Overrides:</b></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="var$path"></a>
<p></p>
<h4>$path</h4>
<div class="indent">
<p class="linenumber">[line 83]</p>
<p align="center"><strong>Path </strong></p>
<p><b>Type:</b> string</p>
<p><b>Overrides:</b></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="var$port"></a>
<p></p>
<h4>$port</h4>
<div class="indent">
<p class="linenumber">[line 77]</p>
<p align="center"><strong>Port </strong></p>
<p><b>Type:</b> integer</p>
<p><b>Overrides:</b></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="var$protocol"></a>
<p></p>
<h4>$protocol</h4>
<div class="indent">
<p class="linenumber">[line 53]</p>
<p align="center"><strong>Protocol </strong></p>
<p><b>Type:</b> string</p>
<p><b>Overrides:</b></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="var$querystring"></a>
<p></p>
<h4>$querystring</h4>
<div class="indent">
<p class="linenumber">[line 89]</p>
<p align="center"><strong>Query string </strong></p>
<p><b>Type:</b> array</p>
<p><b>Overrides:</b></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="var$url"></a>
<p></p>
<h4>$url</h4>
<div class="indent">
<p class="linenumber">[line 47]</p>
<p align="center"><strong>Full url </strong></p>
<p><b>Type:</b> string</p>
<p><b>Overrides:</b></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="var$useBrackets"></a>
<p></p>
<h4>$useBrackets</h4>
<div class="indent">
<p class="linenumber">[line 101]</p>
<p align="center"><strong>Whether to use [] </strong></p>
<p><b>Type:</b> bool</p>
<p><b>Overrides:</b></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="var$username"></a>
<p></p>
<h4>$username</h4>
<div class="indent">
<p class="linenumber">[line 59]</p>
<p align="center"><strong>Username </strong></p>
<p><b>Type:</b> string</p>
<p><b>Overrides:</b></p>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_methods"></a>
<h2>Class Methods</h2>
 
<a name="method__construct"></a>
<p></p>
<h3>__construct</h3>
<div class="indent">
<p><code>Net_URL __construct( [string $url = null], [bool
$useBrackets = true])</code></p>
 
<p class="linenumber">[line 124]</p>
<p align="center"><strong>PHP5 Constructor </strong></p>
<p>Parses the given url and stores the various parts Defaults are
used in certain cases</p>
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$url</b> - Optional URL</li>
<li><span class="type">bool</span> <b>$useBrackets</b> - Whether
to use square brackets when multiple querystrings with the same name
exist</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodNet_URL"></a>
<p></p>
<h3>Net_URL</h3>
<div class="indent">
<p><code>Net_URL Net_URL( [ $url = null], [ $useBrackets =
true])</code></p>
 
<p class="linenumber">[line 108]</p>
<p align="center"><strong>PHP4 Constructor </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>see</b> - <a
href="../default/Net_URL.html#method__construct">Net_URL::__construct()</a></li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type"></span> <b>$url</b> -</li>
<li><span class="type"></span> <b>$useBrackets</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodaddQueryString"></a>
<p></p>
<h3>addQueryString</h3>
<div class="indent">
<p><code>void addQueryString( string $name, string $value,
[bool $preencoded = false])</code></p>
 
<p class="linenumber">[line 245]</p>
<p align="center"><strong>Adds or updates a querystring
item (URL parameter). </strong></p>
<p>Automatically encodes parameters with rawurlencode() if
$preencoded is false. You can pass an array to $value, it gets mapped
via [] in the URL if $this-&gt;useBrackets is activated.</p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$name</b> - Name of item</li>
<li><span class="type">string</span> <b>$value</b> - Value of item</li>
<li><span class="type">bool</span> <b>$preencoded</b> - Whether
value is urlencoded or not, default = not</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodaddRawQueryString"></a>
<p></p>
<h3>addRawQueryString</h3>
<div class="indent">
<p><code>void addRawQueryString( string $querystring)</code></p>
 
<p class="linenumber">[line 281]</p>
<p align="center"><strong>Sets the querystring to literally
what you supply </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$querystring</b> - The
querystring data. Should be of the format foo=bar&amp;x=y etc</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetOption"></a>
<p></p>
<h3>getOption</h3>
<div class="indent">
<p><code>void getOption( $optionName, string $opionName)</code></p>
 
<p class="linenumber">[line 475]</p>
<p align="center"><strong>Get an option </strong></p>
<p>This function gets an option from the $this-&gt;options array and
return it's value.</p>
<h4>Tags:</h4>
<ul>
<li><b>see</b> - $this-&gt;options</li>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$opionName</b> - The name
of the option to retrieve</li>
<li><span class="type"></span> <b>$optionName</b> -</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetQueryString"></a>
<p></p>
<h3>getQueryString</h3>
<div class="indent">
<p><code>string getQueryString( )</code></p>
 
<p class="linenumber">[line 292]</p>
<p align="center"><strong>Returns flat querystring </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - Querystring</li>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetStandardPort"></a>
<p></p>
<h3>getStandardPort</h3>
<div class="indent">
<p><code>integer getStandardPort( string $scheme)</code></p>
 
<p class="linenumber">[line 418]</p>
<p align="center"><strong>Returns the standard port number
for a protocol </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - Port number or NULL if no scheme matches</li>
<li><b>author</b> - Philippe Jausions &lt;<a
href="mailto:Philippe.Jausions@11abacus.com">Philippe.Jausions@11abacus.com</a>&gt;</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$scheme</b> - The protocol
to lookup</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodgetURL"></a>
<p></p>
<h3>getURL</h3>
<div class="indent">
<p><code>string getURL( )</code></p>
 
<p class="linenumber">[line 218]</p>
<p align="center"><strong>Returns full url </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - Full url</li>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodinitialize"></a>
<p></p>
<h3>initialize</h3>
<div class="indent">
<p><code>void initialize( )</code></p>
 
<p class="linenumber">[line 132]</p>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodremoveQueryString"></a>
<p></p>
<h3>removeQueryString</h3>
<div class="indent">
<p><code>void removeQueryString( string $name)</code></p>
 
<p class="linenumber">[line 264]</p>
<p align="center"><strong>Removes a querystring item </strong></p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$name</b> - Name of item</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodresolvePath"></a>
<p></p>
<h3>resolvePath</h3>
<div class="indent">
<p><code>string resolvePath( string $path)</code></p>
 
<p class="linenumber">[line 381]</p>
<p align="center"><strong>Resolves //, ../ and ./ from a
path and returns the result. Eg: </strong></p>
<p>/foo/bar/../boo.php =&gt; /foo/boo.php /foo/bar/../../boo.php
=&gt; /boo.php /foo/bar/.././/boo.php =&gt; /foo/boo.php</p>
<p>This method can also be called statically.</p>
<h4>Tags:</h4>
<ul>
<li><b>return</b> - The result</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$path</b> - URL path to
resolve</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetOption"></a>
<p></p>
<h3>setOption</h3>
<div class="indent">
<p><code>void setOption( string $optionName, string $value)</code></p>
 
<p class="linenumber">[line 454]</p>
<p align="center"><strong>Set an option </strong></p>
<p>This function set an option to be used thorough the script.</p>
<h4>Tags:</h4>
<ul>
<li><b>access</b> - public</li>
</ul>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$optionName</b> - The
optionname to set</li>
<li><span class="type">string</span> <b>$value</b> - The value of
this option.</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="methodsetProtocol"></a>
<p></p>
<h3>setProtocol</h3>
<div class="indent">
<p><code>void setProtocol( string $protocol, [integer $port =
null])</code></p>
 
<p class="linenumber">[line 438]</p>
<p align="center"><strong>Forces the URL to a particular
protocol </strong></p>
 
 
<h4>Parameters:</h4>
<ul>
<li><span class="type">string</span> <b>$protocol</b> - Protocol
to force the URL to</li>
<li><span class="type">integer</span> <b>$port</b> - Optional port
(standard port is used by default)</li>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
<a name="method__toString"></a>
<p></p>
<h3>__toString</h3>
<div class="indent">
<p><code>void __toString( )</code></p>
 
<p class="linenumber">[line 484]</p>
 
 
<h4>Parameters:</h4>
<ul>
</ul>
</div>
<p class="top">[ <a href="#top">Top</a> ]</p>
 
<hr>
<a name="class_consts"></a>
<h2>Class Constants</h2>
</div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/default/_bibliotheque---Registre.php.html
New file
0,0 → 1,101
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Docs for page Registre.php</title>
<link rel="stylesheet" type="text/css" id="layout"
href="../media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="../media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="../media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="../classtrees_default.html">Class
Tree: default</a> ] [ <a href="../elementindex_default.html">Index:
default</a> ] [ <a href="../elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="../li_default.html">default</a></p>
<p><a href="../li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="../default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="../default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="../default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="../default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="../default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="../default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="../default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="../default/_index.php.html"> index.php </a><br>
<a href="../default/_modeles---ListeAdmin.php.html"> ListeAdmin.php
</a><br>
<a href="../default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="../default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="../default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php
</a><br>
<a href="../default/_bibliotheque---Registre.php.html"> Registre.php
</a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="../default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="../default/Controleur.html"> Controleur </a><br>
<a href="../default/GestionnaireException.html">
GestionnaireException </a><br>
<a href="../default/listeAdmin.html"> listeAdmin </a><br>
<a href="../default/Modele.html"> Modele </a><br>
<a href="../default/Net_URL.html"> Net_URL </a><br>
<a href="../default/Net_URL2.html"> Net_URL2 </a><br>
<a href="../default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<h1>Procedural File: Registre.php</h1>
<p style="margin: 0px;">Source Location: /bibliotheque/Registre.php</p>
 
<br>
<br>
 
<div class="contents">
<h2>Classes:</h2>
<dl>
<dt><a href="../default/Registre.html">Registre</a></dt>
<dd>Classe registre, qui permet un accès à différentes variables à
travers les autres classes.</dd>
</dl>
</div>
 
<h2>Page Details:</h2>
<hr>
<hr>
<div id="global"></div>
<hr>
<div id="define"></div>
<hr>
<div id="function"></div>
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/elementindex.html
New file
0,0 → 1,7
<br />
<b>Warning</b>
: Smarty error: unable to read resource: "elementindex.tpl" in
<b>/home/aurelien/web/PhpDocumentor-1.4.2/phpDocumentor/Smarty-2.6.0/libs/Smarty.class.php</b>
on line
<b>1144</b>
<br />
/trunk/doc/classtrees_eFlore.html
New file
0,0 → 1,55
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Class Trees for Package eFlore</title>
<link rel="stylesheet" type="text/css" id="layout"
href="media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="classtrees_eFlore.html">Class
Tree: eFlore</a> ] [ <a href="elementindex_eFlore.html">Index: eFlore</a> ]
[ <a href="elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">eFlore</div>
<div id="packageTitle">eFlore</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="li_default.html">default</a></p>
<p><a href="li_eFlore.html">eFlore</a></p>
</div>
 
</div>
 
<div id="body">
<h1>Class Trees for Package eFlore</h1>
<hr />
<div class="classtree">Root class Chronometre</div>
<br />
<ul>
<li><a href="eFlore/Debogage/Chronometre.html">Chronometre</a></li>
</ul>
 
<hr />
<div class="classtree">Root class GestionnaireErreur</div>
<br />
<ul>
<li><a href="eFlore/Debogage/GestionnaireErreur.html">GestionnaireErreur</a></li>
</ul>
 
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/elementindex_default.html
New file
0,0 → 1,7
<br />
<b>Warning</b>
: Smarty error: unable to read resource: "pkgelementindex.tpl" in
<b>/home/aurelien/web/PhpDocumentor-1.4.2/phpDocumentor/Smarty-2.6.0/libs/Smarty.class.php</b>
on line
<b>1144</b>
<br />
/trunk/doc/index.html
New file
0,0 → 1,82
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Generated Documentation</title>
<link rel="stylesheet" type="text/css" id="layout"
href="media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="classtrees_default.html">Class
Tree: default</a> ] [ <a href="elementindex_default.html">Index: default</a>
] [ <a href="elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="li_default.html">default</a></p>
<p><a href="li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="default/_index.php.html"> index.php </a><br>
<a href="default/_modeles---ListeAdmin.php.html"> ListeAdmin.php </a><br>
<a href="default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php </a><br>
<a href="default/_bibliotheque---Registre.php.html"> Registre.php </a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="default/Controleur.html"> Controleur </a><br>
<a href="default/GestionnaireException.html"> GestionnaireException
</a><br>
<a href="default/listeAdmin.html"> listeAdmin </a><br>
<a href="default/Modele.html"> Modele </a><br>
<a href="default/Net_URL.html"> Net_URL </a><br>
<a href="default/Net_URL2.html"> Net_URL2 </a><br>
<a href="default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<div align="center">
<h1>Generated Documentation</h1>
</div>
<b>Welcome to default!</b><br />
<br />
This documentation was generated by <a href="http://www.phpdoc.org">phpDocumentor
v1.4.1</a><br />
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/doc/li_default.html
New file
0,0 → 1,82
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Generated Documentation</title>
<link rel="stylesheet" type="text/css" id="layout"
href="media/layout.css" media="screen">
<link rel="stylesheet" type="text/css" href="media/style.css"
media="all">
<link rel="stylesheet" type="text/css" href="media/print.css"
media="print">
</head>
 
<body>
<div id="header">
<div id="navLinks">[ <a href="classtrees_default.html">Class
Tree: default</a> ] [ <a href="elementindex_default.html">Index: default</a>
] [ <a href="elementindex.html">All elements</a> ]</div>
<div id="packagePosition">
<div id="packageTitle2">default</div>
<div id="packageTitle">default</div>
<div id="elementPath">&middot;</div>
</div>
</div>
 
<div id="nav" class="small">
<div id="packages">Packages:
<p><a href="li_default.html">default</a></p>
<p><a href="li_eFlore.html">eFlore</a></p>
</div>
 
<div id="index">
<div id="files">Files:<br>
<a href="default/_controleurs---AdminAdministrateur.php.html">
AdminAdministrateur.php </a><br>
<a href="default/_admin_administrateur.php.html">
admin_administrateur.php </a><br>
<a href="default/_autoload.inc.php.html"> autoload.inc.php </a><br>
<a href="default/_configuration---config.inc.php.html">
config.inc.php </a><br>
<a href="default/_configuration---config_chemin.inc.php.html">
config_chemin.inc.php </a><br>
<a href="default/_bibliotheque---Controleur.php.html">
Controleur.php </a><br>
<a href="default/_bibliotheque---GestionnaireException.php.html">
GestionnaireException.php </a><br>
<a href="default/_index.php.html"> index.php </a><br>
<a href="default/_modeles---ListeAdmin.php.html"> ListeAdmin.php </a><br>
<a href="default/_bibliotheque---Modele.php.html"> Modele.php </a><br>
<a href="default/_bibliotheque---Net_URL.php.html"> Net_URL.php </a><br>
<a href="default/_bibliotheque---Net_URL2.php.html"> Net_URL2.php </a><br>
<a href="default/_bibliotheque---Registre.php.html"> Registre.php </a><br>
</div>
<div id="interfaces"></div>
<div id="classes">Classes:<br>
<a href="default/AdminAdministrateur.html"> AdminAdministrateur </a><br>
<a href="default/Controleur.html"> Controleur </a><br>
<a href="default/GestionnaireException.html"> GestionnaireException
</a><br>
<a href="default/listeAdmin.html"> listeAdmin </a><br>
<a href="default/Modele.html"> Modele </a><br>
<a href="default/Net_URL.html"> Net_URL </a><br>
<a href="default/Net_URL2.html"> Net_URL2 </a><br>
<a href="default/Registre.html"> Registre </a><br>
</div>
</div>
</div>
 
<div id="body">
<div align="center">
<h1>Generated Documentation</h1>
</div>
<b>Welcome to default!</b><br />
<br />
This documentation was generated by <a href="http://www.phpdoc.org">phpDocumentor
v1.4.1</a><br />
<div id="credit">
<hr>
Documentation generated on Thu, 02 Apr 2009 10:23:02 +0200 by <a
href="http://www.phpdoc.org">phpDocumentor 1.4.1</a></div>
</div>
</body>
</html>
/trunk/file.php
New file
0,0 → 1,13
<?php
/**
* PHP Version 5
*
* @category PHP
* @package Framework
* @author aurelien <aurelien@tela-botanica.org>
* @copyright 2009 Tela-Botanica
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
* @version SVN: <svn_id>
* @link /doc/framework/
*/
?>
/trunk/autoload.inc.php
New file
0,0 → 1,47
<?php
/**
* Fichier contenant la fonction de chargement automatique
* de classes, il doit toujours rester à la racine
* du framework car il initialise le chemin de
* l'application en se basant sur son propre emplacement.
*/
 
// on définit le chemin de base de l'application
if (!defined('CHEMIN_APPLI')) {
define('CHEMIN_APPLI',dirname(__FILE__).DIRECTORY_SEPARATOR);
}
 
// appel des deux fichiers de configuration
require_once 'configuration/config.inc.php';
require_once 'configuration/config_chemin.inc.php';
 
/**
* La fonction __autoload() charge dynamiquement les
* classes trouvées dans le code.
*
* Cette fonction est appelée par php5 quand il trouve
* une instanciation de classe dans le code.
*
*@param string $classe nom de la classe appelée.
*@return void le fichier contenant la classe .
*/
function __autoload($classe)
{
/* les dossiers dans lequels on cherche sont ceux
*initialisés dans les fichiers de configuration
*TODO: faire un tableau qui soit contenu dans le
*fichier de configuration pour que les utilisateurs
* puissent rajouter les leur .
*/
$dossiers_classes = array(CHEMIN_BIBLIO.DIRECTORY_SEPARATOR,
DOSSIER_CONTROLEURS.DIRECTORY_SEPARATOR,
DOSSIER_MODELES.DIRECTORY_SEPARATOR);
foreach ($dossiers_classes as $chemin) {
if (file_exists($fichier_a_tester = $chemin.$classe.'.php')) {
include_once $fichier_a_tester;
return null;
}
}
}
?>
/trunk/configuration/config.inc.php
New file
0,0 → 1,37
<?php
 
// +------------------------------------------------------------------------------------------------------+
// URL
/** Constante URL de base de l'application, si elle est laissée vide, l'application fonctionnera en Stand-alone */
if(!defined('URL_BASE')) {
define('URL_BASE','') ;
}
 
/** Variable à tester pour l'identification, mettre à true si l'application ne nécessite pas de s'identifier **/
define('VAR_IDENT',true) ;
 
// +------------------------------------------------------------------------------------------------------+
// Débogage
/** Constante stockant si oui ou non on veut afficher le débogage.*/
define('SC_DEBOGAGE', true);
/** Constante stockant si oui ou non on veut afficher le contexte de débogage.*/
define('SC_DEBOGAGE_CONTEXTE', false);
/** Constante stockant une valeur correspondant au niveau d'erreur à employer pour le code PHP.*/
define('SC_DEBOGAGE_NIVEAU', 2048);// Voir le manuel de PHP pour les différents niveaux disponibles.
/** Constante stockant si oui ou nom on veut afficher le tableau de chronométrage de l'application.*/
define('SC_DEBOGAGE_CHRONO', true);
ini_set('html_errors', true);
 
// +------------------------------------------------------------------------------------------------------+
// Paramétrage de la base de données.
/** Constante stockant le protocole de la base de données.*/
define('BDD_PROTOCOLE', 'mysql');
/** Constante stockant le nom du serveur de bases de données.*/
define('BDD_SERVEUR', 'localhost');
/** Constante stockant le nom de l'utilisateur de la base de données.*/
define('BDD_UTILISATEUR', 'root');
/** Constante stockant le mot de passse de l'utilisateur de la base de données.*/
define('BDD_MOT_DE_PASSE', 'Canard123$');
/** Constante stockant le nom de la base de données principale.*/
define('BDD_NOM_PRINCIPALE', 'papyrus_bp');
?>
/trunk/configuration/config_chemin.inc.php
New file
0,0 → 1,11
<?php
// Définition des chemins de fichiers.
/** Constante stockant le chemin vers le dossier bibliothèque, contenant les classes systèmes **/
define('CHEMIN_BIBLIO',CHEMIN_APPLI.'bibliotheque');
/** Constante stockant le chemin vers le dossier controleurs.*/
define('DOSSIER_CONTROLEURS', CHEMIN_APPLI.'controleurs');
/** Constante stockant le chemin vers le dossier modèles.*/
define('DOSSIER_MODELES', CHEMIN_APPLI.'modeles');
/** Constante stockant le chemin vers le dossier squelettes.*/
define('DOSSIER_SQUELETTES', CHEMIN_APPLI.'squelettes');
?>
/trunk/modeles/ListeAdmin.php
New file
0,0 → 1,250
<?php
 
/**
* Modèle d'accès à la base de données des administrateurs
* de papyrus
*/
class listeAdmin extends Modele {
var $config = array() ;
/**
* Charge la liste complète des administrateurs
* return array un tableau contenant des objets d'informations sur les administrateurs
* @return array un tableau d'objets contenant la liste des administrateurs
*/
function chargerAdmin() {
$query = 'SELECT * FROM gen_annuaire ORDER BY ga_id_administrateur' ;
$res = $this->requete($query) ;
$admin = array() ;
foreach ($res->fetchAll() as $ligne)
{
if($ligne['ga_id_administrateur'] != 0) {
$admin[] = $ligne ;
}
}
return $admin ;
}
/**
* Charge les informations liées à un administrateur
* grâce à son id
* @param int l'identifiant de l'administrateur.
* @return object un object contenant les informations de l'administrateur demandé
*/
function loadDetailsAdmin($id) {
$query = 'SELECT * FROM gen_annuaire where ga_id_administrateur="'.$id.'"' ;
$res = $this->requete($query) ;
$admin = array() ;
foreach ($res->fetchAll() as $ligne) {
$admin = $ligne ;
}
return $admin ;
}
/**
* Modifie les informations liées à un administrateur dans la base de données
* Si le mot de passe n'est pas renseigné, il n'est pas changé
* @param int identifiant de l'admiistrateur
* @param string nom
* @param string prenom
* @param string le mail
* @param string le code de langue
* @param string le mot de passe (optionnel)
* @param string la confirmation du mot de passe (optionnel)
* @return array un tableau contenant les erreurs s'il y en a, vide sinon
*/
function modifDetailsAdmin($id,$nom,$prenom,$mail,$lang,$pass='',$pass_conf='') {
$res = array() ;
$nb_admin = 0 ;
if(!$this->validerMail($mail)) {
$res['mail'] = 'Adresse mail invalide' ;
}
$query_verif_mail = 'SELECT COUNT(*) AS nb_admin FROM gen_annuaire WHERE ga_mail = '.$this->proteger($mail).' AND ga_id_administrateur !='.$id ;
if($res_nb = $this->requete($query_verif_mail)) {
$ligne = $res_nb->fetch();
$nb_admin = $ligne['nb_admin'] ;
} else {
$res['bdd'] = 'Erreur dans la base de données' ;
return $res ;
}
if($nb_admin != 0) {
$res['mail'] = 'Cet email est déjà utilisé par un autre utilisateur' ;
}
$query = 'UPDATE gen_annuaire SET ga_ce_i18n='.$this->proteger($lang).', ga_nom='.$this->proteger($nom).',ga_prenom='.
$this->proteger($prenom).',ga_mail='.$this->proteger($mail) ;
// si on a entré quelque chose dans les deux champs de mot de passe
if($pass != '' || $pass_conf != '') {
// on vérifie si les deux concordent
if($pass == $pass_conf) {
// si oui, on les modifie
$query .= ',ga_mot_de_passe='.$this->proteger(md5($pass)) ;
} else {
// si non, on notifiera l'utilisateur
$res['pass'] = 'mot de passe invalide' ;
}
}
 
$query .= ' WHERE ga_id_administrateur='.$id ;
if(count($res) != 0) {
return $res ;
}
if($req_maj = $this->requete($query)) {
} else {
$res['bdd'] = 'Erreur de la requête dans la base de données' ;
}
return $res ;
}
/**
* Supprime un administrateur ayant un id donnée
* @param int l'identifiant de l'administrateur
* @return array un tableau contenant les erreurs s'il y en a, vide sinon
*/
function suppAdmin($id) {
$nb_admin = 0 ;
$res = '' ;
$query_verif = 'SELECT COUNT(*) AS nb_admin FROM gen_annuaire' ;
if($res_nb = $this->requete($query_verif)) {
$ligne = $res_nb->fetch();
$nb_admin = $ligne['nb_admin'] ;
} else {
$res = 'Erreur dans la base de données' ;
return $res ;
}
if($nb_admin == 2) {
$res = 'Impossible de supprimer le dernier administrateur' ;
return $res ;
}
$query = 'DELETE FROM gen_annuaire WHERE ga_id_administrateur='.$id ;
if($res_supp = $this->requete($query)) {
return $res ;
} else {
$res = 'Erreur dans la base de données' ;
return $res ;
}
}
/**
* Ajoute un administrateur dans la base de données
* @param string nom
* @param string prenom
* @param string le mail
* @param string le code de langue
* @param string le mot de passe
* @param string la confirmation du mot de passe
* @return array un tableau contenant les erreurs s'il y en a, vide sinon
*/
function ajoutAdmin($nom,$prenom,$mail,$lang,$pass,$pass_conf) {
$nouvel_id = 0 ;
$nb_admin = 0 ;
$res = array() ;
if(!$this->validerMail($mail)) {
$res['mail'] = 'adresse mail invalide' ;
}
$query_verif_mail = 'SELECT COUNT(*) AS nb_admin FROM gen_annuaire WHERE ga_mail = '.$this->proteger($mail) ;
if($res_nb = $this->requete($query_verif_mail)) {
$ligne = $res_nb->fetch() ;
$nb_admin = $ligne['nb_admin'] ;
} else {
$res['bdd'] = 'Erreur dans la base de données' ;
return $res ;
}
if($nb_admin != 0) {
$res['mail'] = 'Cet email est déjà utilisé par un autre utilisateur' ;
}
if($pass != '' || $pass_conf != '') {
// on vérifie si les deux concordent
if($pass == $pass_conf) {
} else {
// si non, on notifiera l'utilisateur
$res['pass'] = 'mot de passe invalide' ;
}
}
$query = 'SELECT MAX(ga_id_administrateur) as nouvel_id FROM gen_annuaire' ;
if($res_requete_id = $this->requete($query)) {
$ligne = $res_requete_id->fetch() ;
$nouvel_id = $ligne['nouvel_id'] + 1 ;
} else {
return $res ;
}
$query = 'INSERT INTO gen_annuaire VALUES ('.$nouvel_id.','.$this->proteger($lang).','.
$this->proteger($nom).','.$this->proteger($prenom).','.$this->proteger(md5($pass)).','.
$this->proteger($mail).')' ;
if(count($res) != 0) {
return $res ;
}
if($res_ajout = $this->requete($query)) {
} else {
$res['bdd'] = 'Erreur de la requête dans la base de données' ;
}
return $res ;
}
/**
* Fonction qui prend une chaine en paramètre et renvoie vrai
* si elle constitue un email syntaxiquement valide, faux sinon.
* @param string le mail à valider
* @return bool true si le mail est valide, false sinon
*/
function validerMail($mail) {
$atom = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]'; // caractères autorisés avant l'arobase
$domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // caractères autorisés après l'arobase (nom de domaine)
$regex = '/^' . $atom . '+' . // Une ou plusieurs fois les caractères autorisés avant l'arobase
'(\.' . $atom . '+)*' . // Suivis par zéro point ou plus
// séparés par des caractères autorisés avant l'arobase
'@' . // Suivis d'un arobase
'(' . $domain . '{1,63}\.)+' . // Suivis par 1 à 63 caractères autorisés pour le nom de domaine
// séparés par des points
$domain . '{2,63}$/i'; // Suivi de 2 à 63 caractères autorisés pour le nom de domaine
// test de l'adresse e-mail
if (preg_match($regex, $mail)) {
return true ;
} else {
return false ;
}
}
 
}
?>
/trunk/admin_administrateur.php
New file
0,0 → 1,107
<?php
/**
* @category PHP
* @package Framework
* @author aurelien <aurelien@tela-botanica.org>
* @copyright Tela-Botanica 2009
* @link /doc/framework/
* Ceci est un exemple d'application qui permet d'illustrer
* le fonctionnement du framework, il montre comment une application
* peut être dans papyrus, ou bien utilisée en stand alone
*/
// la fonction autolad doit être appelée avant
//tout autre chose dans l'application
require_once 'autoload.inc.php';
 
/**
* Fonction d'affichage de Papyrus, pour le corps de page
*/
function afficherContenuCorps()
{
// si l'utilisateur est authentifié
if (VAR_IDENT) {
// on renvoie la vue principale de l'application
$methode = '' ;
if (isset($_GET['m'])) {
$methode = $_GET['m'] ;
}
$controlleur = new AdminAdministrateur();
switch($methode) {
case 'ajout_admin':
return $controlleur->ajoutAdmin();
break;
case 'ajout_admin_va':
$nom = $_POST['admin_nom'] ;
$prenom = $_POST['admin_prenom'] ;
$mail = $_POST['admin_mail'] ;
$lang = $_POST['admin_lang'] ;
$pass = $_POST['admin_pass'] ;
$pass_conf = $_POST['admin_pass_confirm'] ;
return $controlleur->ajoutAdminVa($nom,$prenom,$mail,$lang,$pass,$pass_conf);
break;
case 'modif_admin':
$id = $_GET['id_admin'];
return $controlleur->modifAdmin($id);
break;
case 'modif_admin_va':
$id = $_GET['id_admin'];
$nom = $_POST['admin_nom'];
$prenom = $_POST['admin_prenom'];
$mail = $_POST['admin_mail'];
$lang = $_POST['admin_lang'];
$pass = $_POST['admin_pass'];
$pass_conf = $_POST['admin_pass_confirm'];
return $controlleur->modifAdminVa($id,$nom,$prenom,$mail,$lang,$pass,$pass_conf);
break;
case 'suppr_admin':
$id = $_GET['id_admin'];
return $controlleur->supprAdmin($id);
break;
default:
return $controlleur->chargerAdmin();
break;
}
} else {
// sinon on lui demande de s'identifier
$controlleur = new AdminAdministrateur() ;
return $controlleur->demanderIdent() ;
}
}
 
function afficherContenuTete() {
$controlleur = new AdminAdministrateur();
return $controlleur->adminTete();
}
 
function afficherContenuPied() {
$controlleur = new AdminAdministrateur();
return $controlleur->adminPied();
}
 
 
if(!defined('PAP_VERSION')) {
echo afficherContenuTete();
echo afficherContenuCorps();
echo afficherContenuPied();
}
/*
* afficherContenuTete()
* afficherContenuNavigation()
* afficherContenuMenu()
* afficherContenuPied()
*
*/
 
?>
/trunk/bibliotheque/GestionnaireException.php
New file
0,0 → 1,122
<?php
/*
* Created on 27 mars 2009
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
/**
* Classe GestionnaireException, gère les exceptions
*/
class GestionnaireException {
/**
* Liste des exceptions enregistrées
*/
private $exceptions;
/**
* Détermine si l'on affiche ou nom le contexte
*/
private $contexte;
/**
* Definit si php est lancé en ligne de commande ou en mode serveur
*/
private $mode;
/**
* le gestionnaire d'exception est un singleton
* et possède donc un "pointeur statique sur lui-même"
*/
private static $gestionnaireException ;
/**
* Constructeur avec paramètres optionnel
* @param bool indique si l'on veut afficher ou non le contexte des exceptions (i.e. la trace)
*/
public function __construct($contexte = false) {
$this->exceptions = array();
$this->contexte = $contexte;
$this->mode = php_sapi_name();
set_exception_handler(array($this,'gererException'));
}
/**
* Renvoie le booleen définissant si l'on affiche le contexte ou non
*/
public function getContexte() {
return $this->contexte;
}
/**
* Definit si l'on veut afficher le contexte ou non
* @param bool true si on veut afficher le contexte, false sinon, par défaut vaut false
*/
public function setContexte($contexte) {
$this->contexte = $contexte;
}
/** Fonction d'accès au singleton
* @return GestionnaireErreur le gestionnaire d'exceptions courant
*/
public static function getInstance()
{
if (self::$gestionnaireException instanceof GestionnaireException) {
return self::$gestionnaireException;
}
self::$gestionnaireException = new GestionnaireException;
return self::$gestionnaireException;
}
/**
* Fonction de gestion des exceptions, remplace le handler par défaut
*/
public static function gererException(Exception $e) {
// pour le moment on se contente de l'ajouter au tableau
$this->exceptions[] = $e;
}
/**
* Renvoie les exceptions au format (X)HTML
* ou bien au format texte suivant le mode d'utilisation de PHP
*/
public function getExceptions() {
foreach ($this->exceptions as $e) {
switch($this->mode) {
case 'cli' :
$retour .= '<pre class="debogage">'."\n";
$retour .= htmlentities($e->getMessage())."\n";
$retour .= '<span class="debogage_fichier">'.'Fichier : '.$e->getFile().'</span>'."\n";
$retour .= '<span class="debogage_ligne">'.'Ligne : '.$e->getLine().'</span>'."\n";
$retour .= '</pre>'."\n";
if ($this->getContexte()) {
$retour .= '<pre>'."\n";
$retour .= '<strong>Contexte : </strong>'."\n".print_r($e->getTraceAsString(), true)."\n";
$retour .= '</pre>'."\n";
}
break;
default:
$retour .= $e->getMessage()."\n";
$retour .= 'Fichier : '.$e->getFile()."\n";
$retour .= 'Ligne : '.$e->getLine()."\n";
$retour .= 'Message : '.$e->getMessage()."\n";
$retour .= 'Fichier : '.$e->getFile()."\n";
$retour .= 'Ligne : '.$e->getLine()."\n";
if ($this->getContexte()) {
$retour .= 'Contexte : '."\n".print_r($e->getTraceAsString(), true)."\n";
}
}
}
return $retour;
}
 
}
?>
/trunk/bibliotheque/Net_URL.php
New file
0,0 → 1,490
<?php
// +-----------------------------------------------------------------------+
// | Copyright (c) 2002-2004, Richard Heyes |
// | All rights reserved. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | o Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | o Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution.|
// | o The names of the authors may not be used to endorse or promote |
// | products derived from this software without specific prior written |
// | permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
// | |
// +-----------------------------------------------------------------------+
// | Author: Richard Heyes <richard at php net> |
// +-----------------------------------------------------------------------+
//
// $Id: URL.php,v 1.3 2007-11-19 14:06:54 alexandre_tb Exp $
//
// Net_URL Class
 
 
class Net_URL
{
var $options = array('encode_query_keys' => false);
/**
* Full url
* @var string
*/
var $url;
 
/**
* Protocol
* @var string
*/
var $protocol;
 
/**
* Username
* @var string
*/
var $username;
 
/**
* Password
* @var string
*/
var $password;
 
/**
* Host
* @var string
*/
var $host;
 
/**
* Port
* @var integer
*/
var $port;
 
/**
* Path
* @var string
*/
var $path;
 
/**
* Query string
* @var array
*/
var $querystring;
 
/**
* Anchor
* @var string
*/
var $anchor;
 
/**
* Whether to use []
* @var bool
*/
var $useBrackets;
 
/**
* PHP4 Constructor
*
* @see __construct()
*/
function Net_URL($url = null, $useBrackets = true)
{
$this->__construct($url, $useBrackets);
}
 
/**
* PHP5 Constructor
*
* Parses the given url and stores the various parts
* Defaults are used in certain cases
*
* @param string $url Optional URL
* @param bool $useBrackets Whether to use square brackets when
* multiple querystrings with the same name
* exist
*/
function __construct($url = null, $useBrackets = true)
{
$this->url = $url;
$this->useBrackets = $useBrackets;
 
$this->initialize();
}
 
function initialize()
{
$HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
 
$this->user = '';
$this->pass = '';
$this->host = '';
$this->port = 80;
$this->path = '';
$this->querystring = array();
$this->anchor = '';
 
// Only use defaults if not an absolute URL given
if (!preg_match('/^[a-z0-9]+:\/\//i', $this->url)) {
$this->protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http');
 
/**
* Figure out host/port
*/
if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) &&
preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches))
{
$host = $matches[1];
if (!empty($matches[3])) {
$port = $matches[3];
} else {
$port = $this->getStandardPort($this->protocol);
}
}
 
$this->user = '';
$this->pass = '';
$this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost');
$this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol));
$this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/';
$this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null;
$this->anchor = '';
}
 
// Parse the url and store the various parts
if (!empty($this->url)) {
$urlinfo = parse_url($this->url);
 
// Default querystring
$this->querystring = array();
 
foreach ($urlinfo as $key => $value) {
switch ($key) {
case 'scheme':
$this->protocol = $value;
$this->port = $this->getStandardPort($value);
break;
 
case 'user':
case 'pass':
case 'host':
case 'port':
$this->$key = $value;
break;
 
case 'path':
if ($value{0} == '/') {
$this->path = $value;
} else {
$path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path);
$this->path = sprintf('%s/%s', $path, $value);
}
break;
 
case 'query':
$this->querystring = $this->_parseRawQueryString($value);
break;
 
case 'fragment':
$this->anchor = $value;
break;
}
}
}
}
/**
* Returns full url
*
* @return string Full url
* @access public
*/
function getURL()
{
$querystring = $this->getQueryString();
 
$this->url = $this->protocol . '://'
. $this->user . (!empty($this->pass) ? ':' : '')
. $this->pass . (!empty($this->user) ? '@' : '')
. $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port)
. $this->path
. (!empty($querystring) ? '?' . $querystring : '')
. (!empty($this->anchor) ? '#' . $this->anchor : '');
 
return $this->url;
}
 
/**
* Adds or updates a querystring item (URL parameter).
* Automatically encodes parameters with rawurlencode() if $preencoded
* is false.
* You can pass an array to $value, it gets mapped via [] in the URL if
* $this->useBrackets is activated.
*
* @param string $name Name of item
* @param string $value Value of item
* @param bool $preencoded Whether value is urlencoded or not, default = not
* @access public
*/
function addQueryString($name, $value, $preencoded = false)
{
if ($this->getOption('encode_query_keys')) {
$name = rawurlencode($name);
}
 
if ($preencoded) {
$this->querystring[$name] = $value;
} else {
$this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value);
}
}
 
/**
* Removes a querystring item
*
* @param string $name Name of item
* @access public
*/
function removeQueryString($name)
{
if ($this->getOption('encode_query_keys')) {
$name = rawurlencode($name);
}
 
if (isset($this->querystring[$name])) {
unset($this->querystring[$name]);
}
}
 
/**
* Sets the querystring to literally what you supply
*
* @param string $querystring The querystring data. Should be of the format foo=bar&x=y etc
* @access public
*/
function addRawQueryString($querystring)
{
$this->querystring = $this->_parseRawQueryString($querystring);
}
 
/**
* Returns flat querystring
*
* @return string Querystring
* @access public
*/
function getQueryString()
{
if (!empty($this->querystring)) {
foreach ($this->querystring as $name => $value) {
// Encode var name
$name = rawurlencode($name);
 
if (is_array($value)) {
foreach ($value as $k => $v) {
$querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v);
}
} elseif (!is_null($value)) {
$querystring[] = $name . '=' . $value;
} else {
$querystring[] = $name;
}
}
$querystring = implode(ini_get('arg_separator.output'), $querystring);
} else {
$querystring = '';
}
 
return $querystring;
}
 
/**
* Parses raw querystring and returns an array of it
*
* @param string $querystring The querystring to parse
* @return array An array of the querystring data
* @access private
*/
function _parseRawQuerystring($querystring)
{
$parts = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY);
$return = array();
 
foreach ($parts as $part) {
if (strpos($part, '=') !== false) {
$value = substr($part, strpos($part, '=') + 1);
$key = substr($part, 0, strpos($part, '='));
} else {
$value = null;
$key = $part;
}
 
if (!$this->getOption('encode_query_keys')) {
$key = rawurldecode($key);
}
 
if (preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) {
$key = $matches[1];
$idx = $matches[2];
 
// Ensure is an array
if (empty($return[$key]) || !is_array($return[$key])) {
$return[$key] = array();
}
 
// Add data
if ($idx === '') {
$return[$key][] = $value;
} else {
$return[$key][$idx] = $value;
}
} elseif (!$this->useBrackets AND !empty($return[$key])) {
$return[$key] = (array)$return[$key];
$return[$key][] = $value;
} else {
$return[$key] = $value;
}
}
 
return $return;
}
 
/**
* Resolves //, ../ and ./ from a path and returns
* the result. Eg:
*
* /foo/bar/../boo.php => /foo/boo.php
* /foo/bar/../../boo.php => /boo.php
* /foo/bar/.././/boo.php => /foo/boo.php
*
* This method can also be called statically.
*
* @param string $path URL path to resolve
* @return string The result
*/
function resolvePath($path)
{
$path = explode('/', str_replace('//', '/', $path));
 
for ($i=0; $i<count($path); $i++) {
if ($path[$i] == '.') {
unset($path[$i]);
$path = array_values($path);
$i--;
 
} elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) {
unset($path[$i]);
unset($path[$i-1]);
$path = array_values($path);
$i -= 2;
 
} elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') {
unset($path[$i]);
$path = array_values($path);
$i--;
 
} else {
continue;
}
}
 
return implode('/', $path);
}
 
/**
* Returns the standard port number for a protocol
*
* @param string $scheme The protocol to lookup
* @return integer Port number or NULL if no scheme matches
*
* @author Philippe Jausions <Philippe.Jausions@11abacus.com>
*/
function getStandardPort($scheme)
{
switch (strtolower($scheme)) {
case 'http': return 80;
case 'https': return 443;
case 'ftp': return 21;
case 'imap': return 143;
case 'imaps': return 993;
case 'pop3': return 110;
case 'pop3s': return 995;
default: return null;
}
}
 
/**
* Forces the URL to a particular protocol
*
* @param string $protocol Protocol to force the URL to
* @param integer $port Optional port (standard port is used by default)
*/
function setProtocol($protocol, $port = null)
{
$this->protocol = $protocol;
$this->port = is_null($port) ? $this->getStandardPort($protocol) : $port;
}
 
/**
* Set an option
*
* This function set an option
* to be used thorough the script.
*
* @access public
* @param string $optionName The optionname to set
* @param string $value The value of this option.
*/
function setOption($optionName, $value)
{
if (!array_key_exists($optionName, $this->options)) {
return false;
}
 
$this->options[$optionName] = $value;
$this->initialize();
}
 
/**
* Get an option
*
* This function gets an option
* from the $this->options array
* and return it's value.
*
* @access public
* @param string $opionName The name of the option to retrieve
* @see $this->options
*/
function getOption($optionName)
{
if (!isset($this->options[$optionName])) {
return false;
}
 
return $this->options[$optionName];
}
function __toString() {
return $this->url ;
}
 
}
?>
/trunk/bibliotheque/Net_URL2.php
New file
0,0 → 1,817
<?php
// +-----------------------------------------------------------------------+
// | Copyright (c) 2007-2008, Christian Schmidt, Peytz & Co. A/S |
// | All rights reserved. |
// | |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | are met: |
// | |
// | o Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | o Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution.|
// | o The names of the authors may not be used to endorse or promote |
// | products derived from this software without specific prior written |
// | permission. |
// | |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
// | |
// +-----------------------------------------------------------------------+
// | Author: Christian Schmidt <schmidt at php dot net> |
// +-----------------------------------------------------------------------+
//
// $Id: URL2.php,v 1.10 2008/04/26 21:57:08 schmidt Exp $
//
// Net_URL2 Class (PHP5 Only)
 
// This code is released under the BSD License - http://www.opensource.org/licenses/bsd-license.php
/**
* @license BSD License
*/
class Net_URL2
{
/**
* Do strict parsing in resolve() (see RFC 3986, section 5.2.2). Default
* is true.
*/
const OPTION_STRICT = 'strict';
 
/**
* Represent arrays in query using PHP's [] notation. Default is true.
*/
const OPTION_USE_BRACKETS = 'use_brackets';
 
/**
* URL-encode query variable keys. Default is true.
*/
const OPTION_ENCODE_KEYS = 'encode_keys';
 
/**
* Query variable separators when parsing the query string. Every character
* is considered a separator. Default is specified by the
* arg_separator.input php.ini setting (this defaults to "&").
*/
const OPTION_SEPARATOR_INPUT = 'input_separator';
 
/**
* Query variable separator used when generating the query string. Default
* is specified by the arg_separator.output php.ini setting (this defaults
* to "&").
*/
const OPTION_SEPARATOR_OUTPUT = 'output_separator';
 
/**
* Default options corresponds to how PHP handles $_GET.
*/
private $options = array(
self::OPTION_STRICT => true,
self::OPTION_USE_BRACKETS => true,
self::OPTION_ENCODE_KEYS => true,
self::OPTION_SEPARATOR_INPUT => 'x&',
self::OPTION_SEPARATOR_OUTPUT => 'x&',
);
 
/**
* @var string|bool
*/
private $scheme = false;
 
/**
* @var string|bool
*/
private $userinfo = false;
 
/**
* @var string|bool
*/
private $host = false;
 
/**
* @var int|bool
*/
private $port = false;
 
/**
* @var string
*/
private $path = '';
 
/**
* @var string|bool
*/
private $query = false;
 
/**
* @var string|bool
*/
private $fragment = false;
 
/**
* @param string $url an absolute or relative URL
* @param array $options
*/
public function __construct($url, $options = null)
{
$this->setOption(self::OPTION_SEPARATOR_INPUT,
ini_get('arg_separator.input'));
$this->setOption(self::OPTION_SEPARATOR_OUTPUT,
ini_get('arg_separator.output'));
if (is_array($options)) {
foreach ($options as $optionName => $value) {
$this->setOption($optionName);
}
}
 
if (preg_match('@^([a-z][a-z0-9.+-]*):@i', $url, $reg)) {
$this->scheme = $reg[1];
$url = substr($url, strlen($reg[0]));
}
 
if (preg_match('@^//([^/#?]+)@', $url, $reg)) {
$this->setAuthority($reg[1]);
$url = substr($url, strlen($reg[0]));
}
 
$i = strcspn($url, '?#');
$this->path = substr($url, 0, $i);
$url = substr($url, $i);
 
if (preg_match('@^\?([^#]*)@', $url, $reg)) {
$this->query = $reg[1];
$url = substr($url, strlen($reg[0]));
}
 
if ($url) {
$this->fragment = substr($url, 1);
}
}
 
/**
* Returns the scheme, e.g. "http" or "urn", or false if there is no
* scheme specified, i.e. if this is a relative URL.
*
* @return string|bool
*/
public function getScheme()
{
return $this->scheme;
}
 
/**
* @param string|bool $scheme
*
* @return void
* @see getScheme()
*/
public function setScheme($scheme)
{
$this->scheme = $scheme;
}
 
/**
* Returns the user part of the userinfo part (the part preceding the first
* ":"), or false if there is no userinfo part.
*
* @return string|bool
*/
public function getUser()
{
return $this->userinfo !== false ? preg_replace('@:.*$@', '', $this->userinfo) : false;
}
 
/**
* Returns the password part of the userinfo part (the part after the first
* ":"), or false if there is no userinfo part (i.e. the URL does not
* contain "@" in front of the hostname) or the userinfo part does not
* contain ":".
*
* @return string|bool
*/
public function getPassword()
{
return $this->userinfo !== false ? substr(strstr($this->userinfo, ':'), 1) : false;
}
 
/**
* Returns the userinfo part, or false if there is none, i.e. if the
* authority part does not contain "@".
*
* @return string|bool
*/
public function getUserinfo()
{
return $this->userinfo;
}
 
/**
* Sets the userinfo part. If two arguments are passed, they are combined
* in the userinfo part as username ":" password.
*
* @param string|bool $userinfo userinfo or username
* @param string|bool $password
*
* @return void
*/
public function setUserinfo($userinfo, $password = false)
{
$this->userinfo = $userinfo;
if ($password !== false) {
$this->userinfo .= ':' . $password;
}
}
 
/**
* Returns the host part, or false if there is no authority part, e.g.
* relative URLs.
*
* @return string|bool
*/
public function getHost()
{
return $this->host;
}
 
/**
* @param string|bool $host
*
* @return void
*/
public function setHost($host)
{
$this->host = $host;
}
 
/**
* Returns the port number, or false if there is no port number specified,
* i.e. if the default port is to be used.
*
* @return int|bool
*/
public function getPort()
{
return $this->port;
}
 
/**
* @param int|bool $port
*
* @return void
*/
public function setPort($port)
{
$this->port = intval($port);
}
 
/**
* Returns the authority part, i.e. [ userinfo "@" ] host [ ":" port ], or
* false if there is no authority none.
*
* @return string|bool
*/
public function getAuthority()
{
if (!$this->host) {
return false;
}
 
$authority = '';
 
if ($this->userinfo !== false) {
$authority .= $this->userinfo . '@';
}
 
$authority .= $this->host;
 
if ($this->port !== false) {
$authority .= ':' . $this->port;
}
 
return $authority;
}
 
/**
* @param string|false $authority
*
* @return void
*/
public function setAuthority($authority)
{
$this->user = false;
$this->pass = false;
$this->host = false;
$this->port = false;
if (preg_match('@^(([^\@]+)\@)?([^:]+)(:(\d*))?$@', $authority, $reg)) {
if ($reg[1]) {
$this->userinfo = $reg[2];
}
 
$this->host = $reg[3];
if (isset($reg[5])) {
$this->port = intval($reg[5]);
}
}
}
 
/**
* Returns the path part (possibly an empty string).
*
* @return string
*/
public function getPath()
{
return $this->path;
}
 
/**
* @param string $path
*
* @return void
*/
public function setPath($path)
{
$this->path = $path;
}
 
/**
* Returns the query string (excluding the leading "?"), or false if "?"
* isn't present in the URL.
*
* @return string|bool
* @see self::getQueryVariables()
*/
public function getQuery()
{
return $this->query;
}
 
/**
* @param string|bool $query
*
* @return void
* @see self::setQueryVariables()
*/
public function setQuery($query)
{
$this->query = $query;
}
 
/**
* Returns the fragment name, or false if "#" isn't present in the URL.
*
* @return string|bool
*/
public function getFragment()
{
return $this->fragment;
}
 
/**
* @param string|bool $fragment
*
* @return void
*/
public function setFragment($fragment)
{
$this->fragment = $fragment;
}
 
/**
* Returns the query string like an array as the variables would appear in
* $_GET in a PHP script.
*
* @return array
*/
public function getQueryVariables()
{
$pattern = '/[' .
preg_quote($this->getOption(self::OPTION_SEPARATOR_INPUT), '/') .
']/';
$parts = preg_split($pattern, $this->query, -1, PREG_SPLIT_NO_EMPTY);
$return = array();
 
foreach ($parts as $part) {
if (strpos($part, '=') !== false) {
list($key, $value) = explode('=', $part, 2);
} else {
$key = $part;
$value = null;
}
 
if ($this->getOption(self::OPTION_ENCODE_KEYS)) {
$key = rawurldecode($key);
}
$value = rawurldecode($value);
 
if ($this->getOption(self::OPTION_USE_BRACKETS) &&
preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) {
 
$key = $matches[1];
$idx = $matches[2];
 
// Ensure is an array
if (empty($return[$key]) || !is_array($return[$key])) {
$return[$key] = array();
}
 
// Add data
if ($idx === '') {
$return[$key][] = $value;
} else {
$return[$key][$idx] = $value;
}
} elseif (!$this->getOption(self::OPTION_USE_BRACKETS)
&& !empty($return[$key])
) {
$return[$key] = (array) $return[$key];
$return[$key][] = $value;
} else {
$return[$key] = $value;
}
}
 
return $return;
}
 
/**
* @param array $array (name => value) array
*
* @return void
*/
public function setQueryVariables(array $array)
{
if (!$array) {
$this->query = false;
} else {
foreach ($array as $name => $value) {
if ($this->getOption(self::OPTION_ENCODE_KEYS)) {
$name = rawurlencode($name);
}
 
if (is_array($value)) {
foreach ($value as $k => $v) {
$parts[] = $this->getOption(self::OPTION_USE_BRACKETS)
? sprintf('%s[%s]=%s', $name, $k, $v)
: ($name . '=' . $v);
}
} elseif (!is_null($value)) {
$parts[] = $name . '=' . $value;
} else {
$parts[] = $name;
}
}
$this->query = implode($this->getOption(self::OPTION_SEPARATOR_OUTPUT),
$parts);
}
}
 
/**
* @param string $name
* @param mixed $value
*
* @return array
*/
public function setQueryVariable($name, $value)
{
$array = $this->getQueryVariables();
$array[$name] = $value;
$this->setQueryVariables($array);
}
 
/**
* @param string $name
*
* @return void
*/
public function unsetQueryVariable($name)
{
$array = $this->getQueryVariables();
unset($array[$name]);
$this->setQueryVariables($array);
}
 
/**
* Returns a string representation of this URL.
*
* @return string
*/
public function getURL()
{
// See RFC 3986, section 5.3
$url = "";
 
if ($this->scheme !== false) {
$url .= $this->scheme . ':';
}
 
$authority = $this->getAuthority();
if ($authority !== false) {
$url .= '//' . $authority;
}
$url .= $this->path;
 
if ($this->query !== false) {
$url .= '?' . $this->query;
}
 
if ($this->fragment !== false) {
$url .= '#' . $this->fragment;
}
return $url;
}
 
/**
* Returns a normalized string representation of this URL. This is useful
* for comparison of URLs.
*
* @return string
*/
public function getNormalizedURL()
{
$url = clone $this;
$url->normalize();
return $url->getUrl();
}
 
/**
* Returns a normalized Net_URL2 instance.
*
* @return Net_URL2
*/
public function normalize()
{
// See RFC 3886, section 6
 
// Schemes are case-insensitive
if ($this->scheme) {
$this->scheme = strtolower($this->scheme);
}
 
// Hostnames are case-insensitive
if ($this->host) {
$this->host = strtolower($this->host);
}
 
// Remove default port number for known schemes (RFC 3986, section 6.2.3)
if ($this->port &&
$this->scheme &&
$this->port == getservbyname($this->scheme, 'tcp')) {
 
$this->port = false;
}
 
// Normalize case of %XX percentage-encodings (RFC 3986, section 6.2.2.1)
foreach (array('userinfo', 'host', 'path') as $part) {
if ($this->$part) {
$this->$part = preg_replace('/%[0-9a-f]{2}/ie', 'strtoupper("\0")', $this->$part);
}
}
 
// Path segment normalization (RFC 3986, section 6.2.2.3)
$this->path = self::removeDotSegments($this->path);
 
// Scheme based normalization (RFC 3986, section 6.2.3)
if ($this->host && !$this->path) {
$this->path = '/';
}
}
 
/**
* Returns whether this instance represents an absolute URL.
*
* @return bool
*/
public function isAbsolute()
{
return (bool) $this->scheme;
}
 
/**
* Returns an Net_URL2 instance representing an absolute URL relative to
* this URL.
*
* @param Net_URL2|string $reference relative URL
*
* @return Net_URL2
*/
public function resolve($reference)
{
if (is_string($reference)) {
$reference = new self($reference);
}
if (!$this->isAbsolute()) {
throw new Exception('Base-URL must be absolute');
}
 
// A non-strict parser may ignore a scheme in the reference if it is
// identical to the base URI's scheme.
if (!$this->getOption(self::OPTION_STRICT) && $reference->scheme == $this->scheme) {
$reference->scheme = false;
}
 
$target = new self('');
if ($reference->scheme !== false) {
$target->scheme = $reference->scheme;
$target->setAuthority($reference->getAuthority());
$target->path = self::removeDotSegments($reference->path);
$target->query = $reference->query;
} else {
$authority = $reference->getAuthority();
if ($authority !== false) {
$target->setAuthority($authority);
$target->path = self::removeDotSegments($reference->path);
$target->query = $reference->query;
} else {
if ($reference->path == '') {
$target->path = $this->path;
if ($reference->query !== false) {
$target->query = $reference->query;
} else {
$target->query = $this->query;
}
} else {
if (substr($reference->path, 0, 1) == '/') {
$target->path = self::removeDotSegments($reference->path);
} else {
// Merge paths (RFC 3986, section 5.2.3)
if ($this->host !== false && $this->path == '') {
$target->path = '/' . $this->path;
} else {
$i = strrpos($this->path, '/');
if ($i !== false) {
$target->path = substr($this->path, 0, $i + 1);
}
$target->path .= $reference->path;
}
$target->path = self::removeDotSegments($target->path);
}
$target->query = $reference->query;
}
$target->setAuthority($this->getAuthority());
}
$target->scheme = $this->scheme;
}
 
$target->fragment = $reference->fragment;
 
return $target;
}
 
/**
* Removes dots as described in RFC 3986, section 5.2.4, e.g.
* "/foo/../bar/baz" => "/bar/baz"
*
* @param string $path a path
*
* @return string a path
*/
private static function removeDotSegments($path)
{
$output = '';
 
// Make sure not to be trapped in an infinite loop due to a bug in this
// method
$j = 0;
while ($path && $j++ < 100) {
// Step A
if (substr($path, 0, 2) == './') {
$path = substr($path, 2);
} elseif (substr($path, 0, 3) == '../') {
$path = substr($path, 3);
 
// Step B
} elseif (substr($path, 0, 3) == '/./' || $path == '/.') {
$path = '/' . substr($path, 3);
 
// Step C
} elseif (substr($path, 0, 4) == '/../' || $path == '/..') {
$path = '/' . substr($path, 4);
$i = strrpos($output, '/');
$output = $i === false ? '' : substr($output, 0, $i);
 
// Step D
} elseif ($path == '.' || $path == '..') {
$path = '';
 
// Step E
} else {
$i = strpos($path, '/');
if ($i === 0) {
$i = strpos($path, '/', 1);
}
if ($i === false) {
$i = strlen($path);
}
$output .= substr($path, 0, $i);
$path = substr($path, $i);
}
}
 
return $output;
}
 
/**
* Returns a Net_URL2 instance representing the canonical URL of the
* currently executing PHP script.
*
* @return string
*/
public static function getCanonical()
{
if (!isset($_SERVER['REQUEST_METHOD'])) {
// ALERT - no current URL
throw new Exception('Script was not called through a webserver');
}
 
// Begin with a relative URL
$url = new self($_SERVER['PHP_SELF']);
$url->scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
$url->host = $_SERVER['SERVER_NAME'];
$port = intval($_SERVER['SERVER_PORT']);
if ($url->scheme == 'http' && $port != 80 ||
$url->scheme == 'https' && $port != 443) {
 
$url->port = $port;
}
return $url;
}
 
/**
* Returns the URL used to retrieve the current request.
*
* @return string
*/
public static function getRequestedURL()
{
return self::getRequested()->getUrl();
}
 
/**
* Returns a Net_URL2 instance representing the URL used to retrieve the
* current request.
*
* @return Net_URL2
*/
public static function getRequested()
{
if (!isset($_SERVER['REQUEST_METHOD'])) {
// ALERT - no current URL
throw new Exception('Script was not called through a webserver');
}
 
// Begin with a relative URL
$url = new self($_SERVER['REQUEST_URI']);
$url->scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
// Set host and possibly port
$url->setAuthority($_SERVER['HTTP_HOST']);
return $url;
}
 
/**
* Sets the specified option.
*
* @param string $optionName a self::OPTION_ constant
* @param mixed $value option value
*
* @return void
* @see self::OPTION_STRICT
* @see self::OPTION_USE_BRACKETS
* @see self::OPTION_ENCODE_KEYS
*/
function setOption($optionName, $value)
{
if (!array_key_exists($optionName, $this->options)) {
return false;
}
$this->options[$optionName] = $value;
}
 
/**
* Returns the value of the specified option.
*
* @param string $optionName The name of the option to retrieve
*
* @return mixed
*/
function getOption($optionName)
{
return isset($this->options[$optionName])
? $this->options[$optionName] : false;
}
public function __toString() {
return $this->getURL();
}
}
/trunk/bibliotheque/Controleur.php
New file
0,0 → 1,132
<?php
/**
* Fichier contenant la classe controleur
*
* @category PHP
* @package Framework
* @author aurelien <aurelien@tela-botanica.org>
* @copyright 2009 Tela-Botanica
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
* @version SVN: <svn_id>
* @link /doc/framework/
*/
 
/**
* classe Controlleur, coeur d'une application, c'est normalement la seule classe d'une application
* qui devrait être appelée de l'extérieur.
* Elle est abstraite donc doit obligatoirement être étendue
*
* PHP Version 5
*
* @category Class
* @package Framework
* @author aurelien <aurelien@tela-botanica.org>
* @copyright 2009 Tela-Botanica
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
* @version SVN: <svn_id>
* @link /doc/framework/
*
*/
abstract class Controleur
{
/**
* Registre global, normalement accessible partout
*/
private $_registre;
/**
* Gestionnaire d'exceptions php
*/
private $__gestionnaire_exception;
/**
* Gestionnaire d'erreurs php
*/
private $_gestionnaire_erreur;
/**
* Constructeur par défaut
*/
final public function __construct()
{
$this->registre = Registre::getInstance();
$this->registre->set('chemin_config', CHEMIN_APPLI.'configuration'.DIRECTORY_SEPARATOR);
$this->registre->set('base_chemin_modele', DOSSIER_MODELES.DIRECTORY_SEPARATOR);
$this->registre->set('base_chemin_squelette', DOSSIER_SQUELETTES.DIRECTORY_SEPARATOR);
$this->registre->set('base_chemin_controleur', DOSSIER_CONTROLEURS.DIRECTORY_SEPARATOR);
$this->registre->set('bdd_type', BDD_PROTOCOLE);
$this->registre->set('bdd_hote', BDD_SERVEUR);
$this->registre->set('bdd_nom', BDD_NOM_PRINCIPALE);
$this->registre->set('bdd_utilisateur', BDD_UTILISATEUR);
$this->registre->set('bdd_pass', BDD_MOT_DE_PASSE);
$this->registre->set('base_url_application', new Net_URL2(URL_BASE));
$this->_gestionnaire_exception = GestionnaireException::getInstance();
$this->_gestionnaire_erreur = GestionnaireErreur::getInstance();
}
/**
* Charge un modele donné et le rend disponible sous la forme $this->nom_modele
*
* @param string $nom_modele le nom du modèle à charger
*
* @return boolean false si le chargement à échoué, rien sinon
*/
final protected function chargerModele($nom_modele)
{
$chemin_modele = ($this->registre->get('base_chemin_modele')).$nom_modele.'.php';
if (!file_exists($chemin_modele)) {
return false;
}
include_once $chemin_modele;
if (!class_exists($nom_modele)) {
return false;
}
$this->$nom_modele = new $nom_modele;
}
/**
* Fonction prenant en paramètre le nom d'un squelette et un tableau associatif de données, en extrait les variables, charge le squelette
* et cree une variable de classe contenant les deux combinés.
*
* @param String $nom_squelette le nom du squelette
* @param Array $donnees un tableau associatif contenant les variables a injecter dans la vue
*
* @return boolean false si la vue n'existe pas, rien sinon
*/
final protected function chargerVue($nom_squelette,$donnees)
{
$chemin_squelette = ($this->registre->get('base_chemin_squelette')).$nom_squelette.'.tpl.html';
if (!file_exists($chemin_squelette)) {
return false ;
}
$donnees['base_url'] = $this->registre->get('base_url_application');
// on extrait les variables du tableau de données
extract($donnees);
// et on enclenche la bufferisation de sortie
ob_start();
// si les tags courts sont désactivés
if ((bool) @ini_get('short_open_tag') === false) {
// on remplace les tags par la syntaxe classique avec echo
echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($chemin_squelette))));
} else {
// sinon, on se contente d'inclure le squelette
include $chemin_squelette;
}
// on récupère le buffer et on le vide
$buffer = ob_get_contents();
@ob_end_clean();
// enfin on renvoie le contenu
$this->$nom_squelette = $buffer;
}
}
?>
/trunk/bibliotheque/GestionnaireErreur.php
New file
0,0 → 1,372
<?php
/*vim: set expandtab tabstop=4 shiftwidth=4: */
// +------------------------------------------------------------------------------------------------------+
// | PHP version 5.0.4 |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 2005 Tela Botanica (accueil@tela-botanica.org) |
// +------------------------------------------------------------------------------------------------------+
// | This file is part of eFlore-Debogage. |
// | |
// | Foobar is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation; either version 2 of the License, or |
// | (at your option) any later version. |
// | |
// | Foobar is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with Foobar; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +------------------------------------------------------------------------------------------------------+
// CVS : $Id: GestionnaireErreur.class.php,v 1.6 2007-07-09 18:54:43 jp_milcent Exp $
/**
* Classe de gestion des erreurs.
*
*
*
*@package eFlore
*@subpackage Debogage
//Auteur original :
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org>
//Autres auteurs :
*@author aucun
*@copyright Tela-Botanica 2000-2005
*@version $Revision: 1.6 $ $Date: 2007-07-09 18:54:43 $
// +------------------------------------------------------------------------------------------------------+
*/
 
// +------------------------------------------------------------------------------------------------------+
// | ENTETE du PROGRAMME |
// +------------------------------------------------------------------------------------------------------+
 
 
// +------------------------------------------------------------------------------------------------------+
// | CORPS du PROGRAMME |
// +------------------------------------------------------------------------------------------------------+
 
 
/**
* Classe GestionnaireErreur
*
* Gérer les erreurs PHP et SQL.
*/
class GestionnaireErreur
{
/*** Attributes: ***/
 
/**
* Permet de savoir si on utilise PHP en ligne de commande dans une console (PHP-CLI) ou en mode module de serveur.
* @access private
*/
private $mode;
 
/**
* Contient la liste des erreurs.
* @access private
*/
private $erreurs;
 
/**
* Permet de savoir si on veut faire apparaître ou pas le contexte de l'erreur,
* c'est à dire le contenu des variables.
* @access private
*/
private $contexte;
/**
* Contient le niveau d'erreur courant. Celui que l'on donne à la fonction
* error_reporting().
* @access private
*/
private $niveau_erreur_courant;
/**
* Le gestionnaire d'erreur est un singleton
*/
private static $gestionnaire_erreurs;
/*** Constructeur: ***/
/**
* Construit le gestionnaire d'erreur.
*
* @return void
* @access public
*/
private function __construct( $contexte = false )
{
$this->mode = php_sapi_name();
$this->erreurs = array();
$this->setContexte($contexte);
$this->niveau_erreur_courant = 2048 ;
set_error_handler(array(&$this, 'gererErreur'));
}
/**
* Fonction d'accès au singleton
* @return GestionnaireErreur le gestionnaire d'erreurs courant
*/
public static function getInstance()
{
if (self::$gestionnaire_erreurs instanceof GestionnaireErreur) {
return self::$gestionnaire_erreurs;
}
self::$gestionnaire_erreurs = new GestionnaireErreur ;
return self::$gestionnaire_erreurs;
}
/*** Accesseurs: ***/
/**
* Récupère le tableau des erreurs.
*
* @return array
* @access public
*/
public function getErreur( ) {
return $this->erreurs;
}
 
/**
* Ajoute une erreur à la liste.
*
* @param array une_erreur
* @return void
* @access public
*/
public function setErreur( $une_erreur ) {
$this->erreurs[] = $une_erreur;
}
 
/**
* Récupère la valeur du contexte.
*
* @return boolean
* @access public
*/
public function getContexte( ) {
return $this->contexte;
}
 
/**
* Définit si oui ou non le contexte sera affiché.
*
* @param boolean un_contexte
* @return void
* @access public
*/
public function setContexte( $un_contexte ) {
$this->contexte = $un_contexte;
}
/**
* Récupère le niveau d'erreur courrant.
*
* @return int le niveau d'erreur courrant.
* @access public
*/
public function getNiveauErreurCourant( ) {
return (int)$this->niveau_erreur_courant;
}
 
/**
* Définit le niveau d'erreur courrant.
*
* @param int un niveau d'erreur.
* @return void
* @access public
*/
public function setNiveauErreurCourant( $niveau = 2048 ) {
$this->niveau_erreur_courant = $niveau;
}
/**
* Définit le niveau d'erreur courrant (synonyme fonction precedente)
*
* @param int un niveau d'erreur.
* @return void
* @access public
*/
public function setActive ($niveau) {
$this->niveau_erreur_courant = $niveau;
}
/*** Méthodes : ***/
/**
*
* @param int niveau
* @param string message
* @param string fichier
* @param int ligne
* @param boolean contexte
* @return void
* @access public
*/
public function gererErreur($niveau, $message, $fichier, $ligne, $contexte)
{
$aso_erreur = array();
// Nous vérifions si nous affichons ou pas l'erreur en fonction du niveau demandé
if ( $niveau <= $this->getNiveauErreurCourant() ) {
$aso_erreur['niveau'] = $niveau;
switch ($niveau) {
case E_USER_NOTICE :
if (is_array($message) || is_object($message)) {
$aso_erreur['message'] = print_r($message, true);
} else {
$aso_erreur['message'] = $message;
}
break;
default:
$aso_erreur['message'] = $message;
}
$aso_erreur['fichier'] = $fichier;
$aso_erreur['ligne'] = $ligne;
if ($this->getContexte()) {
$aso_erreur['contexte'] = $contexte;
}
$this->setErreur($aso_erreur);
}
echo print_r($this->erreurs,true) ;
exit() ;
// Si nous avons à faire à une erreur et non à un warning ou une notice, nous arrêtons l'exécution du script
switch ($niveau) {
case E_ERROR :
case E_USER_ERROR :
die($this->retournerErreur());
break;
}
}
 
/**
* Retourne l'erreur PHP formatée en XHTML.
*
* @return string
* @access public
*/
public function retournerErreur()
{
$retour = '';
foreach($this->getErreur() as $aso_erreur) {
if ('<!-- BEGIN sql -->' == substr($aso_erreur['message'], 0, 18)) {
$retour .= $aso_erreur['message'];
continue;
}
 
switch ($this->mode) {
case 'cli' :
if ($aso_erreur['niveau'] == E_USER_NOTICE) {
$retour .= $aso_erreur['message']."\n";
$retour .= 'Fichier : '.$aso_erreur['fichier']."\n";
$retour .= 'Ligne : '.$aso_erreur['ligne']."\n";
} else if ($aso_erreur['niveau'] <= 512) {
$retour .= 'INFO : Niveau '.$aso_erreur['niveau']."\n";
} else {
$retour .= 'ERREUR : Niveau '.$aso_erreur['niveau']."\n";
}
$retour .= 'Niveau : '.$aso_erreur['niveau']."\n";
$retour .= 'Message : '.$aso_erreur['message']."\n";
$retour .= 'Fichier : '.$aso_erreur['fichier']."\n";
$retour .= 'Ligne : '.$aso_erreur['ligne']."\n";
if ($this->getContexte()) {
$retour .= 'Contexte : '."\n".print_r($aso_erreur['contexte'], true)."\n";
}
break;
default:
if ($aso_erreur['niveau'] == E_USER_NOTICE) {
$retour .= '<pre class="debogage">'."\n";
$retour .= htmlentities($aso_erreur['message'])."\n";
$retour .= '<span class="debogage_fichier">'.'Fichier : '.$aso_erreur['fichier'].'</span>'."\n";
$retour .= '<span class="debogage_ligne">'.'Ligne : '.$aso_erreur['ligne'].'</span>'."\n";
$retour .= '</pre>'."\n";
continue;
} else if ($aso_erreur['niveau'] <= 512) {
$retour .= '<p class="information">'."\n";
$retour .= '<strong>INFO : Niveau '.$aso_erreur['niveau'].'</strong><br />'."\n";
} else {
$retour .= '<p class="attention">'."\n";
$retour .= '<strong>ERREUR : Niveau '.$aso_erreur['niveau'].'</strong><br />'."\n";
}
$retour .= '<strong>Niveau : </strong>'.$aso_erreur['niveau'].'<br />'."\n";
$retour .= '<strong>Message : </strong>'.$aso_erreur['message'].'<br />'."\n";
$retour .= '<strong>Fichier : </strong>'.$aso_erreur['fichier'].'<br />'."\n";
$retour .= '<strong>Ligne : </strong>'.$aso_erreur['ligne'].'<br />'."\n";
if ($this->getContexte()) {
$retour .= '<pre>'."\n";
$retour .= '<strong>Contexte : </strong>'."\n".print_r($aso_erreur['contexte'], true)."\n";
$retour .= '</pre>'."\n";
}
$retour .= '</p>'."\n";
}
}
return $retour;
}
 
/**
* Retourne l'erreur SQL formatée en XHTML.
*
* @param string fichier
* @param int ligne
* @param string message
* @param string requete
* @param string autres
* @return string
* @static
* @access public
*/
public static function retournerErreurSql( $fichier, $methode, $message, $requete = null, $autres = null )
{
$retour = '';
switch (php_sapi_name()) {
case 'cli' :
$retour .= 'ERREUR SQL '."\n";
$retour .= 'Fichier : '.$fichier."\n";
$retour .= 'Méthode : '.$methode."\n";
$retour .= 'Message : '.$message."\n";
if (!is_null($requete)) {
$retour .= 'Requete : '."\n";
$retour .= $requete."\n";
}
if (!is_null($autres)) {
$retour .= 'Autres infos : '."\n";
$retour .= $autres."\n";
}
break;
default:
$retour .= '<!-- BEGIN sql -->';
$retour .= '<div id="zone_erreur">'."\n";
$retour .= '<h1 > ERREUR SQL </h1><br />'."\n";
$retour .= '<dl>'."\n";
$retour .= '<dt> Fichier : </dt> ';
$retour .= '<dd> '.$fichier.'</dd>'."\n";
$retour .= '<dt> Méthode : </dt> ';
$retour .= '<dd> '.$methode.'</dd>'."\n";
$retour .= '<dt> Message erreur : </dt> ';
$retour .= '<dd> '.$message.'</dd>'."\n";
if (!is_null($requete)) {
$retour .= '<dt> Requete : </dt> ';
$retour .= '<dd> '.$requete.' </dd>'."\n";
}
if (!is_null($autres)) {
$retour .= '<dt> Autres infos : </dt> ';
$retour .= '<dd> '.$autres.' </dd>'."\n";
}
$retour .= '</dl>'."\n";
$retour .= '</div>'."\n";
$retour .= '<!-- END sql -->'."\n";
}
return $retour;
}
}
?>
/trunk/bibliotheque/Registre.php
New file
0,0 → 1,88
<?php
/**
* Classe registre, qui permet un accès à différentes variables à travers les autres classes.
* C'est un singleton
*/
class Registre {
 
/**
* Tableau associatif stockant les variables
*/
private $aso_stock = array();
/**
* La classe registre se contient elle-même, (pour le pattern singleton)
*/
private static $registre;
 
/**
* Constructeur par défaut, privé, car on accède à la classe par le getInstance
*/
private function __construct()
{
$registre = $this;
}
/**
* Fonction qui renvoie l'instance de classe en assurant son unicité, c'est l'unique méthode qui doit être
* utilisé pour récupérer l'objet Registre
*/
public static function getInstance()
{
if (self::$registre instanceof Registre) {
return self::$registre;
}
self::$registre = new Registre;
return self::$registre;
}
/**
* Ajoute un objet au tableau selon un intitulé donné
* @param string l'intitulé sous lequel l'objet sera conservé
* @param mixed l'objet à conserver
*/
function set($intitule, $objet)
{
if (is_array($objet) && isset($this->aso_stock[$intitule])) {
$this->aso_stock[$intitule] = array_merge((array)$this->aso_stock[$intitule], (array)$objet);
$message = "Le tableau $intitule présent dans le registre a été fusionné avec un nouveau tableau de même intitulé !";
trigger_error($message, E_USER_WARNING);
} else {
$this->aso_stock[$intitule] = $objet;
}
}
 
/**
* Renvoie l'objet associé à l'intitulé donné en paramètre
* @return mixed l'objet associé à l'intitulé ou null s'il n'est pas présent
*/
function get($intitule)
{
if (isset($this->aso_stock[$intitule])) {
return $this->aso_stock[$intitule];
}
return null;
}
/**
* Détruit l'objet associé à l'intitulé, n'a pas d'effet si il n'y a pas d'objet associé
*/
function detruire($intitule)
{
if (isset($this->aso_stock[$intitule])) {
unset($this->aso_stock[$intitule]);
}
}
/**
* Teste si un objet est présent sous un intitulé donné
* @return boolean true si un objet associé à cet intitulé est présent, false sinon
*/
public function etrePresent($intitule)
{
if(isset($this->aso_stock[$intitule])){
return true;
}
return false;
}
}
?>
/trunk/bibliotheque/Chronometre.php
New file
0,0 → 1,172
<?php
 
/** Fichier de la classe Chronometre
*
* PHP Version 5
*
* @category PHP
* @package Framework
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @copyright 2009 Tela-Botanica
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
* @version SVN: <svn_id>
* @link /doc/framework/
*/
 
/** Classe Chronometre() - Permet de stocker et d'afficher
* les temps d'éxécution de script.
*
* Cette classe permet de réaliser un ensemble
* de mesure de temps prises à
* différents endroits d'un script.
* Ces mesures peuvent ensuite être affichées au
* sein d'un tableau XHTML.
*
*
* PHP Version 5
*
* @category PHP
* @package Framework
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @copyright 2009 Tela-Botanica
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
* @version Release: <package_version>
* @link /doc/framework/
*/
class Chronometre
{
/*** Attributs : ***/
private $_temps = array ();
 
/** Constructeur : **/
public function __construct()
{
$this->setTemps(
array (
'depart' => microtime()
)
);
}
 
/** Accesseurs :
*
* @param string $cle la cle associée à un chronomètre particulier
*
* @return int le temps écoulé
*/
public function getTemps($cle = null)
{
if (!is_null($cle)) {
return $this->_temps[$cle];
} else {
return $this->_temps;
}
}
 
/** Setteur pour la variable temps
*
* @param array() $moment ajoute des points de chronométrage au tableau _temps
*
* @return null
*/
public function setTemps($moment = array ())
{
array_push($this->_temps, $moment);
}
 
/*** Méthodes : ***/
 
/** Méthode afficherChrono() -
* Permet d'afficher les temps d'éxécution de différentes parties d'un script.
*
* Cette fonction permet d'afficher un ensemble de
* mesure de temps prises à différents endroits d'un script.
* Ces mesures sont affichées au sein d'un tableau XHTML
* dont on peut controler l'indentation des balises.
* Pour un site en production, il suffit d'ajouter un style
* #chrono {display:none;} dans la css. De cette façon,
* le tableau ne s'affichera pas. Le webmaster lui pourra
* rajouter sa propre feuille de style affichant le tableau.
* Le développeur initial de cette fonction est Loic d'Anterroches.
* Elle a été modifiée par Jean-Pascal Milcent.
* Elle utilise une variable gobale : $_CHRONO_
*
* @author Loic d'Anterroches
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
*
* @param int $indentation_origine l'indentation de base.
* @param int $indentation le pas d'indentation.
* @return string la chaine XHTML de mesure des temps.
*/
function afficherChrono($indentation_origine = 8, $indentation = 4) {
// Création du chrono de fin
$GLOBALS['_SCRIPT_']['chrono']->setTemps(array (
'fin' => microtime()
));
 
// Début création de l'affichage
$sortie = str_repeat(' ', $indentation_origine) .
'<table id="chrono" lang="fr" summary="Résultat du
chronométrage du programme affichant la page actuelle.">' . "\n";
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) .
'<caption>Chronométrage</caption>' . "\n";
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) .
'<thead>' . "\n";
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))) .
'<tr><th>Action</th><th>Temps écoulé (en s.)</th>
<th>Cumul du temps écoulé (en s.)</th></tr>' . "\n";
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) .
'</thead>' . "\n";
 
$tbody = str_repeat(' ', ($indentation_origine + ($indentation * 1))) .
'<tbody>' . "\n";
 
$total_tps_ecoule = 0;
 
// Récupération de la première mesure
$tab_depart = & $this->getTemps(0);
list ($usec, $sec) = explode(' ', $tab_depart['depart']);
 
// Ce temps correspond à tps_fin
$tps_debut = ((float) $usec + (float) $sec);
 
foreach ($this->getTemps() as $tab_temps) {
foreach ($tab_temps as $cle => $valeur) {
list ($usec, $sec) = explode(' ', $valeur);
$tps_fin = ((float) $usec + (float) $sec);
 
$tps_ecoule = abs($tps_fin - $tps_debut);
$total_tps_ecoule += $tps_ecoule;
 
$tbody .= str_repeat(' ',
($indentation_origine + ($indentation * 2))) .
'<tr>' .
'<th>' . $cle . '</th>' .
'<td>' . number_format($tps_ecoule, 3, ',', ' ') . '</td>' .
'<td>' . number_format($total_tps_ecoule, 3, ',', ' ') . '</td>' .
'</tr>' . "\n";
$tps_debut = $tps_fin;
}
}
$tbody .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) .
'</tbody>' . "\n";
 
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) .
'<tfoot>' . "\n";
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))) .
'<tr>' .
'<th>' . 'Total du temps écoulé (en s.)' . '</th>' .
'<td colspan="2">' .
number_format($total_tps_ecoule, 3, ',', ' ') . '</td>' .
'</tr>' . "\n";
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) .
'</tfoot>' . "\n";
$sortie .= $tbody;
$sortie .= str_repeat(' ', $indentation_origine) .
'</table>' . "\n";
 
return $sortie;
}
 
}
?>
/trunk/bibliotheque/Modele.php
New file
0,0 → 1,122
<?php
/**
* Classe modèle, donc d'accès au données, elle ne devrait pas être appelée de l'extérieur.
* Elle fait office d'abstraction légère de base de données en utilisant les objects PDO natifs
* de PHP
* Elle est abstraite donc doit obligatoirement être étendue.
*/
abstract class Modele {
 
/**
* registre global
*/
private $registre;
/**
* Gestionnaire d'exceptions php
*/
private $gestionnaire_exception;
/**
* Gestionnaire d'erreurs php
*/
private $gestionnaire_erreur;
/**
* DSN pour accéder à la base de données
*/
private $dsn;
/**
* Type de base de données (mysql, mysqli, etc ...)
*/
private $type;
/**
* Hote herbergeant la base de données
*/
private $hote;
/**
* Nom de la base de données à laquelle le modèle doit se connecter
*/
private $bdd_nom;
/**
* Nom d'utilisateur
*/
private $utilisateur;
/**
* Mot de passe
*/
private $pass;
/**
* Connexion à la base de données
*/
private $connexion = null;
 
/**
* Constructeur par défaut, appelé à l'initialisation
*/
final public function __construct() {
// les différents paramètres nécessaires sont lus à partir du registre
$this->registre = Registre::getInstance();
$this->gestionnaire_erreur = GestionnaireErreur::getInstance();
$this->type = $this->registre->get('bdd_type');
$this->hote = $this->registre->get('bdd_hote');
$this->bdd_nom = $this->registre->get('bdd_nom');
$this->utilisateur = $this->registre->get('bdd_utilisateur');
$this->pass = $this->registre->get('bdd_pass');
$this->dsn = $this->type.':dbname='.$this->bdd_nom.';host='.$this->hote;
}
/**
* Fonction qui appelle la bonne fonction de requete suivant le type de bdd
* @param string la requete à effectuer
* @return PDOStatement un objet contenant le résultat de la requête
*/
final protected function requete($requete) {
// on ne se connecte que lors du premier appel à une requete (lazy connexion)
if($this->connexion == null) {
$this->connecter();
}
return $this->connexion->query($requete);
}
/**
* Connecte à la base de données en utilisant les informations fournies par
* le fichier de configuration, private et final car n'a pas vocation a être appelée
* par l'utilisateur
* @throws PDOException une exception dans le cas ou là connexion échoue
*/
final private function connecter() {
// TODO: retirer le try catch et laisser le problème au gestionnaire d'exceptions
try {
$this->connexion = new PDO($this->dsn,$this->utilisateur,$this->pass);
} catch (PDOException $e) {
 
}
}
/**
* protège une chaine de caractères avant l'insertion dans la base de données
*/
final protected function proteger($chaine) {
// on ne se connecte que lors du premier appel à une requete
if($this->connexion == null) {
$this->connecter();
}
return $this->connexion->quote($chaine);
}
/**
* Destructeur de classe, se contente de fermer explicitement la connexion
*/
final public function __destruct() {
if($this->connexion != null) {
$this->connexion = null ;
}
}
}
?>
/trunk/index.php
New file
0,0 → 1,9
<?php
/**
* Created on 19 mars 2009
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
**/
header('Location: admin_administrateur.php');
?>
/trunk/squelettes/modif_admin.tpl.html
New file
0,0 → 1,29
<h2>Modification d'un administrateur</h2>
<form id="modif_admin" action="<?=$base_url.'?m=modif_admin_va&id_admin='.$admin['ga_id_administrateur']
?>" method="post">
<fieldset><label for="admin_nom">Nom : </label> <input
type="text" id="admin_nom" name="admin_nom" maxlength="80" tabindex="1"
value="<?=$admin['ga_nom'] ?>" /> <label for="admin_prenom">Prénom
: </label> <input type="text" id="admin_prenom" name="admin_prenom"
maxlength="80" tabindex="2" value="<?=$admin['ga_prenom'] ?>"
/> <label for="admin_mail">Mail : </label> <input type="text"
id="admin_mail" name="admin_mail" maxlength="120" tabindex="3" value="<?=$admin['ga_mail']
?>" /> <?php if (isset($erreurs['mail'])): ?> <span
class="symbole_obligatoire"> <?=$erreurs['mail'] ?> </span> <?php endif; ?>
<label for="admin_lang">Langue : </label> <select id="admin_lang"
name="admin_lang" tabindex="4">
<option<?=($admin['ga_ce_i18n'] == "fr-FR") ?
'selected="selected"' : '';?> value="fr-FR"> Français</option>
<option<?=($admin['ga_ce_i18n'] == "en-EN") ?
'selected="selected"' : '';?> value="en-EN"> Anglais</option>
</select> <label for="password">Mot de passe : </label> <input type="password"
id="admin_pass" name="admin_pass" maxlength="80" tabindex="5" value="<?=''
?>" /> <label for="password_confirm">Confirmez le mot de passe :
</label> <input type="password" id="admin_pass_confirm"
name="admin_pass_confirm" maxlength="80" tabindex="6" value="<?=''
?>" /> <?php if (isset($erreurs['pass'])): ?> <span
class="symbole_obligatoire"> <?=$erreurs['pass'] ?> </span> <?php endif; ?>
</fieldset>
<input type="submit" id="valider_modif_admin" name="valider_modif_admin"
tabindex="7" value="Modifier" /> <a href="<?=$base_url.'?m=liste_admin'
?>"> annuler </a></form>
/trunk/squelettes/liste_admin.tpl.html
New file
0,0 → 1,26
<h2>Liste des administrateurs</h2>
<table class="liste_admin">
<th>Identifiant d'admin</th>
<th>Nom</th>
<th>Prénom</th>
<th>Langue</th>
<th></th>
<th></th>
<?php foreach ($admin as $element) : ?>
<tr>
<td><?=$element['ga_id_administrateur'] ?></td>
<td><?=$element['ga_nom'] ?></td>
<td><?=$element['ga_prenom'] ?></td>
<td><?=$element['ga_ce_i18n'] ?></td>
<td><a href=<?=$base_url.'?m=modif_admin&id_admin='.$element['ga_id_administrateur']
?>>Modifier</a></td>
<td><a href=<?=$base_url.'?m=suppr_admin&id_admin='.$element['ga_id_administrateur']
?>>Supprimer</a></td>
</tr>
<?php endforeach; ?>
</table>
<?php if (isset($erreurs['supp'])): ?>
<span class="symbole_obligatoire"> <?=$erreurs['supp'] ?> </span>
<?php endif; ?>
<p><a href="<?=$base_url.'?&m=ajout_admin' ?>"> Ajouter un
administrateur </a></p>
/trunk/squelettes/ajout_admin.tpl.html
New file
0,0 → 1,30
<h2>Ajout d'un administrateur</h2>
<form id="modif_admin" action="<?=$base_url.'?&m=ajout_admin_va'?>"
method="post">
<fieldset><?php if (isset($erreurs['champs'])): ?> <span
class="symbole_obligatoire"> <?=$erreurs['champs'] ?> </span> <?php endif; ?>
<label for="admin_nom">Nom : </label> <input type="text" id="admin_nom"
name="admin_nom" maxlength="80" tabindex="1" value="<?=$admin['ga_nom']
?>" /> <label for="admin_prenom">Prénom : </label> <input type="text"
id="admin_prenom" name="admin_prenom" maxlength="80" tabindex="2"
value="<?=$admin['ga_prenom'] ?>" /> <label for="admin_mail">Mail
: </label> <input type="text" id="admin_mail" name="admin_mail" maxlength="120"
tabindex="3" value="<?=$admin['ga_mail'] ?>" /> <?php if (isset($erreurs['mail'])): ?>
<span class="symbole_obligatoire"> <?=$erreurs['mail'] ?> </span> <?php endif; ?>
<label for="admin_lang">Langue : </label> <select id="admin_lang"
name="admin_lang" tabindex="4">
<option<?=($admin['ga_ce_i18n'] == "fr-FR") ?
'selected="selected"' : '';?> value="fr-FR"> Français</option>
<option<?=($admin['ga_ce_i18n'] == "en-EN") ?
'selected="selected"' : '';?> value="en-EN"> Anglais</option>
</select> <label for="password">Mot de passe : </label> <input type="password"
id="admin_pass" name="admin_pass" maxlength="80" tabindex="5" value="<?=''
?>" /> <label for="password_confirm">Confirmez le mot de passe :
</label> <input type="password" id="admin_pass_confirm"
name="admin_pass_confirm" maxlength="80" tabindex="6" value="<?=''
?>" /> <?php if (isset($erreurs['pass'])): ?> <span
class="symbole_obligatoire"> <?=$erreurs['pass'] ?> </span> <?php endif; ?>
</fieldset>
<input type="submit" id="valider_ajout_admin" name="valider_ajout_admin"
tabindex="7" value="Ajouter" /> <a href="<?=
$base_url.'?m=liste_admin' ?>"> annuler </a></form>
/trunk/squelettes/ident_admin.tpl.html
New file
0,0 → 1,13
 
<p class="zone_alert">Identifiez-vous</p>
<form id="form_connexion" style="clear: both;"
class="form_identification" action="<?=$base_url ?>"
method="post">
<fieldset><legend>Identifiez vous</legend> <label
for="username">Courriel : </label> <input type="text" id="username"
name="username" maxlength="80" tabindex="1" value="courriel" /> <label
for="password">Mot de passe : </label> <input type="password"
id="password" name="password" maxlength="80" tabindex="2"
value="mot de passe" /> <input type="submit" id="connexion"
name="connexion" tabindex="3" value="ok" /></fieldset>
</form>
/trunk/controleurs/AdminAdministrateur.php
New file
0,0 → 1,196
<?php
 
/**
* Classe controleur pour l'application administration des administrateurs
*/
class AdminAdministrateur extends Controleur {
/**
* Fonction d'affichage par défaut, elle appelle la liste des administrateurs
*/
function index() {
$this->charger_admin();
}
/**
* Charge la liste des administrateurs et l'envoie à la vue
* @param array un tableau contenant les erreurs à afficher s'il y en a
* @return string la vue correspondante
*/
function chargerAdmin($erreurs = array()) {
 
$this->chargerModele('ListeAdmin');
$data['erreurs'] = $erreurs;
$data['admin'] = $this->ListeAdmin->chargerAdmin();
$this->chargerVue('liste_admin',$data);
 
return $this->liste_admin;
}
/**
* Charge les détails d'un administrateur demandé et l'envoi à la
* vue qui permet de les modifier
* @id string l'id de l'administrateur à modifier
* @return string la vue correspondante
*/
function modifAdmin($id) {
$this->chargerModele('ListeAdmin');
$data['admin'] = $this->ListeAdmin->loadDetailsAdmin($id);
$this->chargerVue('modif_admin',$data);
return $this->modif_admin;
}
/**
* Fonction appelée lors de la validation du formulaire de modification
* des détails d'un administrateurs. Elle modifie les détails dans la base
* de données. S'il y a une erreur et rappelle la formulaire et notifie l'erreur,
* sinon elle charge la liste des administrateurs
* @param string l'identifiant de l'administrateur*
* @param string le nom
* @param string le prénom
* @param string le mail
* @param string le mot de passe
* @param string la confirmation du mot de passe
* @return string la vue correspondante
*/
function modifAdminVa($id,$nom,$prenom,$mail,$lang,$pass,$pass_conf) {
$this->chargerModele('ListeAdmin') ;
$res = $this->ListeAdmin->modifDetailsAdmin($id,$nom,$prenom,$mail,$lang,$pass,$pass_conf) ;
if (count($res) == 0) {
return $this->chargerAdmin() ;
} else {
 
$admin['ga_id_administrateur'] = $id;
$admin['ga_nom'] = $nom;
$admin['ga_prenom'] = $prenom;
$admin['ga_mail'] = $mail;
$admin['ga_ce_i18n'] = $lang;
$data['admin'] = $admin;
$data['erreurs'] = $res;
$this->chargerVue('modif_admin',$data);
return $this->modif_admin;
}
}
/**
* Supprime un administrateur dans la base de données,
* renvoie la liste des administrateurs, en affichant des erreurs
* s'il y en a.
* @return string la vue contenant la liste des administrateurs
*
*/
function supprAdmin($id) {
$this->chargerModele('ListeAdmin');
$res = $this->ListeAdmin->suppAdmin($id);
if ($res == '') {
return $this->chargerAdmin();
} else {
$erreurs['supp'] = $res;
return $this->chargerAdmin($erreurs);
}
}
/**
* Appelle la vue contenant le formulaire d'ajout d'un administrateur
* @return string la vue contenant le formulaire d'ajout
*/
function ajoutAdmin() {
$admin['ga_id_administrateur'] = '';
$admin['ga_nom'] = '';
$admin['ga_prenom'] = '';
$admin['ga_mail'] = '';
$admin['ga_ce_i18n'] = '';
$data['admin'] = $admin;
$this->chargerVue('ajout_admin',$data);
return $this->ajout_admin;
}
/**
* Fonction appelée lors de la validation du formulaire d'ajout d'un administrateur.
* Elle ajoute celui-ci les dans la base de données
* S'il y a une erreur et rappelle la formulaire et notifie l'erreur,
* sinon elle charge la liste des administrateurs
* @param string le nom
* @param string le prénom
* @param string le mail
* @param string le mot de passe
* @param string la confirmation du mot de passe
* @return string la vue correspondante
*/
function ajoutAdminVa($nom,$prenom,$mail,$lang,$pass,$pass_conf) {
if (empty($nom) || empty($prenom) || empty($mail) || empty($pass) || empty($pass_conf)) {
$res = array('champs' => 'Tous les champs sont obligatoires') ;
$data['erreurs'] = $res;
$admin['ga_nom'] = $nom;
$admin['ga_prenom'] = $prenom;
$admin['ga_mail'] = $mail;
$admin['ga_ce_i18n'] = $lang;
$data['admin'] = $admin;
$this->chargerVue('ajout_admin',$data);
return $this->ajout_admin;
}
$this->chargerModele('ListeAdmin');
$res = $this->ListeAdmin->ajoutAdmin($nom,$prenom,$mail,$lang,$pass,$pass_conf);
if (count($res) == 0) {
return $this->chargerAdmin();
} else {
$admin['ga_nom'] = $nom;
$admin['ga_prenom'] = $prenom;
$admin['ga_mail'] = $mail;
$admin['ga_ce_i18n'] = $lang;
$data['admin'] = $admin;
$data['erreurs'] = $res;
$this->chargerVue('ajout_admin',$data);
return $this->ajout_admin;
}
}
/** Apelle le formulaire d'identification (dans le cas où l'utilisateur n'est pas identifié)
* @return string la vue permettant de s'identifier
*/
function demanderIdent() {
$this->chargerVue('ident_admin',null);
return $this->ident_admin;
}
/**
* Renvoie la tête de page de l'application
* @return string la tete de page de l'application
*/
function adminTete() {
$tete = '<h1>Gestion des administrateurs de Papyrus</h1>';
return $tete;
}
/**
* Renvoie le pied de page de l'application
* @return string le pied de page de l'application
*/
function adminPied() {
 
$pied = '';
return $pied;
}
}
 
?>