Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Phpcs cherrypick #10

Closed
wants to merge 2 commits into from

8 participants

@lapistano

Successor of the phpcs PR. But not with all the changes of the PSR-0 Test suite.
Feedback welcome.

Bastian

@dragoonis
Owner

@gsherwood are you able to comment on the quality of this PR since you're the one who was leading the PHPCS stuff.

@bobthecow

It seems like PHPCS standards belong in the PHPCS repo (where the PSR-1 and PSR-2 standards currently are). Or, if we want to host canonical standards, they should probably go in a separate repo.

@AmyStephen

Justin - where are these standards? I thought https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md was the official location.

@bobthecow

@AmyStephen the PSR standards are there. The PHPCS standards are here.

:)

@AmyStephen

Thank you. There are far too many acronyms for this old brain to keep with. :-P

I agree with your comment to keep these resources in one place. Also, it might be helpful to add a link to those definitions from here -- maybe even as a footnote right inside of the published standard in this repo.

@gsherwood

I'd be happy to look at this sniff and write some unit tests for it if you want to contribute it to PHP_CodeSniffer. Given PSR-1 includes PSR-0 and PSR-2 includes PSR-1, it would mean that developers who are using PHPCS to check their code against PSR-1 or PSR-2 would automatically get this check as well, instead of them having to write a custom standard to include it.

Submit a PR in https://github.com/squizlabs/PHP_CodeSniffer if you that is something you'd like to do, or just let me know and I'll port the code over to a new PSR0 directory under CodeSniffer/Standards

@LindaMann

Hello there;
I have created a profile page and it all works except that instead of posting each person's individual weight, it only grabs the first person's from the database and posts that for everyone. Here is the code... I cannot figure out what I am forgetting... I know it is probably something really simple too... I hope that someone can help me soon please...

Thank you so much!

The code is:

<?PHP
session_start();
require_once("./include/membersite_config.php");
$usernames = array("user1", "user2", "user3", "admin", "new user");
$passwords = array("password1", "password2", "password3", "admin", "new password");
$page = "protected_page.php";
$page_title = 'login';
$page_title = 'login-home';
$page_title = 'logout';
for($i=0;$i {
$logindata[$usernames[$i]]=$passwords[$i];
}
if(!$fgmembersite->CheckLogin())
{
$fgmembersite->RedirectToURL("profile.php");
exit;
}

// Connect to the database
$dbc = mysql_connect('jaeger.db.8498764.hostedresource.com', 'jaeger', 'Activate1!', 'jaeger');
mysql_select_db('jaeger');

//database connect info here

//check for file upload
if(isset($_FILES['csv_file']) && is_uploaded_file($_FILES['csv_file']['tmp_name'])){

//upload directory
$upload_dir = "uploads/";

//create file name
$file_path = $upload_dir . $_FILES['csv_file']['name'];

//move uploaded file to upload dir
if (!move_uploaded_file($_FILES['csv_file']['tmp_name'], $file_path)) {

    //error moving upload file
    echo "Error moving file upload";

}

//open the csv file for reading
$handle = fopen($file_path, 'r');

//turn off autocommit and delete the product table
mysql_query("SET AUTOCOMMIT=0");
mysql_query("BEGIN");
$i=0;

while (($data = fgetcsv($handle, 1000, ',')) !== FALSE) {

    if($i>0){

    //Access field data in $data array ex.
    $firstname = addslashes($data[2]);
    $lastname = addslashes($data[3]);
    $email = addslashes($data[4]);
    $teams = addslashes($data[5]);
    $address = addslashes($data[6]);
    $city = addslashes($data[7]);
    $state = addslashes($data[8]);
    $zipcode = addslashes($data[9]);
    $phonenumber = addslashes($data[10]);
    $username = addslashes($data[11]);
    $password = addslashes($data[12]);

    $sql = "INSERT into groups(first_name,last_name,email,radio_name, address, city, state, zipcode, phonenumber, username, password, confirmcode) VALUES('$firstname','$lastname','$email','$teams','$address','$city','$state','$zipcode','$phonenumber','$username','$password','y')";
    mysql_query($sql) or (mysql_query("ROLLBACK") and die(mysql_error() . " - $sql"));

    }
            $i++;
}

//commit the data to the database
mysql_query("COMMIT");
mysql_query("SET AUTOCOMMIT=1");

//delete csv file
unlink($file_path);

}

$pagenum = $_GET["pagenum"];
if (!(isset($pagenum)))

{

$pagenum = 1;

}

$query = "SELECT g.id,first_name,last_name,username,p.weight1,p.weight2,p.weight3,p.weight4,p.weight5,p.weight6,p.weight7,p.weight8 FROM groups g left join profile p on g.id=p.group_id order by first_name asc";
$data = mysql_query($query,$dbc) or die(mysql_error());
$rows = mysql_num_rows($data);
$page_rows = 1;
$last = ceil($rows/$page_rows);
if ($pagenum < 1)
{
$pagenum = 1;
}
if($_SESSION['is_admin']=='1'){
}

elseif ($pagenum > $last)
{
$pagenum = $last;
}
$max = ' limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$query=$query. $max;
$data_p = $data = mysql_query($query,$dbc) or die(mysql_error());
?>
<!DOCTYPE>



Activate Simi Valley - Home



group class group walks swimming vegetables


<!-- end .sidebar1 -->



Activate Simi Valley

Activate Simi Valley


Our Mission: To support healthy living in Simi Valley





Welcome <?php echo $_SESSION['name_of_user']; ?> to your personal profile




This is where you can periodically check on your progress.


Healthy Living Guide




Weigh-In Log



"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } ?>
Weight1 Weight2 Weight3 Weight4 Weight5 Weight6 Weight7 Weight8
". $row["weight1"] ."  ". $row["weight2"] ."  ". $row["weight3"] ."  ". $row["weight4"] ."  ". $row["weight5"] ."  ". $row["weight6"] ."  ". $row["weight7"] ."  ". $row["weight8"] ." 



Logout|  Profile | Users | Add User | Upload Users | User Weight Profiles 




<?PHP

mysql_close($dbc);
?>

Facebook Twitter

Email: YMCA Sponsored by the: Simi Valley YMCA Simi Valley YMCA

Frequently Asked Questions (FAQ)
Web Designer: Linda Designs

Back to the top
<!-- end .content --></div>

<!-- end .container -->


</htm

@bobthecow

Hi @LindaMann

This is still not an appropriate venue for your questions. Also, you posted your database credentials again. You probably don't want to do that.

@AmyStephen

Hello again, @LindaMann -

Agree with @BobtheCow .

My suggestion earlier was to use Google to search for a support forum that offers the services you are after. I went ahead and found three forums where volunteers provide free support for PHP questions. Please try one of these:

@philsturgeon

It looks like @gsherwood is waiting on a PR to their repo, so this can go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
40 accepted/phpcs/README.md
@@ -0,0 +1,40 @@
+===========================
+PSR-0 PHP_CodeSniffer Sniff
+===========================
+
+Purpose
+=======
+This Sniff is to be integrated in your [*PHP_CodeSniffer*][1] ruleset to observe the compatability of your project
+to the [PSR-0 standard][2].
+
+Installation
+============
+Getting the sources
+-------------------
+The installation is pretty simple just clone the sources to your favorite directory.
+This might be the FIG-Standards directory in your home directory.
+
+ $> git clone git://github.com/lapistano/fig-standards.git ~/fig-standards
+
+Setting up
+----------
+If you do not want to move or link the sniffer anywhere, skip this section and move over to __Usage__.
+Otherwise you have multiple choices at this point, either leave the the sniff where they are right now and link
+them to the *Standards* directory of your PHP_CodeSniffer installation (e.g. /usr/share/php/PHP/CodeSniffer/Standards)
+or you copy them to this directory. I propose you do just the linking to make it easy to update, in case the
+sniffer changes.
+
+Usage
+=====
+Mainly the usage is described on the [*PHP_CodeSniffer manual page*][1] on the PEAR website.
+But here is a short how to, if you linked or copied the sniffer to your PHP_CodeSniffer installation directory.
+Open the command line and change to your project directory or the directory to be verified. Then enter
+
+ $>phpcs --standard=Psr0 --extensions=php ./
+
+and PHP_CodeSniffer will do its magic.
+
+Links
+=====
+[1]: http://pear.php.net/manual/en/package.php.php-codesniffer.php
+[2]: http://groups.google.com/group/php-standards
View
148 accepted/phpcs/Standards/Psr0/Sniffs/CompatibilitySniff.php
@@ -0,0 +1,148 @@
+<?php
+/**
+ * Sniff to verify the compatibility of a project to PSR-0.
+ *
+ * PHP version 5
+ *
+ * @author Bastian Feder <lapistano@php.net>
+ * @copyright 2011 Bastian Feder
+ */
+
+namespace figStandards\accepted\phpcs\Standards;
+
+/**
+ * PSR0_Sniffs_CompatibilitySniff.
+ *
+ * Favor PHP 5 constructor syntax, which uses "function __construct()".
+ * Avoid PHP 4 constructor syntax, which uses "function ClassName()".
+ *
+ * @author Bastian Feder <lapistano@php.net>
+ * @copyright 2011 Bastian Feder
+ */
+class Psr0_Sniffs_CompatibilitySniff implements PHP_CodeSniffer_Sniff
+{
+ public $supportedTokenizers = array('PHP');
+
+ /**
+ * 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()
+ {
+ return array(
+ T_CLASS,
+ T_INTERFACE,
+ );
+ }
+
+ /**
+ * 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)
+ {
+ $tokens = $phpcsFile->getTokens();
+ $filename = $phpcsFile->getFilename();
+ $declarationName = $phpcsFile->getDeclarationName($stackPtr);
+ $namespace = $this->getNamespaceName($tokens, $phpcsFile->findPrevious(T_NAMESPACE, $stackPtr));
+ $fulldecla = $namespace . '\\' . $declarationName;
+
+ $fname = $this->translateClassToFilename($fulldecla);
+
+
+ if (false === strpos($filename, $fname)) {
+ $error = sprintf(
+ 'The classname (%s) does not translate correctly into a PSR-0 compatible filename.',
+ $fulldecla
+ );
+ $phpcsFile->addError($error, $stackPtr);
+ }
+ }
+
+ /**
+ * Crawls the namespace from the current file.
+ *
+ * @param array $tokens
+ * @param integer $stackPtr
+ * @return string
+ */
+ protected function getNamespaceName($tokens, $stackPtr)
+ {
+ $namespaceName = '';
+
+ while(isset($tokens[$stackPtr])) {
+ if (in_array($tokens[$stackPtr]['code'], array(T_STRING, T_NS_SEPARATOR))) {
+ $namespaceName .= $tokens[$stackPtr]['content'];
+ }
+ if ($tokens[$stackPtr]['code'] == T_SEMICOLON) {
+ break;
+ }
+ ++$stackPtr;
+ }
+ return $namespaceName;
+ }
+
+ /**
+ * Translates a classname to a filename according to the rules of PSR-0.
+ *
+ * This method is a clone of the autoload() function accepted to be the reference
+ * implementation to autoload classes following the PSR-0 FIG standard.
+ *
+ * @param string $className
+ * @return string
+ * @link https://github.com/php-fig/fig-standards
+ */
+ protected function translateClassToFilename($className)
+ {
+ $className = ltrim($className, '\\');
+ $fileName = '';
+ $namespace = '';
+ if ($lastNsPos = strripos($className, '\\')) {
+ $namespace = substr($className, 0, $lastNsPos);
+ $className = substr($className, $lastNsPos + 1);
+ $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
+ }
+ $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
+ return $fileName;
+ }
+}
View
4 accepted/phpcs/Standards/Psr0/ruleset.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<ruleset name="PSR-0 Compatabitlity">
+ <description>Compatibility check for a project being PSR-0 compatible.</description>
+</ruleset>
Something went wrong with that request. Please try again.