From cd872fbda2dd9f6c213ad9f89cb5ef14fd22b160 Mon Sep 17 00:00:00 2001 From: Tomasz Kowalczyk Date: Tue, 6 Aug 2024 13:58:45 +0200 Subject: [PATCH 1/4] feat: [DPMMA-2707] Update to PHP 8.1 --- .ddev/config.yaml | 11 ++++ .gitignore | 2 + README.md | 8 ++- composer.json | 10 ++-- rector.php | 22 ++++++++ src/Cookie.php | 60 ++++++---------------- src/HttpHeader.php | 47 +++++------------ src/Mautic.php | 97 ++++++++---------------------------- src/Mautic/Config.php | 18 +++---- src/Mautic/Contact.php | 94 ++++++++-------------------------- src/Mautic/Cookie.php | 56 ++++++--------------- src/Mautic/Form.php | 68 ++++++------------------- tests/CookieTest.php | 16 +++--- tests/HttpHeaderTest.php | 22 ++++---- tests/Mautic/ContactTest.php | 30 ++++++----- tests/Mautic/CookieTest.php | 11 ++-- tests/Mautic/FormTest.php | 33 ++++++++---- tests/MauticTest.php | 27 +++++----- 18 files changed, 235 insertions(+), 397 deletions(-) create mode 100644 .ddev/config.yaml create mode 100644 rector.php diff --git a/.ddev/config.yaml b/.ddev/config.yaml new file mode 100644 index 0000000..375d22d --- /dev/null +++ b/.ddev/config.yaml @@ -0,0 +1,11 @@ +name: mautic-form-submit +type: php +docroot: "examples/simple-email-form/" +php_version: "8.1" +webserver_type: nginx-fpm +xdebug_enabled: false +additional_hostnames: [] +additional_fqdns: [] +use_dns_when_possible: true +composer_version: "2" +web_environment: [] \ No newline at end of file diff --git a/.gitignore b/.gitignore index 073e37a..61d34c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ build composer.lock vendor +.idea +.phpunit.result.cache \ No newline at end of file diff --git a/README.md b/README.md index 3d7a688..bbf9bb2 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,12 @@ $result = $form->submit(['f_email' => 'john@doe.email']); For working example see the `examples` dir. +## Run project +``` +ddev start +``` +Project url: https://mautic-form-submit.ddev.site/ + ## Testing ``` @@ -58,8 +64,6 @@ composer cs composer phpstan ``` -PHPSTAN must be installed globally (`composer global require phpstan/phpstan-shim`) and will run only on PHP 7+. - ### Current status [Travis](https://travis-ci.org/escopecz/mautic-form-submit) diff --git a/composer.json b/composer.json index bb6b31c..2dc77c1 100644 --- a/composer.json +++ b/composer.json @@ -15,13 +15,15 @@ } ], "require": { - "php": ">=5.6.0", + "php": ">=8.1", "ext-curl": "*" }, "require-dev": { - "phpunit/phpunit" : "^5.7", - "scrutinizer/ocular": "~1.1", - "squizlabs/php_codesniffer": "~2.3" + "phpunit/phpunit" : "^10.5", + "scrutinizer/ocular": "~1.9", + "squizlabs/php_codesniffer": "^3.10", + "rector/rector": "^1.2", + "phpstan/phpstan": "^1.11" }, "autoload": { "psr-4": { diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..ab965d8 --- /dev/null +++ b/rector.php @@ -0,0 +1,22 @@ +paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_81, + SetList::DEAD_CODE, + SetList::CODE_QUALITY, + SetList::NAMING, + SetList::TYPE_DECLARATION, + ]); +}; \ No newline at end of file diff --git a/src/Cookie.php b/src/Cookie.php index b8a2c90..3757738 100644 --- a/src/Cookie.php +++ b/src/Cookie.php @@ -1,5 +1,7 @@ store[$key])) { - return filter_var($this->store[$key], FILTER_SANITIZE_STRING); + return filter_var($this->store[$key], FILTER_SANITIZE_SPECIAL_CHARS); } - return filter_input(INPUT_COOKIE, $key, FILTER_SANITIZE_STRING); + return filter_input(INPUT_COOKIE, $key, FILTER_SANITIZE_SPECIAL_CHARS); } /** * Get cookie with FILTER_SANITIZE_NUMBER_INT - * - * @param string $key - * - * @return int|null */ - public function getInt($key) + public function getInt(string $key): int { if (isset($this->store[$key])) { return (int) filter_var($this->store[$key], FILTER_SANITIZE_NUMBER_INT); @@ -49,63 +41,39 @@ public function getInt($key) return (int) filter_input(INPUT_COOKIE, $key, FILTER_SANITIZE_NUMBER_INT); } - /** - * Set a cookie value - * - * @param string $key - * @param mixed $value - * - * @return bool - */ - public function set($key, $value) + public function set(string $key, mixed $value): bool { $this->store[$key] = $value; - return setcookie($key, $value); + return setcookie($key, (string) $value); } - /** - * Unset the key from the cookie - * - * @param string $key - * - * @return Cookie - */ - public function clear($key) + public function clear(string $key): static { - setcookie($key, '', time() - 3600); + setcookie($key, '', ['expires' => time() - 3600]); unset($_COOKIE[$key]); unset($this->store[$key]); return $this; } - /** - * Returns $_COOKIE - * - * @return array - */ - public function getSuperGlobalCookie() + public function getSuperGlobalCookie(): array { return $_COOKIE; } /** * Return all cookies as array merged with current state - * - * @return array */ - public function toArray() + public function toArray(): array { return array_merge($this->getSuperGlobalCookie(), $this->store); } /** * Creates unique cookie file in system tmp dir and returns absolute path to it. - * - * @return string|false */ - public function createCookieFile() + public function createCookieFile(): string|false { return tempnam(sys_get_temp_dir(), 'mauticcookie'); } diff --git a/src/HttpHeader.php b/src/HttpHeader.php index d5fcf92..71491a1 100644 --- a/src/HttpHeader.php +++ b/src/HttpHeader.php @@ -1,67 +1,44 @@ parse($textHeaders); } - /** - * @param string $key - * - * @return string|null - */ - public function getHeaderValue($key) + public function getHeaderValue(string $key): ?string { - return isset($this->headers[$key]) ? $this->headers[$key] : null; + return $this->headers[$key] ?? null; } - /** - * @param string $key - * - * @return string|null - */ - public function getCookieValue($key) + public function getCookieValue(?string $key): ?string { - return isset($this->cookies[$key]) ? $this->cookies[$key] : null; + return $this->cookies[$key] ?? null; } /** * Parse text headers and fills in cookies and headers properites - * - * @param string $headers */ - private function parse($headers) + private function parse(string $headers): void { foreach (preg_split('/\r\n|\r|\n/', $headers) as $i => $line) { if ($i === 0) { $this->headers['http_code'] = $line; } else { - list($key, $value) = explode(': ', $line); + [$key, $value] = explode(': ', $line); if ($key === 'Set-Cookie') { - list($textCookie) = explode(';', $value); - list($cookieKey, $cookieValue) = explode('=', $textCookie); + [$textCookie] = explode(';', $value); + [$cookieKey, $cookieValue] = explode('=', $textCookie); $this->cookies[$cookieKey] = $cookieValue; } else { diff --git a/src/Mautic.php b/src/Mautic.php index 80fe242..dc80fc5 100644 --- a/src/Mautic.php +++ b/src/Mautic.php @@ -1,5 +1,7 @@ baseUrl = rtrim(trim($baseUrl), '/'); $this->cookie = new MauticCookie; @@ -53,68 +30,34 @@ public function __construct($baseUrl, Config $config = null) $this->config = $config ?: new Config; } - /** - * Returns Mautic's base URL - * - * @return string - */ - public function getBaseUrl() + public function getBaseUrl(): string { return $this->baseUrl; } - /** - * Returns new Mautic Form representation object - * - * @param int $id - * - * @return Form - */ - public function getForm($id) + public function getForm(int $id): Form { return new Form($this, $id); } - /** - * Sets the Mautic Contact if you want to replace the default one - * - * @param Contact $contact - * - * @return Mautic - */ - public function setContact(Contact $contact) + public function setContact(Contact $contact): static { $this->contact = $contact; return $this; } - /** - * Returns Mautic Contact representation object - * - * @return Contact - */ - public function getContact() + public function getContact(): Contact { return $this->contact; } - /** - * Returns Mautic Cookie representation object - * - * @return MauticCookie - */ - public function getCookie() + public function getCookie(): MauticCookie { return $this->cookie; } - /** - * Returns Mautic Configuration representation object - * - * @return Config - */ - public function getConfig() + public function getConfig(): Config { return $this->config; } diff --git a/src/Mautic/Config.php b/src/Mautic/Config.php index 3b038af..bd42273 100644 --- a/src/Mautic/Config.php +++ b/src/Mautic/Config.php @@ -1,5 +1,7 @@ curlVerbose; } - + /** * Set Curl verbose logging option - * - * @param bool $curlVerbose - * - * @return Config */ - public function setCurlVerbose($curlVerbose) + public function setCurlVerbose(bool $curlVerbose): static { $this->curlVerbose = $curlVerbose; diff --git a/src/Mautic/Contact.php b/src/Mautic/Contact.php index 35f6ace..037974a 100644 --- a/src/Mautic/Contact.php +++ b/src/Mautic/Contact.php @@ -1,117 +1,67 @@ cookie = $cookie; + public function __construct( + protected Cookie $cookie + ) { $this->ip = $this->getIpFromServer(); } /** * Returns Contact ID - * - * @return int */ - public function getId() + public function getId(): int { return (int) $this->cookie->getContactId(); } /** * Set Mautic Contact ID to global cookie - * - * @param int $contactId - * - * @return Contact */ - public function setId($contactId) + public function setId(int $contactId): static { $this->cookie->setContactId($contactId); return $this; } - /** - * Returns Contact IP address - * - * @return string|null - */ - public function getIp() + public function getIp(): ?string { return $this->ip; } - /** - * Sert Contact IP address - * - * @param string $ip - * - * @return Contact - */ - public function setIp($ip) + public function setIp(string $ip): void { $this->ip = $ip; } - /** - * Returns Mautic Contact Session ID - * - * @return string|null - */ - public function getSessionId() + public function getSessionId(): ?string { return $this->cookie->getSessionId(); } - /** - * Set Mautic session ID to global cookie - * - * @param string $sessionId - * - * @return Contact - */ - public function setSessionId($sessionId) + + public function setSessionId(string $sessionId): static { $this->cookie->setSessionId($sessionId); return $this; } - /** - * Set Mautic device ID to global cookie - * - * @param string $deviceId - * - * @return Contact - */ - public function setDeviceId($deviceId) + public function setDeviceId(string $deviceId): static { $this->cookie->setDeviceId($deviceId); @@ -120,10 +70,8 @@ public function setDeviceId($deviceId) /** * Guesses IP address from $_SERVER - * - * @return string */ - public function getIpFromServer() + public function getIpFromServer(): string { $ip = ''; $ipHolders = [ @@ -136,17 +84,17 @@ public function getIpFromServer() 'REMOTE_ADDR' ]; - foreach ($ipHolders as $key) { - if (!empty($_SERVER[$key])) { - $ip = $_SERVER[$key]; - if (strpos($ip, ',') !== false) { + foreach ($ipHolders as $ipHolder) { + if (!empty($_SERVER[$ipHolder])) { + $ip = $_SERVER[$ipHolder]; + if (str_contains((string) $ip, ',')) { // Multiple IPs are present so use the last IP which should be // the most reliable IP that last connected to the proxy - $ips = explode(',', $ip); + $ips = explode(',', (string) $ip); $ips = array_map('trim', $ips); $ip = end($ips); } - $ip = trim($ip); + $ip = trim((string) $ip); break; } } diff --git a/src/Mautic/Cookie.php b/src/Mautic/Cookie.php index db313e8..3dfdeb5 100644 --- a/src/Mautic/Cookie.php +++ b/src/Mautic/Cookie.php @@ -1,5 +1,7 @@ getInt(self::MTC_ID)) { + if (($mtcId = $this->getInt(self::MTC_ID)) !== 0) { return $mtcId; } elseif ($mauticSessionId = $this->getSessionId()) { return $this->getInt($mauticSessionId); @@ -56,12 +48,8 @@ public function getContactId() /** * Set Mautic Contact ID cookies * Note: Call setMauticSessionId prior to this - * - * @param int $contactId - * - * @return Cookie */ - public function setContactId($contactId) + public function setContactId(int $contactId): static { $this->set(self::MTC_ID, $contactId); @@ -73,11 +61,9 @@ public function setContactId($contactId) } /** - * Unet Mautic Contact ID cookies - * - * @return Cookie + * Unit Mautic Contact ID cookies */ - public function unsetContactId() + public function unsetContactId(): static { $this->clear(self::MTC_ID); @@ -90,10 +76,8 @@ public function unsetContactId() /** * Returns Mautic session ID if it exists in the cookie - * - * @return string|null */ - public function getSessionId() + public function getSessionId(): ?string { if ($mauticSessionId = $this->get(self::MAUTIC_SESSION_ID)) { return $mauticSessionId; @@ -108,12 +92,8 @@ public function getSessionId() /** * Set Mautic Session ID cookies - * - * @param string $sessionId - * - * @return Cookie */ - public function setSessionId($sessionId) + public function setSessionId(string $sessionId): static { $this->set(self::MAUTIC_SESSION_ID, $sessionId); $this->set(self::MTC_SID, $sessionId); @@ -123,12 +103,8 @@ public function setSessionId($sessionId) /** * Set Mautic Device ID cookies - * - * @param string $deviceId - * - * @return Cookie */ - public function setDeviceId($deviceId) + public function setDeviceId(string $deviceId): static { $this->set(self::MAUTIC_DEVICE_ID, $deviceId); @@ -137,10 +113,8 @@ public function setDeviceId($deviceId) /** * Unset Mautic Session ID cookies - * - * @return Cookie */ - public function unsetSessionId() + public function unsetSessionId(): static { $this->clear(self::MAUTIC_SESSION_ID); $this->clear(self::MTC_SID); diff --git a/src/Mautic/Form.php b/src/Mautic/Form.php index 35b003a..47c2f66 100644 --- a/src/Mautic/Form.php +++ b/src/Mautic/Form.php @@ -1,51 +1,27 @@ mautic = $mautic; - $this->id = $id; + public function __construct( + protected Mautic $mautic, + protected int $id + ) { } /** * Submit the $data array to the Mautic form, using the optional $curlOpts * array to override curl settings * Returns array containing info about the request, response and cookie - * - * @param array $data - * @param array $curlOpts - * - * @return array */ - public function submit(array $data, array $curlOpts = []) + public function submit(array $data, array $curlOpts = []): array { $originalCookie = $this->mautic->getCookie()->getSuperGlobalCookie(); $request = $this->prepareRequest($data); @@ -107,12 +83,8 @@ public function submit(array $data, array $curlOpts = []) /** * Prepares data for CURL request based on provided form data, $_COOKIE and $_SERVER - * - * @param array $data - * - * @return array */ - public function prepareRequest(array $data) + public function prepareRequest(array $data): array { $contact = $this->mautic->getContact(); $request = ['header' => []]; @@ -152,19 +124,16 @@ public function prepareRequest(array $data) /** * Process the result and split into headers and content - * - * @param string|bool $result - * @return array */ - public function prepareResponse($result) + public function prepareResponse(string|bool $result): array { $response = ['header' => null, 'content' => null]; $d = "\r\n\r\n"; // Headers and content delimiter - if (is_string($result) && strpos($result, $d) !== false) { - list($header, $content) = explode($d, $result, 2); - if (stripos($header, '100 Continue') !== false && strpos($content, $d) !== false) { - list($header, $content) = explode($d, $content, 2); + if (is_string($result) && str_contains($result, $d)) { + [$header, $content] = explode($d, $result, 2); + if (stripos($header, '100 Continue') !== false && str_contains($content, $d)) { + [$header, $content] = explode($d, $content, 2); } $response['header'] = $header; $response['content'] = htmlentities($content); @@ -175,20 +144,13 @@ public function prepareResponse($result) /** * Builds the form URL - * - * @return string */ - public function getUrl() + public function getUrl(): string { return sprintf('%s/form/submit?formId=%d', $this->mautic->getBaseUrl(), $this->id); } - /** - * Returns the Form ID - * - * @return int - */ - public function getId() + public function getId(): int { return $this->id; } diff --git a/tests/CookieTest.php b/tests/CookieTest.php index d6343c6..50901af 100644 --- a/tests/CookieTest.php +++ b/tests/CookieTest.php @@ -1,15 +1,19 @@ assertSame([$key => $val], $cookie->toArray()); } - function test_get_cookie_file() + function test_get_cookie_file(): void { $cookie = new Cookie; $file = $cookie->createCookieFile(); @@ -60,4 +64,4 @@ function test_get_cookie_file() $this->assertTrue(is_writable($file)); $this->assertTrue(unlink($file)); } -} +} \ No newline at end of file diff --git a/tests/HttpHeaderTest.php b/tests/HttpHeaderTest.php index 432288d..b6fae47 100644 --- a/tests/HttpHeaderTest.php +++ b/tests/HttpHeaderTest.php @@ -1,12 +1,16 @@ testTextHeader); - $this->assertEquals('6txmz3mu2dslmkhrera668e', $headerHelper->getCookieValue('mautic_session_id')); - $this->assertEquals('18061', $headerHelper->getCookieValue('mtc_id')); - $this->assertEquals('18061', $headerHelper->getCookieValue('6txmz3mu2dslmkhrera668e')); - $this->assertEquals('Apache/2.4.33 (Unix) OpenSSL/1.0.2o PHP/7.1.16', $headerHelper->getHeaderValue('Server')); + $httpHeader = new HttpHeader($this->testTextHeader); + $this->assertEquals('6txmz3mu2dslmkhrera668e', $httpHeader->getCookieValue('mautic_session_id')); + $this->assertEquals('18061', $httpHeader->getCookieValue('mtc_id')); + $this->assertEquals('18061', $httpHeader->getCookieValue('6txmz3mu2dslmkhrera668e')); + $this->assertEquals('Apache/2.4.33 (Unix) OpenSSL/1.0.2o PHP/7.1.16', $httpHeader->getHeaderValue('Server')); } -} +} \ No newline at end of file diff --git a/tests/Mautic/ContactTest.php b/tests/Mautic/ContactTest.php index c69cdf2..6232143 100644 --- a/tests/Mautic/ContactTest.php +++ b/tests/Mautic/ContactTest.php @@ -1,19 +1,23 @@ baseUrl); $contact = $mautic->getContact(); @@ -26,7 +30,7 @@ function test_get_contact_from_mautic() /** * @runInSeparateProcess */ - function test_set_get_id() + function test_set_get_id(): void { $contactId = 452; $mautic = new Mautic($this->baseUrl); @@ -36,7 +40,7 @@ function test_set_get_id() $this->assertSame($contactId, $contact->getId()); } - function test_set_get_ip() + function test_set_get_ip(): void { $ip = '345.2.2.2'; $mautic = new Mautic($this->baseUrl); @@ -49,7 +53,7 @@ function test_set_get_ip() /** * @runInSeparateProcess */ - function test_get_id_from_mtc_id_cookie() + function test_get_id_from_mtc_id_cookie(): void { $contactId = 4344; $cookie = new Cookie; @@ -63,7 +67,7 @@ function test_get_id_from_mtc_id_cookie() /** * @runInSeparateProcess */ - function test_get_id_from_mautic_session_id_cookie() + function test_get_id_from_mautic_session_id_cookie(): void { $contactId = 4344; $sessionId = 'slk3jhkn3gkn23lkgn3lkgn'; @@ -77,7 +81,7 @@ function test_get_id_from_mautic_session_id_cookie() ->unsetContactId(); } - function test_get_ip_from_server() + function test_get_ip_from_server(): void { $contactIp = '345.2.2.2'; $_SERVER['REMOTE_ADDR'] = $contactIp; @@ -87,7 +91,7 @@ function test_get_ip_from_server() unset($_SERVER['REMOTE_ADDR']); } - function test_get_ip_from_server_method() + function test_get_ip_from_server_method(): void { $contact = new Contact(new Cookie); @@ -100,7 +104,7 @@ function test_get_ip_from_server_method() unset($_SERVER['REMOTE_ADDR']); } - function test_get_ip_from_server_method_when_multiple_ips() + function test_get_ip_from_server_method_when_multiple_ips(): void { $contact = new Contact(new Cookie); @@ -116,7 +120,7 @@ function test_get_ip_from_server_method_when_multiple_ips() /** * @runInSeparateProcess */ - function test_set_session_id_to_cookie() + function test_set_session_id_to_cookie(): void { $cookie = new Cookie; $contact = new Contact($cookie); @@ -133,7 +137,7 @@ function test_set_session_id_to_cookie() /** * @runInSeparateProcess */ - function test_set_contact_id_to_cookie() + function test_set_contact_id_to_cookie(): void { $cookie = new Cookie; $contact = new Contact($cookie); @@ -147,4 +151,4 @@ function test_set_contact_id_to_cookie() $this->assertEquals($contactId, $cookie->getContactId()); $cookie->unsetContactId(); } -} +} \ No newline at end of file diff --git a/tests/Mautic/CookieTest.php b/tests/Mautic/CookieTest.php index 9f926f5..16964a9 100644 --- a/tests/Mautic/CookieTest.php +++ b/tests/Mautic/CookieTest.php @@ -1,15 +1,18 @@ baseUrl); $formId = 3434; @@ -18,7 +22,7 @@ function test_get_id_int_standalone() $this->assertSame($formId, $form->getId()); } - function test_get_id_int_in_mautic_object() + function test_get_id_int_in_mautic_object(): void { $mautic = new Mautic($this->baseUrl); $formId = 3434; @@ -27,7 +31,7 @@ function test_get_id_int_in_mautic_object() $this->assertSame($formId, $form->getId()); } - function test_prepare_request() + function test_prepare_request(): void { $mautic = new Mautic($this->baseUrl); $formId = 3434; @@ -50,7 +54,7 @@ function test_prepare_request() /** * @dataProvider response_result_provider */ - function test_prepare_response($result, $expectedHeader, $expectedContentType) + function test_prepare_response($result, $expectedHeader, $expectedContentType): void { $mautic = new Mautic($this->baseUrl); $formId = 3434; @@ -59,10 +63,19 @@ function test_prepare_response($result, $expectedHeader, $expectedContentType) $response = $form->prepareResponse($result); $this->assertSame($expectedHeader, $response['header']); - $this->assertInternalType($expectedContentType, $response['content']); + switch ($expectedContentType) { + case 'string': + $this->assertIsString($response['content']); + break; + case 'null': + $this->assertNull($response['content']); + break; + default: + throw new InvalidArgumentException("Nieznany typ: $expectedContentType"); + } } - function response_result_provider() + static function response_result_provider(): array { $continue = "HTTP/1.1 100 Continue"; $header = "HTTP/1.1 302 Found\r @@ -85,7 +98,7 @@ function response_result_provider() ]; } - function test_get_url() + function test_get_url(): void { $mautic = new Mautic($this->baseUrl); $formId = 3434; @@ -93,4 +106,4 @@ function test_get_url() $this->assertSame($this->baseUrl.'/form/submit?formId='.$formId, $form->getUrl()); } -} +} \ No newline at end of file diff --git a/tests/MauticTest.php b/tests/MauticTest.php index 5c00ca1..89a0285 100644 --- a/tests/MauticTest.php +++ b/tests/MauticTest.php @@ -1,23 +1,26 @@ baseUrl); $this->assertSame($this->baseUrl, $mautic->getBaseUrl()); } - function test_get_form() + function test_get_form(): void { $mautic = new Mautic($this->baseUrl); $formId = 7; @@ -30,7 +33,7 @@ function test_get_form() /** * @runInSeparateProcess */ - function test_get_contact() + function test_get_contact(): void { $mautic = new Mautic($this->baseUrl); $contact = $mautic->getContact(); @@ -43,21 +46,21 @@ function test_get_contact() /** * @runInSeparateProcess */ - function test_get_set_contact() + function test_get_set_contact(): void { $mautic = new Mautic($this->baseUrl); $contactId = 4; $contactIp = '234.3.2.33'; - $contactA = new Contact(new Cookie); - $contactA->setId($contactId) + $contact = new Contact(new Cookie); + $contact->setId($contactId) ->setIp($contactIp); - $mautic->setContact($contactA); + $mautic->setContact($contact); $contactB = $mautic->getContact(); $this->assertInstanceOf(Contact::class, $contactB); - $this->assertSame($contactA->getId(), $contactB->getId()); - $this->assertSame($contactA->getIp(), $contactB->getIp()); + $this->assertSame($contact->getId(), $contactB->getId()); + $this->assertSame($contact->getIp(), $contactB->getIp()); $this->assertSame($contactId, $contactB->getId()); $this->assertSame($contactIp, $contactB->getIp()); } -} +} \ No newline at end of file From 00fa510a3b643d582815e70bb63ffcd6329a4306 Mon Sep 17 00:00:00 2001 From: John Linhart Date: Thu, 29 Aug 2024 14:51:54 +0200 Subject: [PATCH 2/4] Use local phpstan --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2dc77c1..454eb9d 100644 --- a/composer.json +++ b/composer.json @@ -39,6 +39,6 @@ "test": "phpunit", "test-coverage": "phpdbg -qrr vendor/bin/phpunit", "cs": "phpcs --standard=psr2 src/", - "phpstan": "~/.composer/vendor/phpstan/phpstan-shim/phpstan.phar analyse src tests -l 5" + "phpstan": "vendor/bin/phpstan analyse src tests -l 5" } } From fe5e18ca2926739b6e648939452eac0343351a84 Mon Sep 17 00:00:00 2001 From: John Linhart Date: Thu, 29 Aug 2024 14:52:03 +0200 Subject: [PATCH 3/4] Fixing PHPSTAN issues --- tests/Mautic/FormTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Mautic/FormTest.php b/tests/Mautic/FormTest.php index e3b004c..b239b19 100644 --- a/tests/Mautic/FormTest.php +++ b/tests/Mautic/FormTest.php @@ -71,7 +71,7 @@ function test_prepare_response($result, $expectedHeader, $expectedContentType): $this->assertNull($response['content']); break; default: - throw new InvalidArgumentException("Nieznany typ: $expectedContentType"); + throw new \InvalidArgumentException("Nieznany typ: $expectedContentType"); } } From 09bc7cefcc05d1cf368a4dc716752a17b2a4f6fc Mon Sep 17 00:00:00 2001 From: John Linhart Date: Thu, 29 Aug 2024 15:04:06 +0200 Subject: [PATCH 4/4] Adding working CS fixer --- composer.json | 6 +++--- ecs.php | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 ecs.php diff --git a/composer.json b/composer.json index 454eb9d..8561570 100644 --- a/composer.json +++ b/composer.json @@ -21,9 +21,9 @@ "require-dev": { "phpunit/phpunit" : "^10.5", "scrutinizer/ocular": "~1.9", - "squizlabs/php_codesniffer": "^3.10", "rector/rector": "^1.2", - "phpstan/phpstan": "^1.11" + "phpstan/phpstan": "^1.11", + "symplify/easy-coding-standard": "^12.3" }, "autoload": { "psr-4": { @@ -38,7 +38,7 @@ "scripts": { "test": "phpunit", "test-coverage": "phpdbg -qrr vendor/bin/phpunit", - "cs": "phpcs --standard=psr2 src/", + "cs": "vendor/bin/ecs --fix", "phpstan": "vendor/bin/phpstan analyse src tests -l 5" } } diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..c712871 --- /dev/null +++ b/ecs.php @@ -0,0 +1,24 @@ +withPaths([ + __DIR__ . '/examples', + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withRootFiles() + ->withConfiguredRule( + ArraySyntaxFixer::class, + ['syntax' => 'short'] + ) + ->withRules([ + NoUnusedImportsFixer::class, + ListSyntaxFixer::class, + ]);