3 namespace Friendica\Console;
5 use Friendica\BaseObject;
8 * Tired of chasing typos and finding them after a commit.
9 * Run this and quickly see if we've got any parse errors in our application files.
11 * @author Hypolite Petovan <hypolite@mrpetovan.com>
13 class Typo extends \Asika\SimpleConsole\Console
15 protected $helpOptions = ['h', 'help', '?'];
17 protected function getHelp()
20 console typo - Checks for parse errors in Friendica files
22 bin/console typo [-h|--help|-?] [-v]
25 Checks all PHP files in the Friendica file tree for parse errors
28 -h|--help|-? Show help information
29 -v Show more debug information.
34 protected function doExecute()
36 if ($this->getOption('v')) {
37 $this->out('Class: ' . __CLASS__);
38 $this->out('Arguments: ' . var_export($this->args, true));
39 $this->out('Options: ' . var_export($this->options, true));
42 if (count($this->args) > 0) {
43 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
46 $php_path = BaseObject::getApp()->getConfigCache()->get('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 $files = glob('view/lang/*/strings.php');
90 $this->checkFiles($php_path, $files);
92 $this->out('No errors.');
97 private function checkFiles($php_path, array $files)
99 foreach ($files as $file) {
100 $this->checkFile($php_path, $file);
104 private function checkFile($php_path, $file)
106 if ($this->getOption('v')) {
107 $this->out('Checking ' . $file);
112 exec("$php_path -l $file", $output, $ret);
114 throw new \RuntimeException('Parse error found in ' . $file . ', scan stopped.');