phpstan update

Better typying
This commit is contained in:
Pierre Rudloff 2020-05-13 22:28:05 +02:00
parent 74db3b9ad0
commit 6adc1df213
17 changed files with 166 additions and 158 deletions

View file

@ -40,7 +40,7 @@ class Config
/**
* youtube-dl parameters.
*
* @var array
* @var string[]
*/
public $params = ['--no-warnings', '--ignore-errors', '--flat-playlist', '--restrict-filenames', '--no-playlist'];
@ -61,7 +61,7 @@ class Config
/**
* List of formats available in advanced conversion mode.
*
* @var array
* @var string[]
*/
public $convertAdvancedFormats = ['mp3', 'avi', 'flv', 'wav'];
@ -125,7 +125,7 @@ class Config
/**
* Generic formats supported by youtube-dl.
*
* @var array
* @var string[]
*/
public $genericFormats = [];
@ -139,7 +139,8 @@ class Config
/**
* Config constructor.
*
* @param array $options Options
* @param mixed[] $options Options
* @throws CaseConverterException
*/
private function __construct(array $options = [])
{
@ -210,7 +211,7 @@ class Config
/**
* Apply the provided options.
*
* @param array $options Options
* @param mixed[] $options Options
*
* @return void
*/
@ -260,12 +261,13 @@ class Config
* Set options from a YAML file.
*
* @param string $file Path to the YAML file
* @return void
* @throws Exception
*/
public static function setFile($file)
{
if (is_file($file)) {
$options = Yaml::parse(file_get_contents($file));
$options = Yaml::parse(strval(file_get_contents($file)));
self::$instance = new self($options);
self::$instance->validateOptions();
} else {
@ -276,8 +278,9 @@ class Config
/**
* Manually set some options.
*
* @param array $options Options (see `config/config.example.yml` for available options)
* @param mixed[] $options Options (see `config/config.example.yml` for available options)
* @param bool $update True to update an existing instance
* @return void
* @throws Exception
*/
public static function setOptions(array $options, $update = true)

View file

@ -104,7 +104,7 @@ class Locale
/**
* Get country information from locale.
*
* @return Country|array|null
* @return Country|Country[]|null
*/
public function getCountry()
{

View file

@ -18,7 +18,7 @@ class LocaleManager
/**
* Supported locales.
*
* @var array
* @var string[]
*/
private $supportedLocales = ['en_US', 'fr_FR', 'zh_CN', 'es_ES', 'pt_BR', 'de_DE', 'ar', 'pl_PL', 'tr_TR'];
@ -111,6 +111,7 @@ class LocaleManager
* Set the current locale.
*
* @param Locale $locale Locale
* @return void
*/
public function setLocale(Locale $locale)
{
@ -121,6 +122,7 @@ class LocaleManager
/**
* Unset the current locale.
* @return void
*/
public function unsetLocale()
{
@ -132,7 +134,7 @@ class LocaleManager
/**
* Smarty "t" block.
*
* @param array $params Block parameters
* @param mixed[] $params Block parameters
* @param string $text Block content
*
* @return string Translated string
@ -151,6 +153,7 @@ class LocaleManager
*
* @param string $string String to translate
*
* @param mixed[] $params
* @return string Translated string
*/
public function t($string, array $params = [])

View file

@ -36,7 +36,7 @@ class LocaleMiddleware
/**
* Test if a locale can be used for the current user.
*
* @param array $proposedLocale Locale array created by AcceptLanguage::parse()
* @param mixed[] $proposedLocale Locale array created by AcceptLanguage::parse()
*
* @return Locale|null Locale if chosen, nothing otherwise
*/

View file

@ -21,7 +21,7 @@ class UglyRouter extends Router
*
* @param ServerRequestInterface $request The current HTTP request object
*
* @return array
* @return mixed[]
*
* @link https://github.com/nikic/FastRoute/blob/master/src/Dispatcher.php
*/
@ -43,13 +43,13 @@ class UglyRouter extends Router
* Build the path for a named route including the base path.
*
* @param string $name Route name
* @param array $data Named argument replacement data
* @param array $queryParams Optional query string parameters
*
* @throws RuntimeException If named route does not exist
* @throws InvalidArgumentException If required data not provided
* @param string[] $data Named argument replacement data
* @param string[] $queryParams Optional query string parameters
*
* @return string
* @throws InvalidArgumentException If required data not provided
*
* @throws RuntimeException If named route does not exist
*/
public function pathFor($name, array $data = [], array $queryParams = [])
{

View file

@ -70,7 +70,7 @@ class Video
/**
* URLs of the video files.
*
* @var array
* @var string[]
*/
private $urls;
@ -105,7 +105,7 @@ class Video
*
* @param string[] $arguments Arguments
*
* @return Process
* @return Process<string>
*/
private static function getProcess(array $arguments)
{
@ -137,13 +137,13 @@ class Video
/**
* Call youtube-dl.
*
* @param array $arguments Arguments
* @param string[] $arguments Arguments
*
* @throws PasswordException If the video is protected by a password and no password was specified
* @return string Result
* @throws Exception If the password is wrong
* @throws Exception If youtube-dl returns an error
*
* @return string Result
* @throws PasswordException If the video is protected by a password and no password was specified
*/
private function callYoutubedl(array $arguments)
{
@ -155,7 +155,7 @@ class Video
$process->run();
if (!$process->isSuccessful()) {
$errorOutput = trim($process->getErrorOutput());
$exitCode = $process->getExitCode();
$exitCode = intval($process->getExitCode());
if ($errorOutput == 'ERROR: This video is protected by a password, use the --video-password option') {
throw new PasswordException($errorOutput, $exitCode);
} elseif (substr($errorOutput, 0, 21) == 'ERROR: Wrong password') {
@ -294,7 +294,7 @@ class Video
/**
* Return arguments used to run rtmp for a specific video.
*
* @return array Arguments
* @return string[] Arguments
*/
private function getRtmpArguments()
{
@ -331,7 +331,7 @@ class Video
/**
* Check if a command runs successfully.
*
* @param array $command Command and arguments
* @param string[] $command Command and arguments
*
* @return bool False if the command returns an error, true otherwise
*/
@ -352,9 +352,9 @@ class Video
* @param string $from Start the conversion at this time
* @param string $to End the conversion at this time
*
* @return Process<string> Process
* @throws Exception If avconv/ffmpeg is missing
*
* @return Process Process
*/
private function getAvconvProcess(
$audioBitrate,
@ -427,10 +427,10 @@ class Video
* @param string $from Start the conversion at this time
* @param string $to End the conversion at this time
*
* @throws Exception If your try to convert an M3U8 video
* @return resource popen stream
* @throws Exception If the popen stream was not created correctly
*
* @return resource popen stream
* @throws Exception If your try to convert an M3U8 video
*/
public function getAudioStream($from = null, $to = null)
{
@ -460,10 +460,10 @@ class Video
/**
* Get video stream from an M3U playlist.
*
* @throws Exception If avconv/ffmpeg is missing
* @return resource popen stream
* @throws Exception If the popen stream was not created correctly
*
* @return resource popen stream
* @throws Exception If avconv/ffmpeg is missing
*/
public function getM3uStream()
{
@ -502,9 +502,9 @@ class Video
/**
* Get an avconv stream to remux audio and video.
*
* @return resource popen stream
* @throws Exception If the popen stream was not created correctly
*
* @return resource popen stream
*/
public function getRemuxStream()
{
@ -539,9 +539,9 @@ class Video
/**
* Get video stream from an RTMP video.
*
* @return resource popen stream
* @throws Exception If the popen stream was not created correctly
*
* @return resource popen stream
*/
public function getRtmpStream()
{
@ -575,10 +575,10 @@ class Video
* @param int $audioBitrate Audio bitrate of the converted file
* @param string $filetype Filetype of the converted file
*
* @throws Exception If your try to convert and M3U8 video
* @return resource popen stream
* @throws Exception If the popen stream was not created correctly
*
* @return resource popen stream
* @throws Exception If your try to convert and M3U8 video
*/
public function getConvertedStream($audioBitrate, $filetype)
{
@ -612,7 +612,7 @@ class Video
/**
* Get a HTTP response containing the video.
*
* @param array $headers HTTP headers of the request
* @param mixed[] $headers HTTP headers of the request
*
* @return ResponseInterface
* @throws EmptyUrlException

View file

@ -29,7 +29,7 @@ class ViewFactory
public static function create(ContainerInterface $container, Request $request = null)
{
if (!isset($request)) {
$request = $container['request'];
$request = $container->get('request');
}
$view = new Smarty(__DIR__ . '/../templates/');
@ -37,9 +37,10 @@ class ViewFactory
$request = $request->withUri($request->getUri()->withScheme('https')->withPort(443));
}
$localeManager = $container['locale'];
/** @var LocaleManager $localeManager */
$localeManager = $container->get('locale');
$smartyPlugins = new SmartyPlugins($container['router'], $request->getUri()->withUserInfo(null));
$smartyPlugins = new SmartyPlugins($container->get('router'), $request->getUri()->withUserInfo(null));
$view->registerPlugin('function', 'path_for', [$smartyPlugins, 'pathFor']);
$view->registerPlugin('function', 'base_url', [$smartyPlugins, 'baseUrl']);
$view->registerPlugin('block', 't', [$localeManager, 'smartyTranslate']);

View file

@ -6,6 +6,8 @@
namespace Alltube\Stream;
use Alltube\Exception\EmptyUrlException;
use Alltube\Exception\PasswordException;
use Alltube\Video;
use Barracuda\ArchiveStream\ZipArchive;
use Psr\Http\Message\StreamInterface;
@ -86,20 +88,21 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
*
* @param string $string The string that is to be written
*
* @return void
* @return int|false
*/
public function write($string)
{
fwrite($this->buffer, $string);
return fwrite($this->buffer, $string);
}
/**
* Get the size of the stream if known.
*
* @return void
* @return int|null
*/
public function getSize()
{
return null;
}
/**
@ -145,7 +148,7 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
/**
* Returns the remaining contents in a string.
*
* @return string
* @return string|false
*/
public function getContents()
{
@ -196,7 +199,7 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
{
$this->rewind();
return $this->getContents();
return strval($this->getContents());
}
/**
@ -238,6 +241,8 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
* @param Video $video Video to stream
*
* @return void
* @throws PasswordException
* @throws EmptyUrlException
*/
protected function startVideoStream(Video $video)
{
@ -248,7 +253,7 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
$this->init_file_stream_transfer(
$video->getFilename(),
$contentLengthHeaders[0]
intval($contentLengthHeaders[0])
);
}

View file

@ -41,7 +41,7 @@ class YoutubeChunkStream implements StreamInterface
*/
public function read($length)
{
$size = $this->response->getHeader('Content-Length')[0];
$size = intval($this->response->getHeader('Content-Length')[0]);
if ($size - $this->tell() < $length) {
// Don't try to read further than the end of the stream.
$length = $size - $this->tell();

View file

@ -6,6 +6,8 @@
namespace Alltube\Stream;
use Alltube\Exception\EmptyUrlException;
use Alltube\Exception\PasswordException;
use Alltube\Video;
use GuzzleHttp\Psr7\AppendStream;
@ -19,6 +21,8 @@ class YoutubeStream extends AppendStream
* YoutubeStream constructor.
*
* @param Video $video Video to stream
* @throws EmptyUrlException
* @throws PasswordException
*/
public function __construct(Video $video)
{
@ -31,7 +35,7 @@ class YoutubeStream extends AppendStream
while ($rangeStart < $contentLenghtHeader[0]) {
$rangeEnd = $rangeStart + $video->downloader_options->http_chunk_size;
if ($rangeEnd >= $contentLenghtHeader[0]) {
$rangeEnd = $contentLenghtHeader[0] - 1;
$rangeEnd = intval($contentLenghtHeader[0]) - 1;
}
$response = $video->getHttpResponse(['Range' => 'bytes=' . $rangeStart . '-' . $rangeEnd]);
$this->addStream(new YoutubeChunkStream($response));

View file

@ -27,7 +27,7 @@
"heroku/heroku-buildpack-php": "^162.0",
"php-mock/php-mock-mockery": "^1.3",
"phpro/grumphp": "^0.17.0",
"phpstan/phpstan": "~0.9.2",
"phpstan/phpstan": "^0.12.25",
"phpunit/phpunit": "^8.4",
"roave/security-advisories": "dev-master",
"smarty-gettext/smarty-gettext": "^1.6",

49
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": "d6b6d55bcc8f884443734ed9e2b3d94f",
"content-hash": "1b8bd0ca72e9fbff0c51280a0c2c3e91",
"packages": [
{
"name": "aura/session",
@ -3820,66 +3820,45 @@
},
{
"name": "phpstan/phpstan",
"version": "0.9.2",
"version": "0.12.25",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "e59541bcc7cac9b35ca54db6365bf377baf4a488"
"reference": "9619551d68b2d4c0d681a8df73f3c847c798ee64"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/e59541bcc7cac9b35ca54db6365bf377baf4a488",
"reference": "e59541bcc7cac9b35ca54db6365bf377baf4a488",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/9619551d68b2d4c0d681a8df73f3c847c798ee64",
"reference": "9619551d68b2d4c0d681a8df73f3c847c798ee64",
"shasum": ""
},
"require": {
"jean85/pretty-package-versions": "^1.0.3",
"nette/bootstrap": "^2.4 || ^3.0",
"nette/di": "^2.4.7 || ^3.0",
"nette/robot-loader": "^3.0.1",
"nette/utils": "^2.4.5 || ^3.0",
"nikic/php-parser": "^3.1",
"php": "~7.0",
"phpstan/phpdoc-parser": "^0.2",
"symfony/console": "~3.2 || ~4.0",
"symfony/finder": "~3.2 || ~4.0"
"php": "^7.1"
},
"require-dev": {
"consistence/coding-standard": "2.2.1",
"ext-gd": "*",
"ext-intl": "*",
"ext-mysqli": "*",
"jakub-onderka/php-parallel-lint": "^0.9.2",
"phing/phing": "^2.16.0",
"phpstan/phpstan-php-parser": "^0.9",
"phpstan/phpstan-phpunit": "^0.9.3",
"phpstan/phpstan-strict-rules": "^0.9",
"phpunit/phpunit": "^6.5.4",
"slevomat/coding-standard": "4.0.0"
"conflict": {
"phpstan/phpstan-shim": "*"
},
"bin": [
"bin/phpstan"
"phpstan",
"phpstan.phar"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.9-dev"
"dev-master": "0.12-dev"
}
},
"autoload": {
"psr-4": {
"PHPStan\\": [
"src/",
"build/PHPStan"
"files": [
"bootstrap.php"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPStan - PHP Static Analysis Tool",
"time": "2018-01-28T13:22:19+00:00"
"time": "2020-05-10T20:36:16+00:00"
},
{
"name": "phpunit/php-code-coverage",

View file

@ -77,7 +77,7 @@ class FrontController extends BaseController
*
* @param Request $request PSR-7 request
* @param Response $response PSR-7 response
* @param array $data Query parameters
* @param string[] $data Query parameters
*
* @return Response
*/

View file

@ -10,6 +10,7 @@ use Alltube\LocaleMiddleware;
use Alltube\UglyRouter;
use Alltube\ViewFactory;
use Slim\App;
use Slim\Container;
use Symfony\Component\Debug\Debug;
if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) {
@ -23,6 +24,8 @@ if (is_file(__DIR__ . '/config/config.yml')) {
// Create app.
$app = new App();
/** @var Container $container */
$container = $app->getContainer();
// Load config.

View file

@ -6,6 +6,7 @@
namespace Alltube\Test;
use Alltube\Controller\BaseController;
use Alltube\Controller\DownloadController;
use Alltube\Controller\FrontController;
use Alltube\LocaleManager;
@ -44,6 +45,7 @@ abstract class ControllerTest extends BaseTest
/**
* Controller instance used in tests.
* @var BaseController
*/
protected $controller;
@ -80,7 +82,7 @@ abstract class ControllerTest extends BaseTest
* Run controller function with custom query parameters and return the result.
*
* @param string $request Controller function to call
* @param array $params Query parameters
* @param mixed[] $params Query parameters
*
* @return Response HTTP response
*/
@ -96,7 +98,7 @@ abstract class ControllerTest extends BaseTest
* Assert that calling controller function with these parameters returns a 200 HTTP response.
*
* @param string $request Controller function to call
* @param array $params Query parameters
* @param mixed[] $params Query parameters
*
* @return void
*/
@ -109,7 +111,7 @@ abstract class ControllerTest extends BaseTest
* Assert that calling controller function with these parameters returns an HTTP redirect.
*
* @param string $request Controller function to call
* @param array $params Query parameters
* @param mixed[] $params Query parameters
*
* @return void
*/
@ -122,7 +124,7 @@ abstract class ControllerTest extends BaseTest
* Assert that calling controller function with these parameters returns an HTTP 500 error.
*
* @param string $request Controller function to call
* @param array $params Query parameters
* @param mixed[] $params Query parameters
*
* @return void
*/
@ -135,7 +137,7 @@ abstract class ControllerTest extends BaseTest
* Assert that calling controller function with these parameters returns an HTTP 400 error.
*
* @param string $request Controller function to call
* @param array $params Query parameters
* @param mixed[] $params Query parameters
*
* @return void
*/

View file

@ -17,6 +17,12 @@ use Slim\Http\Request;
*/
class FrontControllerTest extends ControllerTest
{
/**
* Controller instance used in tests.
* @var FrontController
*/
protected $controller;
/**
* Prepare tests.
* @throws Exception

View file

@ -6,6 +6,7 @@
namespace Alltube\Test;
use Psr\Http\Message\StreamInterface;
use RuntimeException;
/**
@ -15,6 +16,7 @@ abstract class StreamTest extends BaseTest
{
/**
* Stream instance.
* @var StreamInterface
*/
protected $stream;