Skip to content

Commit 0f9bb9e

Browse files
authored
Merge pull request #22 from tomekkowalczyk/DPMMA-2707_update_php_8.1
feat: [DPMMA-2707] Update to PHP 8.1
2 parents 6b879e1 + 09bc7ce commit 0f9bb9e

19 files changed

+261
-399
lines changed

.ddev/config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: mautic-form-submit
2+
type: php
3+
docroot: "examples/simple-email-form/"
4+
php_version: "8.1"
5+
webserver_type: nginx-fpm
6+
xdebug_enabled: false
7+
additional_hostnames: []
8+
additional_fqdns: []
9+
use_dns_when_possible: true
10+
composer_version: "2"
11+
web_environment: []

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
build
22
composer.lock
33
vendor
4+
.idea
5+
.phpunit.result.cache

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ $result = $form->submit(['f_email' => 'john@doe.email']);
5050

5151
For working example see the `examples` dir.
5252

53+
## Run project
54+
```
55+
ddev start
56+
```
57+
Project url: https://mautic-form-submit.ddev.site/
58+
5359
## Testing
5460

5561
```
@@ -58,8 +64,6 @@ composer cs
5864
composer phpstan
5965
```
6066

61-
PHPSTAN must be installed globally (`composer global require phpstan/phpstan-shim`) and will run only on PHP 7+.
62-
6367
### Current status
6468

6569
[Travis](https://travis-ci.org/escopecz/mautic-form-submit)

composer.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
}
1616
],
1717
"require": {
18-
"php": ">=5.6.0",
18+
"php": ">=8.1",
1919
"ext-curl": "*"
2020
},
2121
"require-dev": {
22-
"phpunit/phpunit" : "^5.7",
23-
"scrutinizer/ocular": "~1.1",
24-
"squizlabs/php_codesniffer": "~2.3"
22+
"phpunit/phpunit" : "^10.5",
23+
"scrutinizer/ocular": "~1.9",
24+
"rector/rector": "^1.2",
25+
"phpstan/phpstan": "^1.11",
26+
"symplify/easy-coding-standard": "^12.3"
2527
},
2628
"autoload": {
2729
"psr-4": {
@@ -36,7 +38,7 @@
3638
"scripts": {
3739
"test": "phpunit",
3840
"test-coverage": "phpdbg -qrr vendor/bin/phpunit",
39-
"cs": "phpcs --standard=psr2 src/",
40-
"phpstan": "~/.composer/vendor/phpstan/phpstan-shim/phpstan.phar analyse src tests -l 5"
41+
"cs": "vendor/bin/ecs --fix",
42+
"phpstan": "vendor/bin/phpstan analyse src tests -l 5"
4143
}
4244
}

ecs.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
6+
use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
7+
use PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer;
8+
use Symplify\EasyCodingStandard\Config\ECSConfig;
9+
10+
return ECSConfig::configure()
11+
->withPaths([
12+
__DIR__ . '/examples',
13+
__DIR__ . '/src',
14+
__DIR__ . '/tests',
15+
])
16+
->withRootFiles()
17+
->withConfiguredRule(
18+
ArraySyntaxFixer::class,
19+
['syntax' => 'short']
20+
)
21+
->withRules([
22+
NoUnusedImportsFixer::class,
23+
ListSyntaxFixer::class,
24+
]);

rector.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Set\ValueObject\LevelSetList;
7+
use Rector\Set\ValueObject\SetList;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->paths([
11+
__DIR__ . '/src',
12+
__DIR__ . '/tests',
13+
]);
14+
15+
$rectorConfig->sets([
16+
LevelSetList::UP_TO_PHP_81,
17+
SetList::DEAD_CODE,
18+
SetList::CODE_QUALITY,
19+
SetList::NAMING,
20+
SetList::TYPE_DECLARATION,
21+
]);
22+
};

src/Cookie.php

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Escopecz\MauticFormSubmit;
46

57
/**
@@ -12,35 +14,25 @@ class Cookie
1214
* because when cookie is set with setCookie
1315
* it's accessible on the next script run only,
1416
* not at the same run.
15-
*
16-
* @var array
1717
*/
18-
protected $store = [];
18+
protected array $store = [];
1919

2020
/**
2121
* Get cookie with FILTER_SANITIZE_STRING
22-
*
23-
* @param string $key
24-
*
25-
* @return string|null
2622
*/
27-
public function get($key)
23+
public function get(string $key): string|false|null
2824
{
2925
if (isset($this->store[$key])) {
30-
return filter_var($this->store[$key], FILTER_SANITIZE_STRING);
26+
return filter_var($this->store[$key], FILTER_SANITIZE_SPECIAL_CHARS);
3127
}
3228

33-
return filter_input(INPUT_COOKIE, $key, FILTER_SANITIZE_STRING);
29+
return filter_input(INPUT_COOKIE, $key, FILTER_SANITIZE_SPECIAL_CHARS);
3430
}
3531

3632
/**
3733
* Get cookie with FILTER_SANITIZE_NUMBER_INT
38-
*
39-
* @param string $key
40-
*
41-
* @return int|null
4234
*/
43-
public function getInt($key)
35+
public function getInt(string $key): int
4436
{
4537
if (isset($this->store[$key])) {
4638
return (int) filter_var($this->store[$key], FILTER_SANITIZE_NUMBER_INT);
@@ -49,63 +41,39 @@ public function getInt($key)
4941
return (int) filter_input(INPUT_COOKIE, $key, FILTER_SANITIZE_NUMBER_INT);
5042
}
5143

52-
/**
53-
* Set a cookie value
54-
*
55-
* @param string $key
56-
* @param mixed $value
57-
*
58-
* @return bool
59-
*/
60-
public function set($key, $value)
44+
public function set(string $key, mixed $value): bool
6145
{
6246
$this->store[$key] = $value;
6347

64-
return setcookie($key, $value);
48+
return setcookie($key, (string) $value);
6549
}
6650

67-
/**
68-
* Unset the key from the cookie
69-
*
70-
* @param string $key
71-
*
72-
* @return Cookie
73-
*/
74-
public function clear($key)
51+
public function clear(string $key): static
7552
{
76-
setcookie($key, '', time() - 3600);
53+
setcookie($key, '', ['expires' => time() - 3600]);
7754
unset($_COOKIE[$key]);
7855
unset($this->store[$key]);
7956

8057
return $this;
8158
}
8259

83-
/**
84-
* Returns $_COOKIE
85-
*
86-
* @return array
87-
*/
88-
public function getSuperGlobalCookie()
60+
public function getSuperGlobalCookie(): array
8961
{
9062
return $_COOKIE;
9163
}
9264

9365
/**
9466
* Return all cookies as array merged with current state
95-
*
96-
* @return array
9767
*/
98-
public function toArray()
68+
public function toArray(): array
9969
{
10070
return array_merge($this->getSuperGlobalCookie(), $this->store);
10171
}
10272

10373
/**
10474
* Creates unique cookie file in system tmp dir and returns absolute path to it.
105-
*
106-
* @return string|false
10775
*/
108-
public function createCookieFile()
76+
public function createCookieFile(): string|false
10977
{
11078
return tempnam(sys_get_temp_dir(), 'mauticcookie');
11179
}

src/HttpHeader.php

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,44 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Escopecz\MauticFormSubmit;
46

5-
/**
6-
* HTTP Header Helper
7-
*/
87
class HttpHeader
98
{
10-
/**
11-
* Key-valye paries of headers
12-
*
13-
* @var array
14-
*/
15-
private $headers = [];
9+
private array $headers = [];
1610

17-
/**
18-
* Key-valye paries of cookies
19-
*
20-
* @var array
21-
*/
22-
private $cookies = [];
11+
private array $cookies = [];
2312

2413
public function __construct($textHeaders)
2514
{
2615
$this->parse($textHeaders);
2716
}
2817

29-
/**
30-
* @param string $key
31-
*
32-
* @return string|null
33-
*/
34-
public function getHeaderValue($key)
18+
public function getHeaderValue(string $key): ?string
3519
{
36-
return isset($this->headers[$key]) ? $this->headers[$key] : null;
20+
return $this->headers[$key] ?? null;
3721
}
3822

39-
/**
40-
* @param string $key
41-
*
42-
* @return string|null
43-
*/
44-
public function getCookieValue($key)
23+
public function getCookieValue(?string $key): ?string
4524
{
46-
return isset($this->cookies[$key]) ? $this->cookies[$key] : null;
25+
return $this->cookies[$key] ?? null;
4726
}
4827

4928
/**
5029
* Parse text headers and fills in cookies and headers properites
51-
*
52-
* @param string $headers
5330
*/
54-
private function parse($headers)
31+
private function parse(string $headers): void
5532
{
5633
foreach (preg_split('/\r\n|\r|\n/', $headers) as $i => $line) {
5734
if ($i === 0) {
5835
$this->headers['http_code'] = $line;
5936
} else {
60-
list($key, $value) = explode(': ', $line);
37+
[$key, $value] = explode(': ', $line);
6138

6239
if ($key === 'Set-Cookie') {
63-
list($textCookie) = explode(';', $value);
64-
list($cookieKey, $cookieValue) = explode('=', $textCookie);
40+
[$textCookie] = explode(';', $value);
41+
[$cookieKey, $cookieValue] = explode('=', $textCookie);
6542

6643
$this->cookies[$cookieKey] = $cookieValue;
6744
} else {

0 commit comments

Comments
 (0)