From 7a974c13bc3a0339f50795044fe495050b242701 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 11 Mar 2017 14:30:01 +0100 Subject: [PATCH] Added missing subdirectories --- .gitignore | 2 +- Configs/composer.json | 5 + Configs/phpcs.xml | 102 ++++++++++++++++++++ Configs/phpmd.xml | 100 ++++++++++++++++++++ Helper/ipGeoLocationBuilder.php | 19 ++++ Helper/pre_commit.sh | 13 +++ Helper/testGenerator.php | 129 ++++++++++++++++++++++++++ Helper/watcher.sh | 18 ++++ Inspection/Html/attributes.sh | 12 +++ Inspection/Html/tags.sh | 30 ++++++ Inspection/Js/linting.sh | 0 Inspection/Js/tests.sh | 0 Inspection/Json/linting.sh | 5 + Inspection/Logic/module_json.sh | 0 Inspection/Logic/module_navigation.sh | 0 Inspection/Logic/module_route.sh | 0 Inspection/Php/linting.sh | 11 +++ Inspection/Php/security.sh | 42 +++++++++ Inspection/Php/stats.sh | 12 +++ Inspection/Php/tests.sh | 8 ++ Inspection/Php/tools.sh | 10 ++ README.md | 12 +++ config.sh | 1 + setup.sh | 5 +- 24 files changed, 532 insertions(+), 4 deletions(-) create mode 100644 Configs/composer.json create mode 100644 Configs/phpcs.xml create mode 100644 Configs/phpmd.xml create mode 100644 Helper/ipGeoLocationBuilder.php create mode 100644 Helper/pre_commit.sh create mode 100644 Helper/testGenerator.php create mode 100644 Helper/watcher.sh create mode 100644 Inspection/Html/attributes.sh create mode 100644 Inspection/Html/tags.sh create mode 100644 Inspection/Js/linting.sh create mode 100644 Inspection/Js/tests.sh create mode 100644 Inspection/Json/linting.sh create mode 100644 Inspection/Logic/module_json.sh create mode 100644 Inspection/Logic/module_navigation.sh create mode 100644 Inspection/Logic/module_route.sh create mode 100644 Inspection/Php/linting.sh create mode 100644 Inspection/Php/security.sh create mode 100644 Inspection/Php/stats.sh create mode 100644 Inspection/Php/tests.sh create mode 100644 Inspection/Php/tools.sh diff --git a/.gitignore b/.gitignore index 530234e..8b13789 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -**/ + diff --git a/Configs/composer.json b/Configs/composer.json new file mode 100644 index 0000000..98021be --- /dev/null +++ b/Configs/composer.json @@ -0,0 +1,5 @@ +{ + "require-dev": { + "johnkary/phpunit-speedtrap": "^1.0" + } +} diff --git a/Configs/phpcs.xml b/Configs/phpcs.xml new file mode 100644 index 0000000..12e1f58 --- /dev/null +++ b/Configs/phpcs.xml @@ -0,0 +1,102 @@ + + + Orange Management ruleset! www.orange-management.de + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Configs/phpmd.xml b/Configs/phpmd.xml new file mode 100644 index 0000000..f9a6818 --- /dev/null +++ b/Configs/phpmd.xml @@ -0,0 +1,100 @@ + + +Orange Management ruleset! www.orange-management.de + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Helper/ipGeoLocationBuilder.php b/Helper/ipGeoLocationBuilder.php new file mode 100644 index 0000000..2ac09c4 --- /dev/null +++ b/Helper/ipGeoLocationBuilder.php @@ -0,0 +1,19 @@ + /dev/null + if [ $? -ne 0 ]; then + echo -e "\e[1;31m\tAborting commit due to files with syntax errors.\e[0m" >&2 + exit 1 + fi + fi +fi +done || exit $? diff --git a/Helper/testGenerator.php b/Helper/testGenerator.php new file mode 100644 index 0000000..27fc7c4 --- /dev/null +++ b/Helper/testGenerator.php @@ -0,0 +1,129 @@ += 0 && strpos($haystack, $needle, $temp) !== false); +} + +function listFolderFiles($dir, $extension) +{ + $files = []; + $ffs = scandir($dir); + foreach ($ffs as $ff) { + if ($ff !== '.' && $ff !== '..') { + if (is_dir($dir . '/' . $ff)) { + $files = array_merge($files, listFolderFiles($dir . '/' . $ff, $extension)); + } else { + if (endsWith($ff, $extension)) { + $files[] = $dir . '/' . $ff; + } + } + } + } + + return $files; +} + +// PHP tests +$base = __DIR__ . '/../phpOMS'; +$files = listFolderFiles($base, '.php'); +$testBase = __DIR__ . '/../Tests/PHPUnit/Framework'; + +foreach ($files as $file) { + $file = str_replace($base, '', $file); + $subdir = trim($file, '/'); + $split = explode('.', $file); + $testPath = $testBase . '/' . $split[0] . 'Test.' . $split[1]; + + if (stripos($subdir, 'Interface') === false + && stripos($subdir, 'Trait') === false + && stripos($subdir, 'Abstract') === false + ) { + if (!file_exists($testPath)) { + $namespace = str_replace('/', '\\', $split[0]); + $namespace = explode('\\', $namespace); + $classnameSrc = $namespace[count($namespace) - 1]; + $classname = $classnameSrc . 'Test'; + unset($namespace[count($namespace) - 1]); + $use = trim('phpOMS\\' . trim(implode('\\', $namespace), '\\') . '\\' . $classnameSrc, '\\'); + $namespace = trim('Tests\PHPUnit\Framework\\' . trim(implode('\\', $namespace), '\\'), '\\'); + $autoloader = str_repeat('/..', count(explode('\\', $namespace))); + + if(!file_exists(dirname($testPath))) { + mkdir(dirname($testPath), 0777, true); + } + + file_put_contents($testPath, + '' . PHP_EOL + . ' * @author Dennis Eichhorn ' . PHP_EOL + . ' * @copyright Dennis Eichhorn' . PHP_EOL + . ' * @license OMS License 1.0' . PHP_EOL + . ' * @version 1.0.0' . PHP_EOL + . ' * @link http://orange-management.com' . PHP_EOL + . ' */' . PHP_EOL + . '' . PHP_EOL + . 'namespace ' . $namespace . ';' . PHP_EOL + . '' . PHP_EOL + . 'require_once __DIR__ . \'' . $autoloader . '/phpOMS/Autoloader.php\';' . PHP_EOL + . '' . PHP_EOL + . 'use ' . $use . ';' . PHP_EOL + . '' . PHP_EOL + . 'class ' . $classname . ' extends \PHPUnit_Framework_TestCase' . PHP_EOL + . '{' . PHP_EOL + . ' public function testPlaceholder()' . PHP_EOL + . ' {' . PHP_EOL + . ' self::markTestIncomplete();' . PHP_EOL + . ' }' . PHP_EOL + . '}' . PHP_EOL + ); + } + } +} + +// JS tests +$base = __DIR__ . '/../jsOMS'; +$files = listFolderFiles($base, '.js'); +$testBase = __DIR__ . '/../Tests/JS/Framework'; + +foreach ($files as $file) { + $file = str_replace($base, '', $file); + $subdir = trim($file, '/'); + $split = explode('.', $file); + $testPath = $testBase . '/' . $split[0] . 'Test.' . $split[1]; + + if (stripos($subdir, 'Interface') === false + && stripos($subdir, 'Trait') === false + && stripos($subdir, 'Abstract') === false + ) { + if (!file_exists($testPath)) { + $name = explode('/', $split[0]); + + if(!file_exists(dirname($testPath))) { + mkdir(dirname($testPath), 0777, true); + } + + file_put_contents($testPath, + 'describe(\'' . $name[count($name) - 1] . 'Test\', function ()' . PHP_EOL + . '{' . PHP_EOL + . ' "use strict";' . PHP_EOL + . '' . PHP_EOL + . ' beforeEach(function ()' . PHP_EOL + . ' {' . PHP_EOL + . ' });' . PHP_EOL + . '' . PHP_EOL + . ' afterEach(function ()' . PHP_EOL + . ' {' . PHP_EOL + . ' });' . PHP_EOL + . '}' . PHP_EOL + ); + } + } +} \ No newline at end of file diff --git a/Helper/watcher.sh b/Helper/watcher.sh new file mode 100644 index 0000000..7291e28 --- /dev/null +++ b/Helper/watcher.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +DIRECTORY_TO_OBSERVE="cssOMS jsOMS" +function watcher { + inotifywait -r -e modify,move,create,delete \ + --exclude ".*(\.css|\.php|\.json|\.md|\.sh|\.txt|\.log|\.min\.js)" \ + ${DIRECTORY_TO_OBSERVE} +} + +BUILD_SCRIPT=build_frontend.sh +function build { + bash ${BUILD_SCRIPT} +} + +build +while watcher; do + build +done diff --git a/Inspection/Html/attributes.sh b/Inspection/Html/attributes.sh new file mode 100644 index 0000000..750a5ee --- /dev/null +++ b/Inspection/Html/attributes.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +. ../../config.sh + +# Find empty attributes +grep -rln "=\"\"" --include \*.tpl.php ${ROOT_PATH} > ${INSPECTION_PATH}/Modules/html/attributes_empty.log + +# Find invalid attributes +find ${ROOT_PATH} -name "*tpl.php" | xargs -0 grep '(id=")([\ ]*)(")' >> ${INSPECTION_PATH}/Modules/html/attributes_invalid.log +find ${ROOT_PATH} -name "*tpl.php" | xargs -0 grep '(min=")([a-zA-Z]*)(")' >> ${INSPECTION_PATH}/Modules/html/attributes_invalid.log +find ${ROOT_PATH} -name "*tpl.php" | xargs -0 grep '(max=")([a-zA-Z]*)(")' >> ${INSPECTION_PATH}/Modules/html/attributes_invalid.log +find ${ROOT_PATH} -name "*tpl.php" | xargs -0 grep '(=")([#$%^&*\(\)\\/]*)(")' >> ${INSPECTION_PATH}/Modules/html/attributes_invalid.log diff --git a/Inspection/Html/tags.sh b/Inspection/Html/tags.sh new file mode 100644 index 0000000..a944c2e --- /dev/null +++ b/Inspection/Html/tags.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +. ../../config.s + +# Html tag inspection +TAG[0]="<\/html>" +TAG[1]="<\/body>" +TAG[2]="<\/head>" +TAG[3]="<\/thead>" +TAG[4]="<\/tbody>" +TAG[5]="<\/tfoot>" +TAG[6]="<\/tr>" +TAG[7]="<\/th>" +TAG[8]="<\/td>" +TAG[9]="<\/option>" +TAG[10]="<\/li>" +TAG[11]="" +TAG[12]="" +TAG[13]="" +TAG[14]="" +TAG[15]="" +TAG[16]="" +TAG[17]="" +TAG[18]="" + +for i in "${TAG[@]}" +do + grep -rln "$i" --include \*.tpl.php ${ROOT_PATH}/phpOMS >> ${INSPECTION_PATH}/Framework/html/tags.log + grep -rln "$i" --include \*.tpl.php ${ROOT_PATH}/Modules >> ${INSPECTION_PATH}/Modules/html/tags.log +done diff --git a/Inspection/Js/linting.sh b/Inspection/Js/linting.sh new file mode 100644 index 0000000..e69de29 diff --git a/Inspection/Js/tests.sh b/Inspection/Js/tests.sh new file mode 100644 index 0000000..e69de29 diff --git a/Inspection/Json/linting.sh b/Inspection/Json/linting.sh new file mode 100644 index 0000000..1b58150 --- /dev/null +++ b/Inspection/Json/linting.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +. ../../config.s + +find ${ROOT_PATH} -name "*.json" | xargs -L1 jsonlint -q > ${INSPECTION_PATH}/Modules/linting/linting_json.log \ No newline at end of file diff --git a/Inspection/Logic/module_json.sh b/Inspection/Logic/module_json.sh new file mode 100644 index 0000000..e69de29 diff --git a/Inspection/Logic/module_navigation.sh b/Inspection/Logic/module_navigation.sh new file mode 100644 index 0000000..e69de29 diff --git a/Inspection/Logic/module_route.sh b/Inspection/Logic/module_route.sh new file mode 100644 index 0000000..e69de29 diff --git a/Inspection/Php/linting.sh b/Inspection/Php/linting.sh new file mode 100644 index 0000000..5ad9281 --- /dev/null +++ b/Inspection/Php/linting.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +. ../../config.s + +find ${ROOT_PATH}/phpOMS -name "*.php" | xargs -L1 php -l > ${INSPECTION_PATH}/logs/temp.log +sed '/^No syntax.*/ d' < ${INSPECTION_PATH}/logs/temp.log > ${INSPECTION_PATH}/Framework/linting/linting_php.log + +find ${ROOT_PATH}/Modules -name "*.php" | xargs -L1 php -l > ${INSPECTION_PATH}/logs/temp.log +sed '/^No syntax.*/ d' < ${INSPECTION_PATH}/logs/temp.log > ${INSPECTION_PATH}/Modules/linting/linting_php.log + +rm ${INSPECTION_PATH}/logs/temp.log \ No newline at end of file diff --git a/Inspection/Php/security.sh b/Inspection/Php/security.sh new file mode 100644 index 0000000..641c497 --- /dev/null +++ b/Inspection/Php/security.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +. ../../config.s + +# PHP code inspection +CODE[0]="file_get_content" +CODE[1]="fopen" +CODE[2]="include" +CODE[3]="require" +CODE[4]="file_put_content" +CODE[5]="fread" +CODE[6]="fwrite" +CODE[7]="fget" +CODE[8]="fput" +CODE[9]="chmod" +CODE[10]="eval" +CODE[11]="delete" +CODE[12]="mkdir" +CODE[13]="move_uploaded_file" +CODE[14]="mkdir" +CODE[15]="copy" +CODE[16]="chown" +CODE[17]="touch" +CODE[18]="exec" +CODE[19]="_GET" +CODE[20]="_POST" +CODE[21]="_SESSION" +CODE[22]="_REQUEST" +CODE[23]="_SERVER" +CODE[24]="_COOKIE" +CODE[25]="_FILES" +CODE[26]="unlink" +CODE[27]="action=\"" + +for i in "${CODE[@]}" +do + grep -rln "$i" --include \*.php ${ROOT_PATH}/phpOMS >> ${INSPECTION_PATH}/Framework/critical_php.log + grep -rln "$i" --include \*.php ${ROOT_PATH}/Modules >> ${INSPECTION_PATH}/Modules/citical_php.log +done + +# PHP strict type +grep -r -L "declare\(\ *strict_types\ *=\ *1\ *\);" --include=*.php ${ROOT_PATH}/phpOMS > ${INSPECTION_PATH}/Framework/strict_missing.log \ No newline at end of file diff --git a/Inspection/Php/stats.sh b/Inspection/Php/stats.sh new file mode 100644 index 0000000..c34f07a --- /dev/null +++ b/Inspection/Php/stats.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +. ../../config.s + +php ${TOOLS_PATH}/phploc.phar ${ROOT_PATH}/phpOMS/ > ${INSPECTION_PATH}/Framework/phploc.log +php ${TOOLS_PATH}/phploc.phar ${ROOT_PATH}/Modules/ > ${INSPECTION_PATH}/Modules/phploc.log + +php ${TOOLS_PATH}/phpmetrics.phar --report-html=${INSPECTION_PATH}/Framework/metrics/metrics.html ${ROOT_PATH}/phpOMS/ >> ${INSPECTION_PATH}/Framework/build.log +php ${TOOLS_PATH}/phpmetrics.phar --report-html=${INSPECTION_PATH}/Modules/metrics/metrics.html ${ROOT_PATH}/Modules/ >> ${INSPECTION_PATH}/Modules/build.log + +php ${TOOLS_PATH}/pdepend.phar --summary-xml=${INSPECTION_PATH}/Framework/pdepend/pdepend.xml --jdepend-chart=${INSPECTION_PATH}/Framework/pdepend/chart.svg --overview-pyramid=${INSPECTION_PATH}/Framework/pdepend/pyramid.svg ${ROOT_PATH}/phpOMS +php ${TOOLS_PATH}/pdepend.phar --summary-xml=${INSPECTION_PATH}/Modules/pdepend/pdepend.xml --jdepend-chart=${INSPECTION_PATH}/Modules/pdepend/chart.svg --overview-pyramid=${INSPECTION_PATH}/Modules/pdepend/pyramid.svg ${ROOT_PATH}/Modules diff --git a/Inspection/Php/tests.sh b/Inspection/Php/tests.sh new file mode 100644 index 0000000..e589bf2 --- /dev/null +++ b/Inspection/Php/tests.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +. ../../config.s + +php ${TOOLS_PATH}/phpunit.phar --configuration ${TEST_PATH}/PHPUnit/phpunit_default.xml > ${INSPECTION_PATH}/logs/phpunit.log +#phpdbg -qrr phpunit.phar --configuration Tests/PHPUnit/phpunit_default.xml +#php Documentor/src/index.php -s C:\Users\coyle\Desktop\Orange-Management\phpOMS -d C:\Users\coyle\Desktop\outtest -c C:\Users\coyle\Desktop\Orange-Management\Build\log\coverage.xml -u C:\Users\coyle\Desktop\Orange-Management\Build\log\test.xml -g C:\Users\coyle\Desktop\Orange-Management\Developer-Guide +#phpdbg -qrr phpunit.phar Tests/PHPUnit/Framework/Math/Matrix/MatrixTest.php --bootstrap Tests/PHPUnit/Bootstrap.php \ No newline at end of file diff --git a/Inspection/Php/tools.sh b/Inspection/Php/tools.sh new file mode 100644 index 0000000..9e312bb --- /dev/null +++ b/Inspection/Php/tools.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +. ../../config.s + +php ${TOOLS_PATH}/phpcs.phar --report-file=${INSPECTION_PATH}/Framework/phpcs/phpcs.log --ignore=${ROOT_PATH}/phpOMS/Localization --standard=${INSPECTION_PATH}/Configs/phpcs.xml ${ROOT_PATH}/phpOMS +php ${TOOLS_PATH}/phpcs.phar --report-file=${INSPECTION_PATH}/Modules/phpcs/phpcs.log --standard=${INSPECTION_PATH}/Configs/phpcs.xml ${ROOT_PATH}/Modules +#php ${TOOLS_PATH}/phpmd.phar ${ROOT_PATH}/phpOMS xml ${INSPECTION_PATH}/Configs/phpmd.xml --reportfile ${INSPECTION_PATH}/logs/phpmdFramework.log -- bzip missing +#php ${TOOLS_PATH}/phpmd.phar ${ROOT_PATH}/Modules xml ${INSPECTION_PATH}/Configs/phpmd.xml --reportfile ${INSPECTION_PATH}/logs/phpmdModules.log -- bzip missing +php ${TOOLS_PATH}/phpcpd.phar ${ROOT_PATH}/phpOMS --exclude Localization --no-interaction > ${INSPECTION_PATH}/Framework/phpcpd/phpcpd.log +php ${TOOLS_PATH}/phpcpd.phar ${ROOT_PATH}/Modules --no-interaction > ${INSPECTION_PATH}/Modules/phpcpd/phpcpd.log \ No newline at end of file diff --git a/README.md b/README.md index 9dfff35..aea2adb 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,18 @@ The last feature is the backend and documentation generation based on the DocBlo * Modify the `config.sh` file to your needs * Run `setup.sh` +## Dependencies + +The build system will take care of most requirements, the following tools and commands have to be available on the system. + +* npm +* git +* wget +* curl +* grep +* xargs +* sed + # Usage * Run `build_dev.sh` diff --git a/config.sh b/config.sh index b3e4a06..5b4330b 100644 --- a/config.sh +++ b/config.sh @@ -3,6 +3,7 @@ # Paths BASE_PATH="/var/www/html" ROOT_PATH="/var/www/html/Orange-Management" +BUILD_PATH="/var/www/Build" TOOLS_PATH="/var/www/html/Tools" RELEASE_PATH="/var/www/html/Release" diff --git a/setup.sh b/setup.sh index 97c0522..adeacd2 100644 --- a/setup.sh +++ b/setup.sh @@ -12,9 +12,6 @@ mkdir -p ${INSPECTION_PATH} rm -r -f ${TOOLS_PATH} mkdir -p ${TOOLS_PATH} -rm -r -f ${BUILD_PATH} -mkdir -p ${BUILD_PATH} - # Handling git c=0; for i in "${GITHUB_URL[@]}" @@ -76,6 +73,8 @@ wget -nc https://phar.phpunit.de/phpcpd.phar wget -nc http://dl.google.com/closure-compiler/compiler-latest.tar.gz tar -zxvf compiler-latest.tar.gz +cp ${BUILD_PATH}/Configs/composer.json ${TOOLS_PATH}/composer.json + php composer.phar install # Installing tools