PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 2.8.16
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v2.8.16
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / vendor / symfony / mime / Test / Constraint / EmailAddressContains.php

EmailAddressContains.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 2.8.16, at vendor/symfony/mime/Test/Constraint/EmailAddressContains.php

75 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Mime\Test\Constraint;
13
14 use PHPUnit\Framework\Constraint\Constraint;
15 use Symfony\Component\Mime\Header\MailboxHeader;
16 use Symfony\Component\Mime\Header\MailboxListHeader;
17 use Symfony\Component\Mime\RawMessage;
18
19 final class EmailAddressContains extends Constraint
20 {
21 private $headerName;
22 private $expectedValue;
23
24 public function __construct(string $headerName, string $expectedValue)
25 {
26 $this->headerName = $headerName;
27 $this->expectedValue = $expectedValue;
28 }
29
30 /**
31 * {@inheritdoc}
32 */
33 public function toString(): string
34 {
35 return sprintf('contains address "%s" with value "%s"', $this->headerName, $this->expectedValue);
36 }
37
38 /**
39 * @param RawMessage $message
40 *
41 * {@inheritdoc}
42 */
43 protected function matches($message): bool
44 {
45 if (RawMessage::class === \get_class($message)) {
46 throw new \LogicException('Unable to test a message address on a RawMessage instance.');
47 }
48
49 $header = $message->getHeaders()->get($this->headerName);
50 if ($header instanceof MailboxHeader) {
51 return $this->expectedValue === $header->getAddress()->getAddress();
52 } elseif ($header instanceof MailboxListHeader) {
53 foreach ($header->getAddresses() as $address) {
54 if ($this->expectedValue === $address->getAddress()) {
55 return true;
56 }
57 }
58
59 return false;
60 }
61
62 throw new \LogicException('Unable to test a message address on a non-address header.');
63 }
64
65 /**
66 * @param RawMessage $message
67 *
68 * {@inheritdoc}
69 */
70 protected function failureDescription($message): string
71 {
72 return sprintf('the Email %s (value is %s)', $this->toString(), $message->getHeaders()->get($this->headerName)->getBodyAsString());
73 }
74 }
75