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 <mrpetovan@gmail.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');
46 $php_path = $a->getConfigValue('config', 'php_path', 'php');
48 if ($this->getOption('v')) {
49 $this->out('Directory: src');
52 $Iterator = new \RecursiveDirectoryIterator('src');
54 foreach (new \RecursiveIteratorIterator($Iterator) as $file) {
55 if (substr($file, -4) === '.php') {
56 $this->checkFile($php_path, $file);
60 if ($this->getOption('v')) {
61 $this->out('Directory: mod');
64 $files = glob('mod/*.php');
65 $this->checkFiles($php_path, $files);
67 if ($this->getOption('v')) {
68 $this->out('Directory: include');
71 $files = glob('include/*.php');
72 $this->checkFiles($php_path, $files);
74 if ($this->getOption('v')) {
75 $this->out('Directory: addon');
78 $dirs = glob('addon/*');
79 foreach ($dirs as $dir) {
80 $addon = basename($dir);
81 $files = glob($dir . '/' . $addon . '.php');
82 $this->checkFiles($php_path, $files);
85 if ($this->getOption('v')) {
86 $this->out('String files');
89 $this->checkFile($php_path, 'util/strings.php');
91 $files = glob('view/lang/*/strings.php');
92 $this->checkFiles($php_path, $files);
94 $this->out('No errors.');
99 private function checkFiles($php_path, array $files)
101 foreach ($files as $file) {
102 $this->checkFile($php_path, $file);
106 private function checkFile($php_path, $file)
108 if ($this->getOption('v')) {
109 $this->out('Checking ' . $file);
114 exec("$php_path -l $file", $output, $ret);
116 throw new \RuntimeException('Parse error found in ' . $file . ', scan stopped.');