Passed
Push — master ( afb8f6...f8ce69 )
by payever
03:32
created

getNewPluginVersionNotificationText()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 14
rs 10
cc 3
nc 3
nop 2
1
<?php
2
/**
3
 * PHP version 5.4 and 7
4
 *
5
 * @package   Payever\Plugins
6
 * @author    Hennadii.Shymanskyi <[email protected]>
7
 * @copyright 2017-2019 payever GmbH
8
 * @license   MIT <https://opensource.org/licenses/MIT>
9
 */
10
11
namespace Payever\ExternalIntegration\Plugins\Command;
12
13
use Payever\ExternalIntegration\Plugins\Http\MessageEntity\PluginCommandEntity;
14
15
abstract class AbstractPluginCommandExecutor implements PluginCommandExecutorInterface
16
{
17
    /**
18
     * @param string $host
19
     *
20
     * @throws \UnexpectedValueException
21
     */
22
    protected function assertApiHostValid($host)
23
    {
24
        if (!filter_var($host, FILTER_VALIDATE_URL)) {
25
            throw new \UnexpectedValueException(sprintf('Command value %s is not a valid URL', $host));
26
        }
27
    }
28
29
    /**
30
     * @param PluginCommandEntity $commandEntity
31
     * @param string $sentenceDelimiter
32
     *
33
     * @return string - Message to show admin (with clickable HTML links)
34
     */
35
    protected function getNewPluginVersionNotificationText(
36
        PluginCommandEntity $commandEntity,
37
        $sentenceDelimiter = '. '
38
    ) {
39
        $pieces = array();
40
        $commandEntity->setMeta('value', $commandEntity->getValue());
41
42
        foreach ($this->getNewPluginVersionMetaTemplates() as $metaName => $template) {
43
            if ($commandEntity->getMeta($metaName)) {
44
                $pieces[] = sprintf($template, $commandEntity->getMeta($metaName));
45
            }
46
        }
47
48
        return implode($sentenceDelimiter, $pieces);
49
    }
50
51
    /**
52
     * Feel free to override this method in your implementation to get customizable messages
53
     *
54
     * @return array|string[]
55
     */
56
    protected function getNewPluginVersionMetaTemplates()
57
    {
58
        return array(
59
            'value' => 'New payever plugin version is available: %s',
60
            'filename' => 'You can download it <a href="%s" target="_blank">here</a>',
61
            'marketplaceLink' => 'You can also find this update <a href="%s" target="_blank">in marketplace</a>',
62
            'releaseNotes' => 'This update includes: %s',
63
            'callToAction' => '%s',
64
        );
65
    }
66
}
67