MessageMask::getHtmlBody()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 6
c 2
b 1
f 0
dl 0
loc 10
rs 10
cc 4
nc 3
nop 0
1
<?php
2
/*
3
* File: MessageMask.php
4
* Category: Mask
5
* Author: M.Goldenbaum
6
* Created: 14.03.19 20:49
7
* Updated: -
8
*
9
* Description:
10
*  -
11
*/
12
13
namespace Webklex\PHPIMAP\Support\Masks;
14
15
use Webklex\PHPIMAP\Attachment;
16
use Webklex\PHPIMAP\Message;
17
18
/**
19
 * Class MessageMask
20
 *
21
 * @package Webklex\PHPIMAP\Support\Masks
22
 */
23
class MessageMask extends Mask {
24
25
    /** @var Message $parent */
26
    protected $parent;
27
28
    /**
29
     * Get the message html body
30
     *
31
     * @return null
32
     */
33
    public function getHtmlBody(){
34
        $bodies = $this->parent->getBodies();
35
        if (!isset($bodies['html'])) {
36
            return null;
37
        }
38
39
        if(is_object($bodies['html']) && property_exists($bodies['html'], 'content')) {
40
            return $bodies['html']->content;
41
        }
42
        return $bodies['html'];
43
    }
44
45
    /**
46
     * Get the Message html body filtered by an optional callback
47
     * @param callable|bool $callback
48
     *
49
     * @return string|null
50
     */
51
    public function getCustomHTMLBody($callback = false) {
52
        $body = $this->getHtmlBody();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $body is correct as $this->getHtmlBody() targeting Webklex\PHPIMAP\Support\...sageMask::getHtmlBody() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
53
        if($body === null) return null;
0 ignored issues
show
introduced by
The condition $body === null is always true.
Loading history...
54
55
        if ($callback !== false) {
56
            $aAttachment = $this->parent->getAttachments();
57
            $aAttachment->each(function($oAttachment) use(&$body, $callback) {
58
                /** @var Attachment $oAttachment */
59
                if(is_callable($callback)) {
60
                    $body = $callback($body, $oAttachment);
61
                }elseif(is_string($callback)) {
62
                    call_user_func($callback, [$body, $oAttachment]);
63
                }
64
            });
65
        }
66
67
        return $body;
68
    }
69
70
    /**
71
     * Get the Message html body with embedded base64 images
72
     * the resulting $body.
73
     *
74
     * @return string|null
75
     */
76
    public function getHTMLBodyWithEmbeddedBase64Images() {
77
        return $this->getCustomHTMLBody(function($body, $oAttachment){
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getCustomHTMLBody...ion(...) { /* ... */ }) targeting Webklex\PHPIMAP\Support\...sk::getCustomHTMLBody() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
78
            /** @var Attachment $oAttachment */
79
            if ($oAttachment->id) {
80
                $body = str_replace('cid:'.$oAttachment->id, 'data:'.$oAttachment->getContentType().';base64, '.base64_encode($oAttachment->getContent()), $body);
81
            }
82
83
            return $body;
84
        });
85
    }
86
}