Tag Archives: PHP

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

SVN Repository

Subversion is an open source version control system. Using Subversion, you can record the history of source files and documents. It manages files and directories over time. A tree of files is placed into a central repository. The repository is much like an ordinary file server, except that it remembers every change ever made to files and directories.

Subversion is built on a portability layer called APR—the Apache Portable Runtime library.

Subversion is a centralized system for sharing information. At its core is a repository, which is a central store of data. The repository stores information in the form of a filesystem tree—a typical hierarchy of files and directories. Any number of clients connect to the repository, and then read or write to these files. By writing data, a client makes the information available to others; by reading data, the client receives information from other

What makes the Subversion repository special is that it remembers every change ever written to it—every change to every file, and even changes to the directory tree itself, such as the addition, deletion, and rearrangement of files and directories.

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.

Anti Pattern

An anti-pattern (or antipattern) is a pattern that may be commonly used but is ineffective and/or counterproductive in practice

Many anti-pattern ideas amount to little more than mistakes, rants, unsolvable problems, or bad practices to be avoided if possible. Sometimes called pitfalls or dark patterns, this informal use of the term has come to refer to classes of commonly reinvented bad solutions to problems.

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
——————————————————————————–