Skip to content

Commit b13b60e

Browse files
committed
Added laravel/pint as dev dependency and applied PHP style fixes by Pint
1 parent 7b42260 commit b13b60e

11 files changed

Lines changed: 68 additions & 39 deletions

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
/config.private.ini
44
/doc/db-schema.mwb.bak
55
/vendor/
6-
/composer.phar
7-
/composer.lock
6+
composer.phar
7+
composer.lock
8+
.pint.cache.json

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
- Breaking change: Moved sendmail command-line options `-t -i` from Sendmail-wrapper config (`sendmailCmd` in `config.ini`) to the recommended `sendmail_path` configuration in `php.ini` to avoid problems with Symfony Mailer. see [Upgrading](README.md#upgrading) notes for details.
66
- Dropping support for PHP < 7.4
7-
- Cleanup: Added type declaratinos to function arguments, return values
7+
- Cleanup: Added type declaratinos to function arguments, return values.
8+
- Added laravel/pint as dev dependency and applied PHP style fixes by Pint.
89

910
## 1.0.7 (2022-02-27)
1011

app/ConfigLoader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
defined('APP_ROOT')
34
|| define('APP_ROOT', realpath(dirname(__FILE__) . '/..'));
45

app/SendmailThrottle.php

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
require_once 'StdinMailParser.php';
34

45
/**
@@ -71,7 +72,7 @@ public function run(string $username, int $rcptCount): int
7172
$dateUpdated = new DateTime($throttle->updated_ts);
7273
$dateCurrent = new DateTime();
7374
$sameDay = ($dateUpdated->format('Y-m-d') == $dateCurrent->format('Y-m-d'));
74-
if (!$sameDay) {
75+
if (! $sameDay) {
7576
$countCur = 1;
7677
$rcptCur = 1;
7778
} else {
@@ -96,9 +97,9 @@ public function run(string $username, int $rcptCount): int
9697
$stmt = $this->pdo->prepare($sql);
9798
$stmt->bindParam(':countCur', $countCur, PDO::PARAM_INT);
9899
$stmt->bindParam(':countTot', $countTot, PDO::PARAM_INT);
99-
$stmt->bindParam(':rcptCur' , $rcptCur , PDO::PARAM_INT);
100-
$stmt->bindParam(':rcptTot' , $rcptTot , PDO::PARAM_INT);
101-
$stmt->bindParam(':status' , $status , PDO::PARAM_INT);
100+
$stmt->bindParam(':rcptCur', $rcptCur, PDO::PARAM_INT);
101+
$stmt->bindParam(':rcptTot', $rcptTot, PDO::PARAM_INT);
102+
$stmt->bindParam(':status', $status, PDO::PARAM_INT);
102103
$stmt->bindParam(':username', $username);
103104
$stmt->execute();
104105
$id = $throttle->id;
@@ -120,9 +121,9 @@ public function run(string $username, int $rcptCount): int
120121
$stmt = $this->pdo->prepare($sql);
121122
$stmt->bindParam(':username', $username);
122123
$stmt->bindParam(':countMax', $countMax, PDO::PARAM_INT);
123-
$stmt->bindParam(':rcptMax' , $rcptMax , PDO::PARAM_INT);
124-
$stmt->bindParam(':rcptCur' , $rcptCur , PDO::PARAM_INT);
125-
$stmt->bindParam(':rcptTot' , $rcptTot , PDO::PARAM_INT);
124+
$stmt->bindParam(':rcptMax', $rcptMax, PDO::PARAM_INT);
125+
$stmt->bindParam(':rcptCur', $rcptCur, PDO::PARAM_INT);
126+
$stmt->bindParam(':rcptTot', $rcptTot, PDO::PARAM_INT);
126127
$stmt->execute();
127128
$id = $this->pdo->lastInsertId();
128129
}
@@ -159,7 +160,7 @@ public function run(string $username, int $rcptCount): int
159160
$this->conf->global->adminTo,
160161
$this->conf->throttle->adminSubject,
161162
$syslogMsg,
162-
"From: " . $this->conf->global->adminFrom
163+
'From: ' . $this->conf->global->adminFrom
163164
);
164165
}
165166

@@ -197,20 +198,20 @@ protected function logMessage(int $throttleId, string $username, int $rcptCount,
197198
:ccAddr, :bccAddr, :subject, :site, :client, SUBSTRING_INDEX(USER(), '@', -1), :script)";
198199
$stmt = $this->pdo->prepare($sql);
199200
$stmt->bindParam(':throttleId', $throttleId);
200-
$stmt->bindParam(':username' , $username);
201-
$stmt->bindParam(':uid' , $_SERVER['SUDO_UID']);
202-
$stmt->bindParam(':gid' , $_SERVER['SUDO_GID']);
203-
$stmt->bindParam(':rcptCount' , $rcptCount);
204-
$stmt->bindParam(':status' , $status);
205-
$stmt->bindParam(':msgid' , $headerArr['x-meta-msgid']);
206-
$stmt->bindParam(':fromAddr' , $from);
207-
$stmt->bindParam(':toAddr' , $to);
208-
$stmt->bindParam(':ccAddr' , $cc);
209-
$stmt->bindParam(':bccAddr' , $bcc);
210-
$stmt->bindParam(':subject' , $subject);
211-
$stmt->bindParam(':site' , $headerArr['x-meta-site']);
212-
$stmt->bindParam(':client' , $headerArr['x-meta-client']);
213-
$stmt->bindParam(':script' , $headerArr['x-meta-script']);
201+
$stmt->bindParam(':username', $username);
202+
$stmt->bindParam(':uid', $_SERVER['SUDO_UID']);
203+
$stmt->bindParam(':gid', $_SERVER['SUDO_GID']);
204+
$stmt->bindParam(':rcptCount', $rcptCount);
205+
$stmt->bindParam(':status', $status);
206+
$stmt->bindParam(':msgid', $headerArr['x-meta-msgid']);
207+
$stmt->bindParam(':fromAddr', $from);
208+
$stmt->bindParam(':toAddr', $to);
209+
$stmt->bindParam(':ccAddr', $cc);
210+
$stmt->bindParam(':bccAddr', $bcc);
211+
$stmt->bindParam(':subject', $subject);
212+
$stmt->bindParam(':site', $headerArr['x-meta-site']);
213+
$stmt->bindParam(':client', $headerArr['x-meta-client']);
214+
$stmt->bindParam(':script', $headerArr['x-meta-script']);
214215
$stmt->execute();
215216
}
216217
}

app/SendmailWrapper.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
require_once 'StdinMailParser.php';
34
require_once 'SendmailThrottle.php';
45

@@ -31,7 +32,7 @@ public function run(): int
3132
// RFC 2822 (http://www.faqs.org/rfcs/rfc2822.html)
3233
$msgId = sprintf(
3334
'%s.%s@%s',
34-
date("YmdHis"),
35+
date('YmdHis'),
3536
base_convert(mt_rand(), 10, 36),
3637
$defaultHost
3738
);
@@ -60,8 +61,8 @@ public function run(): int
6061
'cc' => @$headerArr['cc'],
6162
'bcc' => @$headerArr['bcc'],
6263
'subject' => @$headerArr['subject'],
63-
'site' => @$_SERVER["HTTP_HOST"],
64-
'client' => @$_SERVER["REMOTE_ADDR"],
64+
'site' => @$_SERVER['HTTP_HOST'],
65+
'client' => @$_SERVER['REMOTE_ADDR'],
6566
'script' => getenv('SCRIPT_FILENAME'),
6667
];
6768

@@ -83,7 +84,7 @@ public function run(): int
8384
'X-Meta-Script' => $messageInfo['script'],
8485
]);
8586
$descriptorSpec = [
86-
0 => ['pipe', 'r']
87+
0 => ['pipe', 'r'],
8788
];
8889
$proc = proc_open($throttleCmd, $descriptorSpec, $pipes);
8990
if (is_resource($proc)) {
@@ -157,7 +158,7 @@ public function run(): int
157158
$data = $this->buildMessage();
158159

159160
// pass email to the original sendmail binary
160-
$h = popen($sendmailCmd, "w");
161+
$h = popen($sendmailCmd, 'w');
161162
fwrite($h, $data);
162163
pclose($h);
163164

app/StdinMailParser.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
require_once 'ConfigLoader.php';
34

45
/**
@@ -34,7 +35,7 @@ abstract class StdinMailParser
3435
'resent-msg-id',
3536
'comments',
3637
'keywords',
37-
'optional-field'
38+
'optional-field',
3839
];
3940

4041
public function __construct()
@@ -50,7 +51,7 @@ public function init()
5051
{
5152
// read STDIN (complete mail message)
5253
$data = '';
53-
while (!feof(STDIN)) {
54+
while (! feof(STDIN)) {
5455
$data .= fread(STDIN, 1024);
5556
}
5657

@@ -80,14 +81,14 @@ public function getParsedHeaderArr(): array
8081
$headerLines = explode(PHP_EOL, $this->header);
8182
$headerArr = [];
8283
foreach ($headerLines as $line) {
83-
@list($key, $value) = explode(":", $line, 2);
84+
@[$key, $value] = explode(':', $line, 2);
8485
if (is_null($value)) {
8586
// avoid 'PHP Notice: Undefined offset: 1' on header line without colon
8687
syslog(LOG_WARNING, sprintf('%s: Could not parse mail header line: %s', __METHOD__, $line));
8788
}
8889
$key = strtolower(trim($key));
8990
$value = trim($value);
90-
if (isset($headerArr[$key]) && !in_array($key, $this->rfc5322MultiHeaders)) {
91+
if (isset($headerArr[$key]) && ! in_array($key, $this->rfc5322MultiHeaders)) {
9192
// workaround for duplicate headers that should not appear
9293
// more than once: simply merge them, comma separated.
9394
// This prevents spammers to tamper with our recipient counting.
@@ -113,14 +114,14 @@ public function buildMessage(array $extraHeaders = null): string
113114
// add all additional headers after the original ones
114115
if ($this->additionalHeaders) {
115116
foreach ($this->additionalHeaders as $name => $value) {
116-
$header .= PHP_EOL . $name . ": " . $value;
117+
$header .= PHP_EOL . $name . ': ' . $value;
117118
}
118119
}
119120

120121
// these are "on-the-fly" headers that are only used temporarily
121122
if ($extraHeaders) {
122123
foreach ($extraHeaders as $name => $value) {
123-
$header .= PHP_EOL . $name . ": " . $value;
124+
$header .= PHP_EOL . $name . ': ' . $value;
124125
}
125126
}
126127

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@
2121
"ext-pdo": "*",
2222
"ext-imap": "*",
2323
"ext-json": "*"
24+
},
25+
"require-dev": {
26+
"laravel/pint": "^1.7"
2427
}
2528
}

pint.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"preset": "laravel",
3+
"rules": {
4+
"braces": false,
5+
"blank_line_before_statement": false,
6+
"class_definition": false,
7+
"binary_operator_spaces": false,
8+
"concat_space": false,
9+
"no_unused_imports": false,
10+
"Laravel/laravel_phpdoc_alignment": false,
11+
"phpdoc_separation": false,
12+
"class_attributes_separation": false,
13+
"modernize_strpos": true,
14+
"no_superfluous_phpdoc_tags": false
15+
},
16+
"exclude": [
17+
"node_modules",
18+
"tmp"
19+
],
20+
"cache-file": ".pint.cache.json"
21+
}

prepend.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
2+
23
// environment variables that should be available in child processes
34
$envVars = [
45
'HTTP_HOST',
56
'SCRIPT_NAME',
67
'SCRIPT_FILENAME',
78
'DOCUMENT_ROOT',
8-
'REMOTE_ADDR'
9+
'REMOTE_ADDR',
910
];
1011

1112
// sanitizing environment variables for Bash ShellShock mitigation

sendmail-throttle.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*
77
* @copyright Copyright (c) Onlime GmbH (https://www.onlime.ch)
88
*/
9-
109
require_once 'app/SendmailThrottle.php';
1110

1211
// extract main parameters

0 commit comments

Comments
 (0)