Skip to content

Instantly share code, notes, and snippets.

@cordoval
Created July 16, 2012 14:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cordoval/3123010 to your computer and use it in GitHub Desktop.
Save cordoval/3123010 to your computer and use it in GitHub Desktop.
Diff parser
<?php
$diff = 'diff --git a/README.md b/README.md
index 9b6fc2a..cac3d88 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,34 @@
-*This project is not stable, tested or production ready. It\'s a proof of concept and a work in progress.*
+** This project is not stable, tested or production ready. It\'s a proof of concept and a work in progress. **
# Github Pull Request PHP Codesniffer
A fairly straight forward Silex app for processing pull request events, running PHP Codesniffer over the changed files and reporting any errors as comments.
-After cloning run the following: `git update-index --assume-unchanged resources/config/prod.php` to make sure your app secret isn\'t exposed.
\ No newline at end of file
+Installation
+------------
+
+### Without git clone
+
+Run the following commands:
+
+ curl -s http://getcomposer.org/installer | php
+ php composer.phar create-project lyrixx/Silex-Kitchen-Edition PATH/TO/YOUR/APP
+ cd PATH/TO/YOUR/APP
+
+### With git clone
+
+Run the following commands:
+
+ git clone https://github.com/lyrixx/Silex-Kitchen-Edition.git PATH/TO/YOUR/APP
+ cd PATH/TO/YOUR/APP
+ curl -s http://getcomposer.org/installer | php
+ php composer.phar install
+
+### Then
+
+You can edit `resources/config/prod.php` and start hacking in `src/controllers.php`
+
+Help
+----
+
+* http://silex.sensiolabs.org/documentation
diff --git a/src/controllers.php b/src/controllers.php
index c27cdfb..7387113 100644
--- a/src/controllers.php
+++ b/src/controllers.php
@@ -224,7 +224,7 @@
}
// Run PHP Code Sniffer
- exec("phpcs --standard=Symfony2 {$eventFolderPath}/files/* --extensions=php", $output);
+ exec("phpcs --standard=Symfony2 --extensions=php {$eventFolderPath}/files/", $output);
$report = implode("\n", $output);
$report = preg_replace("/FILE:(.*?)".$eventTime."\/files\//", "FILE: ", $report);
file_put_contents($eventFolderPath."/report.txt", $report);
';
$patterns = array(
'originalFile' => "/^--- (.*)/",
'newFile' => "/^\+\+\+ (.*)/",
'chunk' => "/^@@ -(\d+),(\d+) +(\d+),(\d+) @@/",
'addedLine' => "/^\+(.*)/",
'removedLine' => "/^-(.*)/",
'unchangedLine' => "/^ (.*)/",
);
$results = array();
foreach (explode("\n", $diff) as $lineNum => $line) {
foreach ($patterns as $patternKey => $pattern) {
if(preg_match($pattern, $line, $matches)){
$results[$patternKey][$lineNum] = $line;
continue(2);
}
}
}
var_dump($results);
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment