MimePartAttachmentParser::parse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
declare(strict_types=1);
3
4
namespace AcMailer\Attachment\Parser;
5
6
use AcMailer\Attachment\Helper\AttachmentHelperTrait;
7
use AcMailer\Exception\InvalidAttachmentException;
8
use Zend\Mime;
9
10
class MimePartAttachmentParser implements AttachmentParserInterface
11
{
12
    use AttachmentHelperTrait;
13
14
    /**
15
     * @param string|resource|array|Mime\Part $attachment
16
     * @param string|null $attachmentName
17
     * @return Mime\Part
18
     * @throws InvalidAttachmentException
19
     */
20
    public function parse($attachment, string $attachmentName = null): Mime\Part
21
    {
22
        if (! $attachment instanceof Mime\Part) {
23
            throw InvalidAttachmentException::fromExpectedType(Mime\Part::class);
24
        }
25
26
        return $this->applyNameToPart($attachment, $attachmentName);
27
    }
28
}
29