summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-05-09 15:46:33 +0200
committerJoas Schilling <coding@schilljs.com>2017-05-16 16:16:07 +0200
commit93fc7fcdbef0fdd0fda1ea2be9047817bb68524c (patch)
tree85d23c11983fbbba5b5d771b7e2425ca58f092b2 /lib
parente22b957d7f8705ba87096b05fbb375aca392b076 (diff)
downloadnextcloud-server-93fc7fcdbef0fdd0fda1ea2be9047817bb68524c.tar.gz
nextcloud-server-93fc7fcdbef0fdd0fda1ea2be9047817bb68524c.zip
Check the syntax of the language file
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/App/CodeChecker/LanguageParseChecker.php56
3 files changed, 58 insertions, 0 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 59cac3db775..19380f6571b 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -336,6 +336,7 @@ return array(
'OC\\App\\CodeChecker\\EmptyCheck' => $baseDir . '/lib/private/App/CodeChecker/EmptyCheck.php',
'OC\\App\\CodeChecker\\ICheck' => $baseDir . '/lib/private/App/CodeChecker/ICheck.php',
'OC\\App\\CodeChecker\\InfoChecker' => $baseDir . '/lib/private/App/CodeChecker/InfoChecker.php',
+ 'OC\\App\\CodeChecker\\LanguageParseChecker' => $baseDir . '/lib/private/App/CodeChecker/LanguageParseChecker.php',
'OC\\App\\CodeChecker\\NodeVisitor' => $baseDir . '/lib/private/App/CodeChecker/NodeVisitor.php',
'OC\\App\\CodeChecker\\PrivateCheck' => $baseDir . '/lib/private/App/CodeChecker/PrivateCheck.php',
'OC\\App\\CodeChecker\\StrongComparisonCheck' => $baseDir . '/lib/private/App/CodeChecker/StrongComparisonCheck.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index b7e584c324a..46285356489 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -366,6 +366,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\App\\CodeChecker\\EmptyCheck' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/EmptyCheck.php',
'OC\\App\\CodeChecker\\ICheck' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/ICheck.php',
'OC\\App\\CodeChecker\\InfoChecker' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/InfoChecker.php',
+ 'OC\\App\\CodeChecker\\LanguageParseChecker' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/LanguageParseChecker.php',
'OC\\App\\CodeChecker\\NodeVisitor' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/NodeVisitor.php',
'OC\\App\\CodeChecker\\PrivateCheck' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/PrivateCheck.php',
'OC\\App\\CodeChecker\\StrongComparisonCheck' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/StrongComparisonCheck.php',
diff --git a/lib/private/App/CodeChecker/LanguageParseChecker.php b/lib/private/App/CodeChecker/LanguageParseChecker.php
new file mode 100644
index 00000000000..29331d1e648
--- /dev/null
+++ b/lib/private/App/CodeChecker/LanguageParseChecker.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017, Joas Schilling <coding@schilljs.com>
+ *
+ * @author Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\App\CodeChecker;
+
+class LanguageParseChecker {
+
+ /**
+ * @param string $appId
+ * @return array
+ */
+ public function analyse($appId) {
+ $appPath = \OC_App::getAppPath($appId);
+ if ($appPath === false) {
+ throw new \RuntimeException("No app with given id <$appId> known.");
+ }
+
+ $errors = [];
+ $directory = new \DirectoryIterator($appPath . '/l10n/');
+
+ foreach ($directory as $file) {
+ if ($file->getExtension() !== 'json') {
+ continue;
+ }
+
+ $content = file_get_contents($file->getPathname());
+ json_decode($content, true);
+
+ if (json_last_error() !== JSON_ERROR_NONE) {
+ $errors[] = 'Invalid language file found: l10n/' . $file->getFilename() . ': ' . json_last_error_msg();
+ }
+ }
+
+ return $errors;
+ }
+}