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()->getConfig()->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: tests');
64 $Iterator = new \RecursiveDirectoryIterator('tests');
66 foreach (new \RecursiveIteratorIterator($Iterator) as $file) {
67 if (substr($file, -4) === '.php') {
68 $this->checkFile($php_path, $file);
72 if ($this->getOption('v')) {
73 $this->out('Directory: mod');
76 $files = glob('mod/*.php');
77 $this->checkFiles($php_path, $files);
79 if ($this->getOption('v')) {
80 $this->out('Directory: include');
83 $files = glob('include/*.php');
84 $this->checkFiles($php_path, $files);
86 if ($this->getOption('v')) {
87 $this->out('Directory: addon');
90 $dirs = glob('addon/*');
91 foreach ($dirs as $dir) {
92 $addon = basename($dir);
93 $files = glob($dir . '/' . $addon . '.php');
94 $this->checkFiles($php_path, $files);
97 if ($this->getOption('v')) {
98 $this->out('String files');
101 $files = glob('view/lang/*/strings.php');
102 $this->checkFiles($php_path, $files);
104 $this->out('No errors.');
109 private function checkFiles($php_path, array $files)
111 foreach ($files as $file) {
112 $this->checkFile($php_path, $file);
116 private function checkFile($php_path, $file)
118 if ($this->getOption('v')) {
119 $this->out('Checking ' . $file);
124 exec("$php_path -l $file", $output, $ret);
126 throw new \RuntimeException('Parse error found in ' . $file . ', scan stopped.');