From f3f769316a3172c274e59fefb0c204932d6bafa6 Mon Sep 17 00:00:00 2001 From: Pavel Dohnal Date: Wed, 20 Mar 2019 16:16:59 +0100 Subject: [PATCH] Upgrade PHPStan level to 5 [MAILPOET-1915] --- RoboFile.php | 2 +- lib/Cron/Workers/SimpleWorker.php | 2 +- lib/DI/ContainerWrapper.php | 6 +++--- lib/Models/Model.php | 12 ++++++------ lib/Newsletter/Renderer/Renderer.php | 2 +- lib/Subscribers/ImportExport/Import/MailChimp.php | 2 +- lib/Util/Security.php | 2 +- lib/Util/Url.php | 2 +- tasks/phpstan/phpstan.neon | 1 + 9 files changed, 16 insertions(+), 15 deletions(-) diff --git a/RoboFile.php b/RoboFile.php index a5f175a458..695f2ba565 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -378,7 +378,7 @@ class RoboFile extends \Robo\Tasks { 'php -d memory_limit=2G '. "$dir/phpstan.phar analyse ". "--configuration $dir/tasks/phpstan/phpstan.neon ". - '--level 4 '. + '--level 5 '. "$dir/lib" ) ->dir(__DIR__ . '/tasks/phpstan') diff --git a/lib/Cron/Workers/SimpleWorker.php b/lib/Cron/Workers/SimpleWorker.php index 85b15eaa92..e8239aaacf 100644 --- a/lib/Cron/Workers/SimpleWorker.php +++ b/lib/Cron/Workers/SimpleWorker.php @@ -116,7 +116,7 @@ abstract class SimpleWorker { $wp = new WPFunctions(); $date = Carbon::createFromTimestamp($wp->currentTime('timestamp')); // Random day of the next week - $date->setISODate($date->format('o'), ((int)$date->format('W')) + 1, mt_rand(1, 7)); + $date->setISODate((int)$date->format('o'), ((int)$date->format('W')) + 1, mt_rand(1, 7)); $date->startOfDay(); return $date; } diff --git a/lib/DI/ContainerWrapper.php b/lib/DI/ContainerWrapper.php index fa84919c1e..4a89145388 100644 --- a/lib/DI/ContainerWrapper.php +++ b/lib/DI/ContainerWrapper.php @@ -8,16 +8,16 @@ use MailPoetVendor\Symfony\Component\DependencyInjection\Container; class ContainerWrapper implements ContainerInterface { - /** @var ContainerInterface */ + /** @var Container */ private $free_container; - /** @var ContainerInterface|null */ + /** @var Container|null */ private $premium_container; /** @var ContainerWrapper|null */ private static $instance; - public function __construct(ContainerInterface $free_container, ContainerInterface $premium_container = null) { + public function __construct(Container $free_container, Container $premium_container = null) { $this->free_container = $free_container; $this->premium_container = $premium_container; } diff --git a/lib/Models/Model.php b/lib/Models/Model.php index 7debd1f898..c7c7c8e2e8 100644 --- a/lib/Models/Model.php +++ b/lib/Models/Model.php @@ -41,12 +41,12 @@ if (!defined('ABSPATH')) exit; * @method $this selectMany(...$values) * @method static static selectMany(...$values) * @method static selectManyExpr($values) - * @method $this rawJoin($table, $constraint, $table_alias, $parameters = array()) - * @method $this innerJoin($table, $constraint, $table_alias=null) - * @method $this join(string $table, string $constraint, $table_alias=null) - * @method $this leftOuterJoin($table, $constraint, $table_alias=null) - * @method $this rightOuterJoin($table, $constraint, $table_alias=null) - * @method $this fullOuterJoin($table, $constraint, $table_alias=null) + * @method $this rawJoin(string $table, string|array $constraint, string $table_alias, array $parameters = array()) + * @method $this innerJoin(string $table, string|array $constraint, string $table_alias=null) + * @method $this join(string $table, string|array $constraint, string $table_alias=null) + * @method $this leftOuterJoin(string $table, string|array $constraint, string $table_alias=null) + * @method $this rightOuterJoin(string $table, string|array $constraint, string $table_alias=null) + * @method $this fullOuterJoin(string $table, string|array $constraint, string $table_alias=null) * @method $this where($column_name, $value=null) * @method static $this where($column_name, $value=null) * @method $this whereEqual($column_name, $value=null) diff --git a/lib/Newsletter/Renderer/Renderer.php b/lib/Newsletter/Renderer/Renderer.php index ae60dfe16c..163e14fe87 100644 --- a/lib/Newsletter/Renderer/Renderer.php +++ b/lib/Newsletter/Renderer/Renderer.php @@ -154,7 +154,7 @@ class Renderer { /** * @param string $template - * @param string $content + * @param string[] $content * @return string|string[]|null */ private function injectContentIntoTemplate($template, $content) { diff --git a/lib/Subscribers/ImportExport/Import/MailChimp.php b/lib/Subscribers/ImportExport/Import/MailChimp.php index 039c4b86fc..63fe931429 100644 --- a/lib/Subscribers/ImportExport/Import/MailChimp.php +++ b/lib/Subscribers/ImportExport/Import/MailChimp.php @@ -87,7 +87,7 @@ class MailChimp { } if (!isset($header_hash)) { $header_hash = md5(implode(',', $header)); - } elseif (md5(implode(',', $header) !== $header_hash)) { + } elseif (md5(implode(',', $header)) !== $header_hash) { return $this->throwException('headers'); } } else { diff --git a/lib/Util/Security.php b/lib/Util/Security.php index ceeffda172..d6c26987c5 100644 --- a/lib/Util/Security.php +++ b/lib/Util/Security.php @@ -15,7 +15,7 @@ class Security { static function generateRandomString($length = 5) { // non-cryptographically strong random generator return substr( - md5(uniqid(mt_rand(), true)), + md5(uniqid((string)mt_rand(), true)), 0, min(max(5, (int)$length), 32) ); diff --git a/lib/Util/Url.php b/lib/Util/Url.php index ac87974bfd..da33ab6504 100644 --- a/lib/Util/Url.php +++ b/lib/Util/Url.php @@ -10,7 +10,7 @@ class Url { // Remove WPFunctions::get()->homeUrl() path from add_query_arg if (isset($home_url['path'])) { - $query_args = str_replace($home_url['path'], null, $query_args); + $query_args = str_replace($home_url['path'], '', $query_args); } return WPFunctions::get()->homeUrl($query_args); diff --git a/tasks/phpstan/phpstan.neon b/tasks/phpstan/phpstan.neon index 985a474c0e..1b61871cfd 100644 --- a/tasks/phpstan/phpstan.neon +++ b/tasks/phpstan/phpstan.neon @@ -6,6 +6,7 @@ parameters: - '#MailPoet\\Premium\\DI\\ContainerConfigurator not found#' # this class is not available when premium is not active - '#Call to an undefined method IdiormResultSet::set()#' - '#Argument of an invalid type pQuery\\IQuery supplied for foreach, only iterables are supported#' + - '#Parameter \#2 \$prefix of function http_build_query expects string, null given.#' reportUnmatchedIgnoredErrors: false dynamicConstantNames: - WP_DEBUG