diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c72cfa3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,27 @@ +# EditorConfig helps keep your project formatting consistent. +# See https://EditorConfig.org +# +# PHP PSR-2 Coding Standards +# http://www.php-fig.org/psr/psr-2/ +# +# Author: Sal Ferrarello (@salcode) +# +# You can download this file directly +# to your project from the command-line with +# curl -O https://gist.githubusercontent.com/salcode/18eaa8cfa3b097da2f58b582197906d7/raw/.editorconfig + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 2 + +[*.php] +indent_size = 4 + +[*.md] +trim_trailing_whitespace = false diff --git a/bin/app.php b/bin/app.php index a9acede..3098c07 100755 --- a/bin/app.php +++ b/bin/app.php @@ -4,7 +4,17 @@ use Consolidation\AnnotatedCommand\CommandFileDiscovery; use Symfony\Component\Console\Output\ConsoleOutput; -require_once __DIR__ . '/../vendor/autoload.php'; +foreach ([ + // Legacy-style autoload. + '/../vendor/autoload.php', + // Under vendor. + '/../../vendor/autoload.php', + ] as $path) { + $pathy = __DIR__ . $path; + if (file_exists($pathy)) { + require_once $pathy; + } +} putenv("COMPOSER_MEMORY_LIMIT=-1"); diff --git a/bin/dktl b/bin/dktl index 7846af7..93d4476 100755 --- a/bin/dktl +++ b/bin/dktl @@ -13,7 +13,7 @@ main() { set_project_directory "$@" set_slug - + if [ "$DKTL_MODE" = "DOCKER" ]; then dktl_docker_run "$@" elif [ "$DKTL_MODE" = "HOST" ]; then @@ -52,20 +52,20 @@ dktl_docker_run() { # Proxy-pass to docker and save exit status. The command will re- # run in host mode inside the cli container, so dktl_run will still - # ultimately be run whichever mode dktl is set to. + # ultimately be run whichever mode dktl is set to. dc_base exec $EXEC_OPTS cli dktl "$1" "${@:2}" exit_status=$? dktl_docker_cleanup "$@" - # if we encountered a non-zero exit status during the docker exec, + # if we encountered a non-zero exit status during the docker exec, # pass it on. if [ $exit_status -ne 0 ]; then exit $exit_status fi } -# Set DKTL_PLATFORM to which platform we're running on (linux and mac +# Set DKTL_PLATFORM to which platform we're running on (linux and mac # supported) set_platform() { if [ -z $PLATFORM ]; then @@ -73,7 +73,7 @@ set_platform() { fi } -# Set DKTL_MODE. Determine whether we want to run inside the docker container +# Set DKTL_MODE. Determine whether we want to run inside the docker container # or in the host machine. set_mode() { if [ -z $DKTL_MODE ] || [ "$DKTL_MODE" = "DOCKER" ]; then @@ -103,22 +103,25 @@ check_dependencies() { # Set DKTL_PROJECT_DIRECTORY. Needs "$@" because dktl init hsa different logic. set_project_directory() { - # Find project root so we can run from anywhere - find_up () { - path=$(pwd) - while [[ "$path" != "" && ! -e "$path/$1" ]]; do - path=${path%/*} - done - echo "$path" - } - - if [ "$1" = "init" ] || [ "$1" = "down" ]; then + if [ -z "$DKTL_PROJECT_DIRECTORY" ]; then DKTL_PROJECT_DIRECTORY=$(pwd) - else - DKTL_PROJECT_DIRECTORY=$(find_up dktl.yml) - if [ -z "$DKTL_PROJECT_DIRECTORY" ]; then - echo "DKTL is running outside of a DKTL project. Run dktl init in the project directory first." - exit 1 + # Find project root so we can run from anywhere + find_up () { + path=$(pwd) + while [[ "$path" != "" && ! -e "$path/$1" ]]; do + path=${path%/*} + done + echo "$path" + } + + if [ "$1" = "init" ] || [ "$1" = "down" ]; then + DKTL_PROJECT_DIRECTORY=$(pwd) + else + DKTL_PROJECT_DIRECTORY=$(find_up dktl.yml) + if [ -z "$DKTL_PROJECT_DIRECTORY" ]; then + echo "DKTL is running outside of a DKTL project. Run dktl init in the project directory first." + exit 1 + fi fi fi export DKTL_PROJECT_DIRECTORY @@ -126,17 +129,20 @@ set_project_directory() { # Set DKTL_DIRECTORY set_directory() { - DKTL_DIRECTORY=$(which dktl) + if [ -z "$DKTL_DIRECTORY" ]; then + DKTL_DIRECTORY=$(which dktl) - if [[ -L $(which dktl) ]]; then - # readlink command needs -f to work properly in linux - if [ "$PLATFORM" = "Linux" ]; then RL_OPT='-f'; fi; - DKTL_DIRECTORY=$(readlink $RL_OPT "$DKTL_DIRECTORY") - fi + if [[ -L $(which dktl) ]]; then + # readlink command needs -f to work properly in linux + if [ "$PLATFORM" = "Linux" ]; then RL_OPT='-f'; fi; + DKTL_DIRECTORY=$(readlink $RL_OPT "$DKTL_DIRECTORY") + fi - # Currently DKTL_DIRECTORY contains /bin/dktl, strip the - # /bin/dktl to get the root dktl directory. - DKTL_DIRECTORY="${DKTL_DIRECTORY%/bin/dktl}" + # TODO: Figure out a way to modify the path without making assumptions. + # Currently DKTL_DIRECTORY contains /bin/dktl, strip the + # /bin/dktl to get the root dktl directory. + DKTL_DIRECTORY="${DKTL_DIRECTORY%/bin/dktl}" + fi export DKTL_DIRECTORY } diff --git a/composer.json b/composer.json index c7f060b..43bd27f 100644 --- a/composer.json +++ b/composer.json @@ -5,6 +5,10 @@ "pear/archive_tar": "^1.4", "aws/aws-sdk-php": "^3.67" }, + "bin": [ + "bin/dktl", + "bin/app.php" + ], "autoload": { "psr-4": { "DkanTools\\": "src", @@ -15,5 +19,8 @@ "platform": { "php": "7.4" } + }, + "require-dev": { + "squizlabs/php_codesniffer": "^3.7" } } diff --git a/composer.lock b/composer.lock index c7a4abb..734aba2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fe253ea4beefd6b14efcc890d092a240", + "content-hash": "b5feae8d371314005ccfdd48444c15dc", "packages": [ { "name": "aws/aws-crt-php", @@ -3032,7 +3032,64 @@ "time": "2022-01-26T16:32:32+00:00" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "squizlabs/php_codesniffer", + "version": "3.7.0", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "a2cd51b45bcaef9c1f2a4bda48f2dd2fa2b95563" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/a2cd51b45bcaef9c1f2a4bda48f2dd2fa2b95563", + "reference": "a2cd51b45bcaef9c1f2a4bda48f2dd2fa2b95563", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, + "time": "2022-06-13T06:31:38+00:00" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], @@ -3043,5 +3100,5 @@ "platform-overrides": { "php": "7.4" }, - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..9e349c3 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,21 @@ + + + The coding standard for DKAN Tools. + + */bin/dktl + */assets + */vendor + + + + + + + + + + + + + diff --git a/src/Command/ProjectCommands.php b/src/Command/ProjectCommands.php index 43a4fa7..9e7c384 100644 --- a/src/Command/ProjectCommands.php +++ b/src/Command/ProjectCommands.php @@ -72,8 +72,7 @@ protected function symlinkOrInstallCypress(): void if ($result->getExitCode() !== 0) { throw new \RuntimeException('Failed to symlink cypress package folder'); } - } - else { + } else { $this->io()->warning('Cypress installation not found in standard location; Attempting to install cypress locally...'); $result = $this->taskExec('npm install cypress') ->dir(self::TESTS_DIR) diff --git a/src/Util/Util.php b/src/Util/Util.php index 774ed8b..7b0cbba 100644 --- a/src/Util/Util.php +++ b/src/Util/Util.php @@ -9,6 +9,7 @@ */ class Util { + const TMP_DIR = "/tmp/dktl"; public static function getDktlDirectory() @@ -27,12 +28,13 @@ public static function getDktlProxyDomain() public static function getProjectDirectory() { + if ($proj_dir = getenv("DKTL_PROJECT_DIRECTORY")) { + return $proj_dir; + } if (isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == "init") { $directory = exec("pwd"); return $directory; } - - return getenv("DKTL_PROJECT_DIRECTORY"); } public static function getUri() @@ -80,7 +82,7 @@ public static function urlExists($url) $headers = @get_headers($url); return (count(preg_grep('/^HTTP.*404/', $headers)) > 0) ? false : true; } - + public static function directoryAndFileCreationCheck(\Robo\Result $result, $df, $io) { if ($result->getExitCode() == 0 && file_exists($df)) { @@ -95,7 +97,11 @@ public static function directoryAndFileCreationCheck(\Robo\Result $result, $df, */ public static function generateHashSalt($count = 32) { - return str_replace(['+', '/', '='], ['-', '_', ''], base64_encode(random_bytes($count))); + return str_replace(['+', '/', '='], [ + '-', + '_', + '', + ], base64_encode(random_bytes($count))); } /** @@ -106,7 +112,7 @@ public static function generateHashSalt($count = 32) public static function ensureFilesExist(array $paths, $message) { foreach ($paths as $path) { - if (! file_exists($path)) { + if (!file_exists($path)) { throw new \Exception("{$path} is missing."); } }