AbstractPluginCommandExecutor   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 16
c 1
b 0
f 0
dl 0
loc 50
rs 10

3 Methods

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