Permalink
Browse files

Add travis support and fix warnings/errors

  • Loading branch information...
1 parent 2a10d74 commit 12d9e3409b3a088bf144c0527af78c0657192f4d Blaine Schmeisser committed Dec 4, 2012
View
@@ -0,0 +1,16 @@
+language: php
+
+php:
+ - 5.3
+ - 5.4
+
+before_install:
+ - cd ../
+ - git clone git://github.com/UnionOfRAD/framework.git
+ - mv li3_quality/ framework/app/libraries/li3_quality
+ - cd framework
+ - git submodule update --init --recursive
+ - cd libraries/lithium && git pull --rebase origin master
+ - cd ../../app/libraries/li3_quality
+
+script: ../../../libraries/lithium/console/li3 test tests && ../../../libraries/lithium/console/li3 quality syntax --library=li3_quality
@@ -16,8 +16,8 @@
)
));
-if(!Multibyte::config('li3_quality')) {
- Multibyte::config(array('li3_quality' => array('adapter' => 'Mbstring')));
+if (!Multibyte::config('li3_quality')) {
+ Multibyte::config(array('li3_quality' => array('adapter' => 'Mbstring')));
}
?>
@@ -60,19 +60,19 @@ public function syntax($path = null) {
. "on ". count($testables) . " classes."
);
- foreach($testables as $count => $path) {
+ foreach ($testables as $count => $path) {
$result = Rules::apply(new Testable(compact('path')));
- if($result['success']) {
+ if ($result['success']) {
$this->out("[OK] $path", "green");
}
- if(!$result['success']) {
+ if (!$result['success']) {
$pass = false;
$this->error("[FAIL] $path", "red");
$output = array(
array("Line", "Position", "Violation"),
array("----", "--------", "---------")
);
- foreach($result['violations'] as $violation) {
+ foreach ($result['violations'] as $violation) {
$defaults = array(
'line' => '-',
'position' => '-',
@@ -85,7 +85,7 @@ public function syntax($path = null) {
$this->columns($output, array('style' => 'red', 'error' => true));
}
}
- return (boolean) !$pass;
+ return (boolean) $pass;
}
/**
@@ -98,7 +98,7 @@ public function documented() {
$this->out("Checking documentation on " . count($testables) . " classes.");
- foreach($testables as $count => $path) {
+ foreach ($testables as $count => $path) {
//
}
}
@@ -121,10 +121,10 @@ public function coverage() {
$tests[$class] = $test;
}
- foreach($testables as $count => $path) {
+ foreach ($testables as $count => $path) {
$coverage = null;
- if($hasTest = isset($tests[$path])) {
+ if ($hasTest = isset($tests[$path])) {
$report = Dispatcher::run($tests[$path], array(
'format' => 'txt',
'filters' => array('Coverage')
@@ -141,7 +141,7 @@ public function coverage() {
$color = 'yellow';
}
- if($coverage == null || $coverage <= $this->threshold) {
+ if ($coverage == null || $coverage <= $this->threshold) {
$this->out(sprintf('%10s | %7s | %s',
$hasTest ? 'has test' : 'no test',
is_numeric($coverage) ? sprintf('%.2f%%', $coverage) : 'n/a',
@@ -169,7 +169,7 @@ protected function _testables($options = array()) {
}
$testables = Libraries::find($this->library, $options);
- if(!$testables) {
+ if (!$testables) {
$library = $path ? $path : $this->library;
$this->stop(0, "Could not find any files in {$library}.");
}
@@ -36,8 +36,8 @@ public static function apply($report, $tests, array $options = array()) {
public static function analyze($report, array $options = array()) {
$results = $report->results['filters'][__CLASS__];
$metrics = array();
- foreach($results as $result) {
- foreach($result as $class => $metric) {
+ foreach ($results as $result) {
+ foreach ($result as $class => $metric) {
$metrics[$class] = $metric['violations'];
}
}
View
@@ -22,9 +22,9 @@ class Rules extends \lithium\core\StaticObject {
*/
public static function __init() {
$rulePaths = Libraries::locate('rules');
- foreach($rulePaths as $rulePath) {
+ foreach ($rulePaths as $rulePath) {
$rule = new $rulePath();
- if($rule->enabled()) {
+ if ($rule->enabled()) {
static::add($rule);
}
}
@@ -44,9 +44,9 @@ public static function apply($testable) {
$violations = array();
$success = true;
- foreach(static::$_rules as $rule) {
+ foreach (static::$_rules as $rule) {
$rule->apply($testable);
- if(!$rule->success()) {
+ if (!$rule->success()) {
$success = false;
$violations = array_merge($violations, $rule->violations());
}
View
@@ -71,7 +71,7 @@ public function source() {
* when using an SplFixed array (which is faster), the app segfaults.
*/
public function tokens() {
- if($this->_tokens === null) {
+ if ($this->_tokens === null) {
$this->_tokens = Parser::tokenize($this->source());
}
return $this->_tokens;
@@ -84,19 +84,19 @@ public function tokens() {
*/
public function lines($line = null) {
$lineEnding = function($source) {
- if(strpos($source, "\r\n") !== false) {
+ if (strpos($source, "\r\n") !== false) {
return "\r\n";
- } elseif(strpos($source, "\r") !== false) {
+ } elseif (strpos($source, "\r") !== false) {
return "\r";
} else {
return "\n";
}
};
- if($this->_lines === null) {
+ if ($this->_lines === null) {
$this->_lines = explode($lineEnding($this->source()), $this->source());
}
- if($line) {
+ if ($line) {
return $this->_lines[++$line];
}
return $this->_lines;
View
@@ -66,4 +66,6 @@ protected function _mockRule($rule, $source) {
return $this->rule->success();
}
-}
+}
+
+?>
@@ -14,7 +14,7 @@ public function apply($testable) {
$message = "File does not begin with <?php";
$lines = $testable->lines();
- if($lines[0] != "<?php") {
+ if ($lines[0] != "<?php") {
$this->addViolation(array(
'message' => $message,
'line' => 1
@@ -17,10 +17,10 @@ public function apply($testable) {
$tabWidth = 3;
$message = "Maximum line length of \"" . $maxLength . "\" exceeded";
- foreach($testable->lines() as $i => $line) {
+ foreach ($testable->lines() as $i => $line) {
$tabBounty = substr_count($line, "\t") * $tabWidth;
$strlen = Multibyte::strlen($line, array('name' => 'li3_quality'));
- if(($length = $tabBounty + $strlen) > $maxLength) {
+ if (($length = $tabBounty + $strlen) > $maxLength) {
$this->addViolation(array(
'message' => $message,
'line' => $i+1,
@@ -14,7 +14,7 @@ public function apply($testable) {
$message = "File does not end with ?>";
$lines = $testable->lines();
- if($lines[count($lines)-1] != "?>") {
+ if ($lines[count($lines)-1] != "?>") {
$this->addViolation(array(
'message' => $message,
'line' => count($lines)-1
@@ -15,10 +15,10 @@ class HasCorrectClassName extends \li3_quality\test\Rule {
public function apply($testable) {
$tokens = $testable->tokens();
- foreach($tokens as $key => $token) {
- if($token['name'] == 'T_CLASS') {
+ foreach ($tokens as $key => $token) {
+ if ($token['name'] == 'T_CLASS') {
$className = $tokens[$key+2]['content'];
- if($className != Inflector::camelize($className)) {
+ if ($className != Inflector::camelize($className)) {
$this->addViolation(array(
'message' => 'Class name is not in CamelCase style',
'line' => $token['line']
@@ -13,7 +13,7 @@ class HasCorrectEncoding extends \li3_quality\test\Rule {
public function apply($testable) {
$message = "File is not encoded as UTF-8";
- if(mb_detect_encoding($testable->source(), 'UTF-8', true) != 'UTF-8') {
+ if (mb_detect_encoding($testable->source(), 'UTF-8', true) != 'UTF-8') {
$this->addViolation(compact('message'));
}
}
@@ -17,11 +17,11 @@ public function apply($testable) {
$pathinfo = pathinfo($testable->config('path'));
- if($pathinfo['extension'] != 'php') {
+ if ($pathinfo['extension'] != 'php') {
return;
}
- if($pathinfo['filename'] != Inflector::camelize($pathinfo['filename'])) {
+ if ($pathinfo['filename'] != Inflector::camelize($pathinfo['filename'])) {
$this->addViolation(array('message' => $message));
}
}
@@ -23,18 +23,18 @@ class HasCorrectFunctionNames extends \li3_quality\test\Rule {
public function apply($testable) {
$tokens = $testable->tokens();
- foreach($tokens as $key => $token) {
- if($token['name'] == 'T_FUNCTION') {
+ foreach ($tokens as $key => $token) {
+ if ($token['name'] == 'T_FUNCTION') {
$this->_checkCamelBack($tokens[$key+2]);
}
}
}
protected function _checkCamelBack($lookahead) {
$isMagic = in_array($lookahead['content'], $this->_magicMethods);
- if($lookahead['name'] == 'T_STRING' && !$isMagic) {
+ if ($lookahead['name'] == 'T_STRING' && !$isMagic) {
$name = preg_replace('/^_+/', '', $lookahead['content']);
- if($name != Inflector::camelize($name, false)) {
+ if ($name != Inflector::camelize($name, false)) {
$this->addViolation(array(
'message' => 'Function "' . $name . '" is not in camelBack style',
'line' => $lookahead['line']
@@ -12,7 +12,7 @@ class HasCorrectPermissions extends \li3_quality\test\Rule {
public function apply($testable) {
$message = "File is executable";
- if(is_executable($testable->config('path'))) {
+ if (is_executable($testable->config('path'))) {
$this->addViolation(compact('message'));
}
}
@@ -27,10 +27,10 @@ class HasCorrectVariableNames extends \li3_quality\test\Rule {
public function apply($testable) {
$tokens = $testable->tokens();
- foreach($tokens as $token) {
- if($token['name'] == 'T_VARIABLE' && !isset($this->_superglobals[$token['content']])) {
+ foreach ($tokens as $token) {
+ if ($token['name'] == 'T_VARIABLE' && !isset($this->_superglobals[$token['content']])) {
$name = preg_replace('/(\$_?|_+$)/', '', $token['content']);
- if($name != Inflector::camelize($name, false)) {
+ if ($name != Inflector::camelize($name, false)) {
$this->addViolation(array(
'message' => 'Variable "' . $name . '" is not in camelBack style',
'line' => $token['line']
@@ -12,8 +12,8 @@ class HasNoCarriageReturn extends \li3_quality\test\Rule {
public function apply($testable) {
$message = "Carriage Return character found";
- foreach($testable->lines() as $i => $line) {
- if(($pos = strpos($line, "\r")) !== false) {
+ foreach ($testable->lines() as $i => $line) {
+ if (($pos = strpos($line, "\r")) !== false) {
$this->addViolation(array(
'message' => $message,
'line' => $i+1,
@@ -15,7 +15,7 @@ public function apply($testable) {
$lines = $testable->lines();
$lastLine = trim($lines[count($lines)-1]);
- if(empty($lastLine)) {
+ if (empty($lastLine)) {
$this->addViolation(array(
'message' => $message,
'line' => count($lines)
@@ -26,16 +26,16 @@ class HasNoForbiddenStatements extends \li3_quality\test\Rule {
public function apply($testable) {
$tokens = $testable->tokens();
- foreach($tokens as $token) {
- if(isset($_forbidden[$token['name']])) {
+ foreach ($tokens as $token) {
+ if (isset($_forbidden[$token['name']])) {
$tokenName = $this->_forbidden[$token['name']];
$this->addViolation(array(
'message' => 'Forbidden "' . $tokenName . '" statement found',
'line' => $token['line']
));
}
- if($token['name'] === 'T_STRING' && $token['content'] === 'var_dump') {
+ if ($token['name'] === 'T_STRING' && $token['content'] === 'var_dump') {
$this->addViolation(array(
'message' => 'Forbidden "var_dump" statement found',
'line' => $token['line']
@@ -13,8 +13,8 @@ class HasNoPrivateMethods extends \li3_quality\test\Rule {
public function apply($testable) {
$tokens = $testable->tokens();
- foreach($tokens as $key => $token) {
- if($token['name'] == 'T_PRIVATE') {
+ foreach ($tokens as $key => $token) {
+ if ($token['name'] == 'T_PRIVATE') {
$this->addViolation(array(
'message' => 'Private method found',
'line' => $token['line']
@@ -15,7 +15,7 @@ class HasNoTrailingWhitespace extends \li3_quality\test\Rule {
public function apply($testable) {
$message = "Trailing whitespace found";
- foreach($testable->lines() as $i => $line) {
+ foreach ($testable->lines() as $i => $line) {
$name = 'li3_quality';
$length = Multibyte::strlen($line, compact('name'));
$lengthTrimmed = Multibyte::strlen(rtrim($line), compact('name'));
@@ -14,8 +14,8 @@ public function apply($testable) {
$message = "Uses spaces instead of tabs";
$lines = $testable->lines();
- foreach($lines as $number => $line) {
- if(preg_match('/^ +[^*]/', $line)) {
+ foreach ($lines as $number => $line) {
+ if (preg_match('/^ +[^*]/', $line)) {
$this->addViolation(array(
'message' => $message,
'line' => $number+1
@@ -21,7 +21,7 @@ public function apply($testable) {
$tokens = $testable->tokens();
foreach ($tokens as $key => $token) {
- if(isset($this->_inspectableTokens[$token['name']])) {
+ if (isset($this->_inspectableTokens[$token['name']])) {
for ($i = 1; $i <= 2; $i++) {
if ($tokens[$key+$i]['name'] == 'T_WHITESPACE') {
continue;
Oops, something went wrong.

0 comments on commit 12d9e34

Please sign in to comment.