3 namespace Friendica\Core\Console;
6 * Tired of chasing typos and finding them after a commit.
7 * Run this and quickly see if we've got any parse errors in our application files.
9 * @author Hypolite Petovan <hypolite@mrpetovan.com>
11 class Typo extends \Asika\SimpleConsole\Console
13 protected $helpOptions = ['h', 'help', '?'];
15 protected function getHelp()
18 console typo - Checks for parse errors in Friendica files
20 bin/console typo [-h|--help|-?] [-v]
23 Checks all PHP files in the Friendica file tree for parse errors
26 -h|--help|-? Show help information
27 -v Show more debug information.
32 protected function doExecute()
34 if ($this->getOption('v')) {
35 $this->out('Class: ' . __CLASS__);
36 $this->out('Arguments: ' . var_export($this->args, true));
37 $this->out('Options: ' . var_export($this->options, true));
40 if (count($this->args) > 0) {
41 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
44 $php_path = \Friendica\Core\Config::getConfigValue('config', 'php_path', 'php');
46 if ($this->getOption('v')) {
47 $this->out('Directory: src');
50 $Iterator = new \RecursiveDirectoryIterator('src');
52 foreach (new \RecursiveIteratorIterator($Iterator) as $file) {
53 if (substr($file, -4) === '.php') {
54 $this->checkFile($php_path, $file);
58 if ($this->getOption('v')) {
59 $this->out('Directory: mod');
62 $files = glob('mod/*.php');
63 $this->checkFiles($php_path, $files);
65 if ($this->getOption('v')) {
66 $this->out('Directory: include');
69 $files = glob('include/*.php');
70 $this->checkFiles($php_path, $files);
72 if ($this->getOption('v')) {
73 $this->out('Directory: addon');
76 $dirs = glob('addon/*');
77 foreach ($dirs as $dir) {
78 $addon = basename($dir);
79 $files = glob($dir . '/' . $addon . '.php');
80 $this->checkFiles($php_path, $files);
83 if ($this->getOption('v')) {
84 $this->out('String files');
87 $files = glob('view/lang/*/strings.php');
88 $this->checkFiles($php_path, $files);
90 $this->out('No errors.');
95 private function checkFiles($php_path, array $files)
97 foreach ($files as $file) {
98 $this->checkFile($php_path, $file);
102 private function checkFile($php_path, $file)
104 if ($this->getOption('v')) {
105 $this->out('Checking ' . $file);
110 exec("$php_path -l $file", $output, $ret);
112 throw new \RuntimeException('Parse error found in ' . $file . ', scan stopped.');