This repository was archived by the owner on Sep 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax.php
More file actions
101 lines (86 loc) · 3.08 KB
/
Copy pathsyntax.php
File metadata and controls
101 lines (86 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* FollowUpBoss: Real Estate Lead Management Software.
*
* @author Anthony Gentile <anthony@followupboss.com>
* @copyright Copyright (c) 2014, Enchant LLC.
* @license Property of Enchant LLC. All rights reserved.
*/
namespace FUBSyntax;
require dirname(__FILE__) . '/lib/phpca/src/Autoload.php';
use Exception;
use spriebsch\PHPca\Result;
use spriebsch\PHPca\Application;
use spriebsch\PHPca\Configuration;
use spriebsch\PHPca\ProgressPrinterInterface;
/**
* Runs syntax checks against files. This will validate
* against the Lithium and FUB coding, documentation and testing standards.
*/
class Syntax implements ProgressPrinterInterface {
/**
* Aura\Cli\Stdio object
*
* @var object
*/
protected $stdio;
/**
* Run syntax check against a file or directory.
*
* @param string $path Absolute path to file or directory.
* @param object $stdio Aura\Cli\Stdio object.
* @return boolean
*/
public function run($path, $stdio) {
$this->stdio = $stdio;
$app = new Application(getcwd());
$app->registerProgressPrinter($this);
$file = __DIR__ . '/fub-standard.ini';
$config = new Configuration(getcwd());
$parsed = parse_ini_file($file, true);
if ($parsed['PHPca']['additional_rules'] == 'rules') {
$parsed['PHPca']['additional_rules'] = __DIR__ . '/rules';
}
$config->setStandard($parsed);
$config->setConfiguration(array());
$php = PHP_BINDIR . '/' . 'php';
try {
$result = $app->run($php, $path, $config);
} catch (Exception $e) {
$this->stdio->outln($message = $e->getMessage());
return $message == 'No PHP files to analyze';
}
return !$result->hasErrors();
}
public function showProgress($file, Result $result, Application $application) {
$self = $this;
$format = function ($result) use ($self) {
return sprintf(
'%1$4s| %2$3s| %4$s',
$result->getLine() ?: '??',
$result->getColumn() ?: '??',
'',
$result->getMessage() ?: '??'
);
};
if ($result->wasSkipped($file)) {
$this->stdio->outln("[<<blue>>skip<<reset>>] {$file}");
} elseif ($result->hasLintError($file)) {
$this->stdio->outln("[<<blue>>exception<<reset>>] {$file}");
$this->stdio->outln($format($result->getLintError($file)));
} elseif ($result->hasRuleError($file)) {
$this->stdio->outln("[<<blue>>exception<<reset>>] {$file}");
foreach ($result->getRuleErrors($file) as $error) {
$this->stdio->outln($format($error));
}
} elseif ($result->hasViolations($file)) {
$this->stdio->outln("[<<red>>fail<<reset>>] {$file}");
foreach ($result->getViolations($file) as $violation) {
$this->stdio->outln($format($violation));
}
} else {
$this->stdio->outln("[<<green>>pass<<reset>>] {$file}");
}
}
}
?>