3 namespace Friendica\Core\Console;
\r
6 * Tired of chasing typos and finding them after a commit.
\r
7 * Run this and quickly see if we've got any parse errors in our application files.
\r
9 * @author Hypolite Petovan <mrpetovan@gmail.com>
\r
11 class Typo extends \Asika\SimpleConsole\Console
\r
13 protected $helpOptions = ['h', 'help', '?'];
\r
15 protected function getHelp()
\r
18 console typo - Checks for parse errors in Friendica files
\r
20 bin/console typo [-h|--help|-?] [-v]
\r
23 Checks all PHP files in the Friendica file tree for parse errors
\r
26 -h|--help|-? Show help information
\r
27 -v Show more debug information.
\r
32 protected function doExecute()
\r
34 if ($this->getOption('v')) {
\r
35 $this->out('Class: ' . __CLASS__);
\r
36 $this->out('Arguments: ' . var_export($this->args, true));
\r
37 $this->out('Options: ' . var_export($this->options, true));
\r
40 if (count($this->args) > 0) {
\r
41 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
\r
46 $php_path = $a->getConfigValue('config', 'php_path', 'php');
\r
48 if ($this->getOption('v')) {
\r
49 $this->out('Directory: src');
\r
52 $Iterator = new \RecursiveDirectoryIterator('src');
\r
54 foreach (new \RecursiveIteratorIterator($Iterator) as $file) {
\r
55 if (substr($file, -4) === '.php') {
\r
56 $this->checkFile($php_path, $file);
\r
60 if ($this->getOption('v')) {
\r
61 $this->out('Directory: mod');
\r
64 $files = glob('mod/*.php');
\r
65 $this->checkFiles($php_path, $files);
\r
67 if ($this->getOption('v')) {
\r
68 $this->out('Directory: include');
\r
71 $files = glob('include/*.php');
\r
72 $this->checkFiles($php_path, $files);
\r
74 if ($this->getOption('v')) {
\r
75 $this->out('Directory: addon');
\r
78 $dirs = glob('addon/*');
\r
79 foreach ($dirs as $dir) {
\r
80 $addon = basename($dir);
\r
81 $files = glob($dir . '/' . $addon . '.php');
\r
82 $this->checkFiles($php_path, $files);
\r
85 if ($this->getOption('v')) {
\r
86 $this->out('String files');
\r
89 $this->checkFile($php_path, 'util/strings.php');
\r
91 $files = glob('view/lang/*/strings.php');
\r
92 $this->checkFiles($php_path, $files);
\r
94 $this->out('No errors.');
\r
99 private function checkFiles($php_path, array $files)
\r
101 foreach ($files as $file) {
\r
102 $this->checkFile($php_path, $file);
\r
106 private function checkFile($php_path, $file)
\r
108 if ($this->getOption('v')) {
\r
109 $this->out('Checking ' . $file);
\r
114 exec("$php_path -l $file", $output, $ret);
\r
116 throw new \RuntimeException('Parse error found in ' . $file . ', scan stopped.');
\r