More minor code fixes, add linting to CI and docker.sh script.

This commit is contained in:
Buster "Silver Eagle" Neece 2019-01-31 14:29:45 -06:00
parent 8a6701403a
commit 7fa44db264
18 changed files with 114 additions and 23 deletions

1
.gitignore vendored
View File

@ -9,6 +9,7 @@ tmp/cache/*---*
.vagrant
.idea
/ubuntu-*-console.log
.phplint-cache
# Local development files.
/src/Controller/Frontend/UtilController.php

7
.phplint.yml Normal file
View File

@ -0,0 +1,7 @@
path: ./
jobs: 10
extensions:
- php
- phtml
exclude:
- vendor

View File

@ -19,17 +19,19 @@ before_install:
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
- alias dc-testing='docker-compose -f docker-compose.sample.yml -f docker-compose.testing.yml'
install:
- echo $TRAVIS_BUILD_DIR
- chmod 777 $TRAVIS_BUILD_DIR/tests/_output/
- cp azuracast.sample.env azuracast.env
- 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 azuracast_install
- dc-testing build web
- dc-testing 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
- dc-testing run --user="azuracast" --rm web /var/azuracast/www/vendor/bin/phplint $*
- dc-testing run --user="azuracast" --rm web /var/azuracast/www/vendor/bin/phpstan analyze
- dc-testing run --user="azuracast" --rm web /var/azuracast/www/vendor/bin/codecept run --no-interaction --coverage --coverage-xml --fail-fast
after_failure:
- cat tests/_output/*.html

View File

@ -53,7 +53,8 @@
"phpstan/phpstan-doctrine": "^0.11.0",
"phpstan/phpstan-strict-rules": "^0.11.0",
"roave/security-advisories": "dev-master",
"squizlabs/php_codesniffer": "3.*"
"squizlabs/php_codesniffer": "3.*",
"overtrue/phplint": "^1.1"
},
"authors": [
{

55
composer.lock generated
View File

@ -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": "ed3da9194aa98af532dd7268cd7f1d98",
"content-hash": "d2ff96e51f34be2fc3034d4beaa4f30f",
"packages": [
{
"name": "aws/aws-sdk-php",
@ -6427,6 +6427,59 @@
],
"time": "2019-01-12T16:31:37+00:00"
},
{
"name": "overtrue/phplint",
"version": "1.1.9",
"source": {
"type": "git",
"url": "https://github.com/overtrue/phplint.git",
"reference": "dab041512195a6bf52401a66b65dc5b19e4d09ea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/overtrue/phplint/zipball/dab041512195a6bf52401a66b65dc5b19e4d09ea",
"reference": "dab041512195a6bf52401a66b65dc5b19e4d09ea",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": ">=5.5.9",
"symfony/console": "^3.2|^4.0",
"symfony/finder": "^3.0|^4.0",
"symfony/process": "^3.0|^4.0",
"symfony/yaml": "^3.0|^4.0"
},
"require-dev": {
"jakub-onderka/php-console-highlighter": "^0.3.2"
},
"bin": [
"bin/phplint"
],
"type": "library",
"autoload": {
"psr-4": {
"Overtrue\\PHPLint\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "overtrue",
"email": "anzhengchao@gmail.com"
}
],
"description": "a php syntax check tool.",
"keywords": [
"check",
"lint",
"phplint",
"syntax"
],
"time": "2019-01-04T12:59:53+00:00"
},
{
"name": "phar-io/manifest",
"version": "1.0.3",

View File

@ -234,7 +234,25 @@ static() {
#
# DEVELOPER TOOL:
# Run the full test suite.
#
dev-tests() {
dev-lint
dev-phpstan
dev-codeception
}
#
# DEVELOPER TOOL:
# Run linter across all PHP code in the app.
#
dev-lint() {
docker-compose exec --user="azuracast" web vendor/bin/phplint $*
}
#
# DEVELOPER TOOL:
# Run PHPStan for static analysis.
#
dev-phpstan() {
docker-compose exec --user="azuracast" web vendor/bin/phpstan analyze $*

View File

@ -6,6 +6,9 @@ parameters:
bootstrap: %rootDir%/../../../util/phpstan.php
doctrine:
repositoryClass: Azura\Doctrine\Repository
universalObjectCratesClasses:
- Azura\Session\NamespaceInterface
- Azura\View
@ -14,6 +17,9 @@ parameters:
# Caused by Symfony Validator (perhaps wrongly) returning the interface.
- '#Cannot cast Symfony\\Component\\Validator\\ConstraintViolationListInterface to string.#'
# Doctrine custom repositories aren't handled by the Doctrine plugin yet.
# - '#Property .* does not accept Azura\\Doctrine\\Repository<.*>.#'
# Supervisor functions that do exist but aren't annotated properly in the connector lib.
- '#Call to an undefined method Supervisor\\Supervisor::reloadConfig().#'
- '#Call to an undefined method Supervisor\\Supervisor::tailProcessLog().#'

View File

@ -14,10 +14,10 @@ class Auth
/** @var UserRepository */
protected $_user_repo;
/** @var User|null */
/** @var User|bool|null */
protected $_user;
/** @var User|null */
/** @var User|bool|null */
protected $_masqueraded_user;
public function __construct(Session $session, UserRepository $user_repo)

View File

@ -51,7 +51,7 @@ class DjAuth extends CommandAbstract
if (!($station instanceof Entity\Station) || !$station->getEnableStreamers()) {
$output->write('false');
return false;
return null;
}
$user = $input->getOption('dj_user');
@ -65,10 +65,10 @@ class DjAuth extends CommandAbstract
if ($adapter instanceof Liquidsoap) {
$response = $adapter->authenticateStreamer($station, $user, $pass);
$output->write($response);
return ($response === 'true');
return null;
}
$output->write('false');
return false;
return null;
}
}

View File

@ -31,7 +31,7 @@ class MigrateConfig extends CommandAbstract
if (!empty($settings['db_password'])) {
$output->writeln('Configuration already set up.');
return false;
return null;
}
}
@ -72,6 +72,6 @@ class MigrateConfig extends CommandAbstract
file_put_contents($env_path, implode("\n", $ini_data));
$output->writeln('Configuration successfully written.');
return 0;
return null;
}
}

View File

@ -44,7 +44,7 @@ class NextSong extends CommandAbstract
if (!($station instanceof Entity\Station)) {
$output->write('false');
return false;
return null;
}
$as_autodj = ($input->getArgument('as_autodj') !== 'false');
@ -56,7 +56,7 @@ class NextSong extends CommandAbstract
if ($adapter instanceof Liquidsoap) {
$output->write($adapter->getNextSong($station, $as_autodj));
return 0;
return null;
}
$output->write('');

View File

@ -51,10 +51,10 @@ class SetSetting extends CommandAbstract
$settings_repo->deleteSetting($setting_key);
$io->success(sprintf('Setting "%s" removed.', $setting_key));
return;
return null;
}
if (substr($setting_value, 0, 1) === '{') {
if (0 === strpos($setting_value, '{')) {
$setting_value = json_decode($setting_value, true);
}

View File

@ -45,7 +45,10 @@ class SettingsController
$this->settings_repo = $settings_repo;
$all_settings = $settings_repo->fetchAll();
$this->api_settings = $this->serializer->denormalize($all_settings, Entity\Api\Admin\Settings::class);
/** @var Entity\Api\Admin\Settings $api_settings */
$api_settings = $this->serializer->denormalize($all_settings, Entity\Api\Admin\Settings::class);
$this->api_settings = $api_settings;
}
/**

View File

@ -193,7 +193,7 @@ class BatchController extends FilesControllerAbstract
$music_files = $this->_getMusicFiles($fs, $files);
$files_found = count($music_files);
$directory_path = $request->getParsedBody()['directory'];
$directory_path = ((array)$request->getParsedBody())['directory'];
$directory_path_full = 'media://'.$directory_path;
foreach ($music_files as $file) {

View File

@ -91,7 +91,7 @@ class OverviewController
$hourly_ranges[] = [$stat['time'], $stat['min'], $stat['max']];
$hourly_averages[] = [$stat['time'], round($stat['value'], 2)];
$hour = date('G', round($stat['time'] / 1000));
$hour = (int)date('G', round($stat['time'] / 1000));
$totals_by_hour[$hour][] = $stat['value'];
}

View File

@ -327,7 +327,7 @@ class StationMedia
$length_min = floor($length / 60);
$length_sec = $length % 60;
$this->length = round($length);
$this->length = (int)round($length);
$this->length_text = $length_min . ':' . str_pad($length_sec, 2, '0', STR_PAD_LEFT);
}

View File

@ -731,6 +731,6 @@ class StationPlaylist
$now = Chronos::now(new \DateTimeZone('UTC'));
}
return $now->format('Hi');
return (int)$now->format('Hi');
}
}

View File

@ -45,7 +45,7 @@ class StationFilesystem extends MountManager
{
$buffer = $this->readStream($from);
if ($buffer === false) {
return false;
throw new \Azura\Exception('Source file could not be read.');
}
$written = $this->putStream($to, $buffer, $config);