Remove PHPStan level 6 errors from Import
Remove the following errors from Subscribers\ImportExport\Import\MailChimp: (Method|Property|Function) has no (return )?type specified. (Method|Function) has parameter with no type (specified). [MAILPOET-3720]
This commit is contained in:
@@ -20,7 +20,7 @@ class MailChimp {
|
|||||||
private $mapper;
|
private $mapper;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$apiKey
|
string $apiKey
|
||||||
) {
|
) {
|
||||||
$this->apiKey = $this->getAPIKey($apiKey);
|
$this->apiKey = $this->getAPIKey($apiKey);
|
||||||
$this->maxPostSize = (int)Helpers::getMaxPostSize('bytes');
|
$this->maxPostSize = (int)Helpers::getMaxPostSize('bytes');
|
||||||
@@ -58,7 +58,7 @@ class MailChimp {
|
|||||||
return $lists;
|
return $lists;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSubscribers($lists = []): array {
|
public function getSubscribers(array $lists = []): array {
|
||||||
if (!$this->apiKey || !$this->dataCenter) {
|
if (!$this->apiKey || !$this->dataCenter) {
|
||||||
$this->throwException('API');
|
$this->throwException('API');
|
||||||
}
|
}
|
||||||
@@ -111,13 +111,21 @@ class MailChimp {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string|false $apiKey
|
||||||
|
* @return false|string
|
||||||
|
*/
|
||||||
public function getDataCenter($apiKey) {
|
public function getDataCenter($apiKey) {
|
||||||
if (!$apiKey) return false;
|
if (!$apiKey) return false;
|
||||||
$apiKeyParts = explode('-', $apiKey);
|
$apiKeyParts = explode('-', $apiKey);
|
||||||
return end($apiKeyParts);
|
return end($apiKeyParts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAPIKey($apiKey) {
|
/**
|
||||||
|
* @param string $apiKey
|
||||||
|
* @return false|string
|
||||||
|
*/
|
||||||
|
public function getAPIKey(string $apiKey) {
|
||||||
return (preg_match(self::API_KEY_REGEX, $apiKey)) ? $apiKey : false;
|
return (preg_match(self::API_KEY_REGEX, $apiKey)) ? $apiKey : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,7 +23,7 @@ class MailChimpTest extends \MailPoetTest {
|
|||||||
$this->lists = explode(",", (string)getenv('WP_TEST_IMPORT_MAILCHIMP_LISTS'));
|
$this->lists = explode(",", (string)getenv('WP_TEST_IMPORT_MAILCHIMP_LISTS'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function _before() {
|
public function _before(): void {
|
||||||
WPFunctions::set(Stub::make(new WPFunctions, [
|
WPFunctions::set(Stub::make(new WPFunctions, [
|
||||||
'__' => function ($value) {
|
'__' => function ($value) {
|
||||||
return $value;
|
return $value;
|
||||||
@@ -31,7 +31,7 @@ class MailChimpTest extends \MailPoetTest {
|
|||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItCanGetAPIKey() {
|
public function testItCanGetAPIKey(): void {
|
||||||
$validApiKeyFormat = '12345678901234567890123456789012-ab1';
|
$validApiKeyFormat = '12345678901234567890123456789012-ab1';
|
||||||
// key must consist of two parts separated by hyphen
|
// key must consist of two parts separated by hyphen
|
||||||
expect($this->mailchimp->getAPIKey('invalid_api_key_format'))->false();
|
expect($this->mailchimp->getAPIKey('invalid_api_key_format'))->false();
|
||||||
@@ -49,14 +49,14 @@ class MailChimpTest extends \MailPoetTest {
|
|||||||
->equals($validApiKeyFormat);
|
->equals($validApiKeyFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItCanGetDatacenter() {
|
public function testItCanGetDatacenter(): void {
|
||||||
$validApiKeyFormat = '12345678901234567890123456789012-ab1';
|
$validApiKeyFormat = '12345678901234567890123456789012-ab1';
|
||||||
$dataCenter = 'ab1';
|
$dataCenter = 'ab1';
|
||||||
expect($this->mailchimp->getDataCenter($validApiKeyFormat))
|
expect($this->mailchimp->getDataCenter($validApiKeyFormat))
|
||||||
->equals($dataCenter);
|
->equals($dataCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItFailsWithIncorrectAPIKey() {
|
public function testItFailsWithIncorrectAPIKey(): void {
|
||||||
if (getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') $this->markTestSkipped();
|
if (getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') $this->markTestSkipped();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -69,7 +69,7 @@ class MailChimpTest extends \MailPoetTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItCanGetLists() {
|
public function testItCanGetLists(): void {
|
||||||
if (getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') $this->markTestSkipped();
|
if (getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') $this->markTestSkipped();
|
||||||
try {
|
try {
|
||||||
$lists = $this->mailchimp->getLists();
|
$lists = $this->mailchimp->getLists();
|
||||||
@@ -81,7 +81,7 @@ class MailChimpTest extends \MailPoetTest {
|
|||||||
expect($lists[0]['name'])->notEmpty();
|
expect($lists[0]['name'])->notEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItFailsWithIncorrectLists() {
|
public function testItFailsWithIncorrectLists(): void {
|
||||||
if (getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') $this->markTestSkipped();
|
if (getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') $this->markTestSkipped();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -99,7 +99,7 @@ class MailChimpTest extends \MailPoetTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItCanGetSubscribers() {
|
public function testItCanGetSubscribers(): void {
|
||||||
if (getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') $this->markTestSkipped();
|
if (getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') $this->markTestSkipped();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -115,7 +115,7 @@ class MailChimpTest extends \MailPoetTest {
|
|||||||
expect($subscribers['subscribersCount'])->equals(1);
|
expect($subscribers['subscribersCount'])->equals(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItFailsWhenSubscribersDataTooLarge() {
|
public function testItFailsWhenSubscribersDataTooLarge(): void {
|
||||||
if (getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') $this->markTestSkipped();
|
if (getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') $this->markTestSkipped();
|
||||||
$mailchimp = clone($this->mailchimp);
|
$mailchimp = clone($this->mailchimp);
|
||||||
$mailchimp->maxPostSize = 10;
|
$mailchimp->maxPostSize = 10;
|
||||||
@@ -177,7 +177,7 @@ class MailChimpTest extends \MailPoetTest {
|
|||||||
expect($this->mailchimp->isSubscriberAllowed($subscribed))->true();
|
expect($this->mailchimp->isSubscriberAllowed($subscribed))->true();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function _after() {
|
public function _after(): void {
|
||||||
WPFunctions::set(new WPFunctions);
|
WPFunctions::set(new WPFunctions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user