set up subversion

1) Install SVN

sudo apt-get install subversion libapache2-svn

2) Create your repository. Once svn is installed on your host, you can proceed with the repository set up

svnadmin create /svnrepos

3) Create a SVN User

Run the below given command

vi /svnrepos/conf/svnserve.conf

and paste here the below given code in  svnserve.conf

anon-access = none
auth-access = write
password-db = passwd

4)Create a password file:

vi /svnrepos/conf/passwd
# add users in the format : user = password
phpcode = phppass

5)  Import Your Project

svn import /projects/myrailsproject file:///svnrepos/myrailsproject

6) Start the SVN Server as Daemon

svnserve -d

7) Restart apache

sudo /etc/init.d/apache2 restart

set up svn

1) Install SVN

sudo apt-get install subversion libapache2-svn

2) Create your repository. Once svn is installed on your host, you can proceed with the repository set up

svnadmin create /svnrepos

3) Create a SVN User

Run the below given command

vi /svnrepos/conf/svnserve.conf

and paste here the below given code in  svnserve.conf

anon-access = none
auth-access = write
password-db = passwd

4)Create a password file:

vi /svnrepos/conf/passwd
# add users in the format : user = password
phpcode = phppass

5)  Import Your Project

svn import /projects/myrailsproject file:///svnrepos/myrailsproject

6) Start the SVN Server as Daemon

svnserve -d

7) Restart apache

sudo /etc/init.d/apache2 restart

Create A New Coding Standard

Please follow the below given steps

1) Find out the location of PHP_CodeSniffer install .

locate PHP_CodeSniffer

2) Change the directory to install

cd path/to/PHP_CodeSniffer

3) Create a directory that represent the new coding standard and change the directory to it

sudo mkdir PHPCodezStandard

cd PHPCodezStandard

4) Create the directory sniff that is used to store all the sniff files for this coding standard and change the directory to it

sudo mkdir Sniffs

5) Create a file ruleset.xml

sudo vi ruleset.xml

6) Paste the below given content in ruleset.xml

<?xml version=”1.0″?>
<ruleset name=”PHPCodezStandard”>
<description>New coding standard.</description>
</ruleset>

Then change the directory to Sniffs

cd Sniffs

7) Create the sniff that require a single php file and it’s name should be end with Sniff.php and should be placed in a subdirectory

sudo  mkdir Commenting
cd Commenting
sudo vi PHPCodezSniff.php

8 ) Paste the below given code in PHPCodezSniff.php

<?php
class PHPCodezStandard_Sniffs_Commenting_PHPCOdezSniff implements PHP_CodeSniffer_Sniff
{
public function register()  {
return array(T_COMMENT);
}

public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr){
$tokens = $phpcsFile->getTokens();
if ($tokens[$stackPtr][‘content’]{0} === ‘#’) {
$error = ‘Hash comments are prohibited; found %s’;
$data  = array(trim($tokens[$stackPtr][‘content’]));
$phpcsFile->addError($error, $stackPtr, ‘Found’, $data);
}

}
}
?>

10) You can use this standard as follows

phpcs –standard=/usr/share/php/data/PHP_CodeSniffer/PHPCodezStandard exception.php

FILE: /var/www/test/exception.php
——————————————————————————–
FOUND 1 ERROR(S) AFFECTING 1 LINE(S)
——————————————————————————–
2 | ERROR | Hash comments are prohibited; found #
——————————————————————————–

PHP_CompatInfo Features

  • parse a single file
  • parse a folder/directory
  • parse an array (list of file)
  • ability to give a list of functions to ignore when calculating the version needed
  • ability to give a list of directories to ignore when calculating the version needed
  • ability to go recursively or not into folder to find files
  • ability to reduce or extends list of extensions to parse for PHP code
  • ability to give a list of constants to ignore when calculating the version needed. Available since version 1.2.0
  • ability to get list of functions related to a PHP version (or a subset). Available since version 1.2.0
  • ability to give a list of php modules/extensions to ignore when calculating the version needed. Available since version 1.4.0
  • ability to give a list of php versions to ignore when calculating the version needed. Available since version 1.4.0
  • ability to exclude from parsing scope, some functions, extensions, constants, based on conditionnal code. Available since version 1.7.0
  • ability to know conditional code (such as function_exists) used by php scripts. Available since version 1.7.0

PHP_Compat

PHP_Compat provides missing functionality in the form of functions and constants for older versions of PHP.

The replicated functions are designed to be interchangable with their native equivilants. They have the same signature, same return values and throw the same errors. Each function is unit tested to ensure accuracy.

PHP_Compat is designed for ease of use. It has no dependencies and can be used completely outside the PEAR infrastructure.

Check a directory with PHP CodeSniffer

phpcs /var/www/test/xml

FILE: /var/www/test/xml/index.php
——————————————————————————–
FOUND 2 ERROR(S) AFFECTING 2 LINE(S)
——————————————————————————–
1 | ERROR | End of line character is invalid; expected “n” but found “rn”
2 | ERROR | Missing file doc comment
——————————————————————————–
FILE: /var/www/test/xml/xml.php
——————————————————————————–
FOUND 8 ERROR(S) AND 1 WARNING(S) AFFECTING 8 LINE(S)
——————————————————————————–
1 | ERROR | End of line character is invalid; expected “n” but found
| | “rn”
2 | ERROR | Missing file doc comment
13 | ERROR | Expected “foreach (…) {n”; found “foreach(…)n{n”
15 | ERROR | Line indented incorrectly; expected at least 4 spaces, found 3
16 | ERROR | Line indented incorrectly; expected at least 4 spaces, found 3
18 | ERROR | Line indented incorrectly; expected 4 spaces, found 3
19 | ERROR | Line indented incorrectly; expected at least 8 spaces, found 4
19 | WARNING | Line exceeds 85 characters; contains 92 characters
21 | ERROR | Line indented incorrectly; expected at least 4 spaces, found 3
——————————————————————————–

Check a file with PHP CodeSniffer

phpcs test.php

FILE: /var/www/test/test.php
——————————————————————————–
FOUND 2 ERROR(S) AFFECTING 2 LINE(S)
——————————————————————————–
1 | ERROR | End of line character is invalid; expected “n” but found “rn”
2 | ERROR | Missing file doc comment
——————————————————————————–