Create PHPStan bootstrap file, integrate into Travis CI.

This commit is contained in:
Buster "Silver Eagle" Neece 2019-01-30 21:36:07 -06:00
parent a174c3ba5b
commit 91c334ffff
6 changed files with 51 additions and 26 deletions

View File

@ -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:

8
composer.lock generated
View File

@ -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",

View File

@ -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

View File

@ -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

View File

@ -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();

22
util/phpstan.php Normal file
View File

@ -0,0 +1,22 @@
<?php
/**
* PHPStan Bootstrap File
*/
// Register gettext to avoid related errors
$translator = new \Gettext\Translator();
$translator->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);