Fix other phpstan errors in lib

[MAILPOET-3146]
This commit is contained in:
Rostislav Wolny
2020-10-07 10:33:16 +02:00
committed by Veljko V
parent ab9130f845
commit bf7bd6d2d9
4 changed files with 16 additions and 8 deletions

View File

@ -186,20 +186,23 @@ class CronHelper {
throw new \Exception(__('Site URL is unreachable.', 'mailpoet')); throw new \Exception(__('Site URL is unreachable.', 'mailpoet'));
} }
$scheme = ''; $callScheme = '';
if (isset($parsedUrl['scheme']) && ($parsedUrl['scheme'] === 'https')) { if (isset($parsedUrl['scheme']) && ($parsedUrl['scheme'] === 'https')) {
$scheme = 'ssl://'; $callScheme = 'ssl://';
} }
// 1. if site URL does not contain a port, return the URL // 1. if site URL does not contain a port, return the URL
if (!isset($parsedUrl['port']) || empty($parsedUrl['port'])) return $siteUrl; if (!isset($parsedUrl['port']) || empty($parsedUrl['port'])) return $siteUrl;
// 2. if site URL contains valid port, try connecting to it // 2. if site URL contains valid port, try connecting to it
$fp = @fsockopen($scheme . $parsedUrl['host'], $parsedUrl['port'], $errno, $errstr, 1); $urlHost = $parsedUrl['host'] ?? '';
$fp = @fsockopen($callScheme . $urlHost, $parsedUrl['port'], $errno, $errstr, 1);
if ($fp) return $siteUrl; if ($fp) return $siteUrl;
// 3. if connection fails, attempt to connect the standard port derived from URL // 3. if connection fails, attempt to connect the standard port derived from URL
// schema // schema
$port = (strtolower($parsedUrl['scheme']) === 'http') ? 80 : 443; $urlScheme = $parsedUrl['scheme'] ?? '';
$fp = @fsockopen($scheme . $parsedUrl['host'], $port, $errno, $errstr, 1); $port = (strtolower($urlScheme) === 'http') ? 80 : 443;
if ($fp) return sprintf('%s://%s', $parsedUrl['scheme'], $parsedUrl['host']); $fp = @fsockopen($callScheme . $urlHost, $port, $errno, $errstr, 1);
if ($fp) return sprintf('%s://%s', $urlScheme, $urlHost);
// 4. throw an error if all connection attempts failed // 4. throw an error if all connection attempts failed
throw new \Exception(__('Site URL is unreachable.', 'mailpoet')); throw new \Exception(__('Site URL is unreachable.', 'mailpoet'));
} }

View File

@ -36,7 +36,7 @@ class JsonType extends Type {
$value = stream_get_contents($value); $value = stream_get_contents($value);
} }
$value = mb_convert_encoding($value, 'UTF-8', 'UTF-8'); // sanitize invalid utf8 $value = mb_convert_encoding((string)$value, 'UTF-8', 'UTF-8'); // sanitize invalid utf8
$decoded = json_decode($value, true); $decoded = json_decode($value, true);
$this->handleErrors(); $this->handleErrors();
return $decoded; return $decoded;

View File

@ -168,6 +168,7 @@ class Widget extends \WP_Widget {
} }
</script> </script>
<?php <?php
return '';
} }
/** /**

View File

@ -222,6 +222,10 @@ class Model extends \MailPoetVendor\Sudzy\ValidModel {
} }
} }
/**
* @return static
* @phpstan-ignore-next-line Our Model has incompatible return type with parent
*/
public function save() { public function save() {
$this->setTimestamp(); $this->setTimestamp();
$this->newRecord = $this->isNew(); $this->newRecord = $this->isNew();
@ -387,7 +391,7 @@ class Model extends \MailPoetVendor\Sudzy\ValidModel {
public function __set($name, $value) { public function __set($name, $value) {
$name = Helpers::camelCaseToUnderscore($name); $name = Helpers::camelCaseToUnderscore($name);
return parent::__set($name, $value); parent::__set($name, $value);
} }
public function __isset($name) { public function __isset($name) {