From 91c334ffff46f0869eb2f9e4fa6915a6bea5eca8 Mon Sep 17 00:00:00 2001 From: "Buster \"Silver Eagle\" Neece" Date: Wed, 30 Jan 2019 21:36:07 -0600 Subject: [PATCH] Create PHPStan bootstrap file, integrate into Travis CI. --- .travis.yml | 1 + composer.lock | 8 +++---- docker.sh | 19 +++++++++++++++ phpstan.neon | 23 +------------------ src/Controller/Frontend/ApiKeysController.php | 4 ++++ util/phpstan.php | 22 ++++++++++++++++++ 6 files changed, 51 insertions(+), 26 deletions(-) create mode 100644 util/phpstan.php diff --git a/.travis.yml b/.travis.yml index 3fec4599f..e461ec03c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,7 @@ install: - docker-compose -f docker-compose.sample.yml -f docker-compose.testing.yml run --user="azuracast" --rm web azuracast_install script: + - docker-compose -f docker-compose.sample.yml -f docker-compose.testing.yml run --user="azuracast" --rm web /var/azuracast/www/vendor/bin/phpstan analyze - docker-compose -f docker-compose.sample.yml -f docker-compose.testing.yml run --user="azuracast" --rm web /var/azuracast/www/vendor/bin/codecept run --no-interaction --coverage --coverage-xml --fail-fast after_failure: diff --git a/composer.lock b/composer.lock index 4a935962f..b2db6a4f9 100644 --- a/composer.lock +++ b/composer.lock @@ -198,12 +198,12 @@ "source": { "type": "git", "url": "https://github.com/AzuraCast/nowplaying.git", - "reference": "58d38e04ccd6d1f9f4be7b276f7c7af1b3511bac" + "reference": "9100c1b242264d1ef81bb045b650b5391e7674ee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/AzuraCast/nowplaying/zipball/58d38e04ccd6d1f9f4be7b276f7c7af1b3511bac", - "reference": "58d38e04ccd6d1f9f4be7b276f7c7af1b3511bac", + "url": "https://api.github.com/repos/AzuraCast/nowplaying/zipball/9100c1b242264d1ef81bb045b650b5391e7674ee", + "reference": "9100c1b242264d1ef81bb045b650b5391e7674ee", "shasum": "" }, "require": { @@ -233,7 +233,7 @@ } ], "description": "A lightweight PHP adapter for viewing the current now playing data in Icecast and SHOUTcast 1/2. A part of the AzuraCast software suite.", - "time": "2019-01-17T12:41:09+00:00" + "time": "2019-01-30T19:21:33+00:00" }, { "name": "beberlei/assert", diff --git a/docker.sh b/docker.sh index 625300183..62f100316 100755 --- a/docker.sh +++ b/docker.sh @@ -223,6 +223,7 @@ restore() { } # +# DEVELOPER TOOL: # Access the static console as a developer. # Usage: ./docker.sh static [static_container_command] # @@ -231,6 +232,24 @@ static() { docker-compose -f docker-compose.static.yml run --rm static $* } +# +# DEVELOPER TOOL: +# +# +dev-phpstan() { + docker-compose exec --user="azuracast" web vendor/bin/phpstan analyze $* +} + +# +# DEVELOPER TOOL: +# Run codeception for unit testing. +# +dev-codeception() { + docker-compose -f docker-compose.sample.yml -f docker-compose.testing.yml build web + docker-compose -f docker-compose.sample.yml -f docker-compose.testing.yml run --user="azuracast" --rm web /var/azuracast/www/vendor/bin/codecept run --no-interaction --coverage --coverage-xml --fail-fast +} + + # # Stop all Docker containers and remove related volumes. # Usage: ./docker.sh uninstall diff --git a/phpstan.neon b/phpstan.neon index 0bbf153de..142cf86ec 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,28 +4,7 @@ parameters: paths: - src - ignoreErrors: - # These errors are reported because the gettext extension is not installed/enabled in CLI (see https://github.com/phpstan/phpstan/issues/604) - - '#Function __ not found.#' - - '#Function n__ not found.#' - - # See https://github.com/phpstan/phpstan/issues/768 - - '#Constant APP_IS_COMMAND_LINE not found.#' - - '#Constant APP_TESTING_MODE not found.#' - - '#Constant APP_INCLUDE_ROOT not found.#' - - '#Constant APP_APPLICATION_ENV not found.#' - - '#Constant APP_INSIDE_DOCKER not found.#' - - '#Constant APP_IN_PRODUCTION not found.#' - - '#Constant APP_INCLUDE_TEMP not found.#' - - '#Constant APP_DOCKER_REVISION not found.#' - - # Seems to be a bug that is also present in PHPStorm. We should consider changing the code there - - - message: '#Variable \$key_identifier might not be defined.#' - path: %rootDir%/../../../src/Controller/Frontend/ApiKeysController.php - - - message: '#Variable \$key_verifier might not be defined.#' - path: %rootDir%/../../../src/Controller/Frontend/ApiKeysController.php + bootstrap: %rootDir%/../../../util/phpstan.php includes: - vendor/phpstan/phpstan-doctrine/extension.neon diff --git a/src/Controller/Frontend/ApiKeysController.php b/src/Controller/Frontend/ApiKeysController.php index 0cb078242..8b3d13375 100644 --- a/src/Controller/Frontend/ApiKeysController.php +++ b/src/Controller/Frontend/ApiKeysController.php @@ -69,6 +69,10 @@ class ApiKeysController if ($_POST && $form->isValid($_POST)) { $data = $form->getValues(); + // Setting values here to avoid static analysis errors. + $key_identifier = null; + $key_verifier = null; + if ($new_record) { $record = new Entity\ApiKey($user); list($key_identifier, $key_verifier) = $record->generate(); diff --git a/util/phpstan.php b/util/phpstan.php new file mode 100644 index 000000000..9c7eed706 --- /dev/null +++ b/util/phpstan.php @@ -0,0 +1,22 @@ +register(); + +// Define APP_ constants used by AzuraCast. +define('APP_IS_COMMAND_LINE', true); +define('APP_INCLUDE_ROOT', dirname(__DIR__)); +define('APP_INCLUDE_TEMP', dirname(APP_INCLUDE_ROOT).'/www_tmp'); + +define('APP_INSIDE_DOCKER', true); +define('APP_DOCKER_REVISION', 1); + +define('APP_TESTING_MODE', true); +define('SAMPLE_TIMESTAMP', rand(time() - 86400, time() + 86400)); + +define('APP_APPLICATION_ENV', 'testing'); +define('APP_IN_PRODUCTION', false);