Skip to content

Commit 68cd209

Browse files
derrabusnicolas-grekas
authored andcommitted
Leverage str_contains/str_starts_with
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent e62115f commit 68cd209

File tree

5 files changed

+9
-8
lines changed

5 files changed

+9
-8
lines changed

Test/TransportFactoryTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testCreate(Dsn $dsn, TransportInterface $transport)
6969
$factory = $this->getFactory();
7070

7171
$this->assertEquals($transport, $factory->create($dsn));
72-
if (false !== strpos('smtp', $dsn->getScheme())) {
72+
if (str_contains('smtp', $dsn->getScheme())) {
7373
$this->assertStringMatchesFormat($dsn->getScheme().'://%S'.$dsn->getHost().'%S', (string) $transport);
7474
}
7575
}

Tests/Transport/Smtp/SmtpTransportTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ public function write(string $bytes, $debug = true): void
166166

167167
$this->commands[] = $bytes;
168168

169-
if (0 === strpos($bytes, 'DATA')) {
169+
if (str_starts_with($bytes, 'DATA')) {
170170
$this->nextResponse = '354 Enter message, ending with "." on a line by itself';
171-
} elseif (0 === strpos($bytes, 'QUIT')) {
171+
} elseif (str_starts_with($bytes, 'QUIT')) {
172172
$this->nextResponse = '221 Goodbye';
173173
} else {
174174
$this->nextResponse = '250 OK';

Transport/SendmailTransport.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ public function __construct(string $command = null, EventDispatcherInterface $di
5050
parent::__construct($dispatcher, $logger);
5151

5252
if (null !== $command) {
53-
if (false === strpos($command, ' -bs') && false === strpos($command, ' -t')) {
53+
if (!str_contains($command, ' -bs') && !str_contains($command, ' -t')) {
5454
throw new \InvalidArgumentException(sprintf('Unsupported sendmail command flags "%s"; must be one of "-bs" or "-t" but can include additional flags.', $command));
5555
}
5656

5757
$this->command = $command;
5858
}
5959

6060
$this->stream = new ProcessStream();
61-
if (false !== strpos($this->command, ' -bs')) {
61+
if (str_contains($this->command, ' -bs')) {
6262
$this->stream->setCommand($this->command);
6363
$this->transport = new SmtpTransport($this->stream, $dispatcher, $logger);
6464
}
@@ -87,13 +87,13 @@ protected function doSend(SentMessage $message): void
8787
$this->getLogger()->debug(sprintf('Email transport "%s" starting', __CLASS__));
8888

8989
$command = $this->command;
90-
if (false === strpos($command, ' -f')) {
90+
if (!str_contains($command, ' -f')) {
9191
$command .= ' -f'.escapeshellarg($message->getEnvelope()->getSender()->getEncodedAddress());
9292
}
9393

9494
$chunks = AbstractStream::replace("\r\n", "\n", $message->toIterable());
9595

96-
if (false === strpos($command, ' -i') && false === strpos($command, ' -oi')) {
96+
if (!str_contains($command, ' -i') && !str_contains($command, ' -oi')) {
9797
$chunks = AbstractStream::replace("\n.", "\n..", $chunks);
9898
}
9999

Transport/Smtp/Stream/AbstractStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static function replace(string $from, string $to, iterable $chunks): \Gen
114114
continue;
115115
}
116116

117-
if (false !== strpos($chunk, $from)) {
117+
if (str_contains($chunk, $from)) {
118118
$chunk = explode($from, $chunk);
119119
$carry = array_pop($chunk);
120120

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"psr/log": "^1|^2|^3",
2222
"symfony/event-dispatcher": "^4.3",
2323
"symfony/mime": "^4.4.21|^5.2.6",
24+
"symfony/polyfill-php80": "^1.16",
2425
"symfony/service-contracts": "^1.1|^2"
2526
},
2627
"require-dev": {

0 commit comments

Comments
 (0)