Configuration::addSpamAlertsSection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 13
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 15
ccs 13
cts 13
cp 1
crap 1
rs 9.8333
1
<?php
2
3
namespace Azine\MailgunWebhooksBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
9
/**
10
 * This is the class that validates and merges configuration from your app/config files.
11
 *
12
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
13
 */
14
class Configuration implements ConfigurationInterface
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19 3
    public function getConfigTreeBuilder()
20
    {
21 3
        $treeBuilder = new TreeBuilder(AzineMailgunWebhooksExtension::PREFIX);
0 ignored issues
show
Unused Code introduced by
The call to Symfony\Component\Config...eBuilder::__construct() has too many arguments starting with Azine\MailgunWebhooksBun...bhooksExtension::PREFIX. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
        $treeBuilder = /** @scrutinizer ignore-call */ new TreeBuilder(AzineMailgunWebhooksExtension::PREFIX);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
22 3
        $rootNode = $this->getRootNode($treeBuilder, AzineMailgunWebhooksExtension::PREFIX);
23
24
        $rootNode
25 3
            ->children()
26 3
                ->scalarNode(AzineMailgunWebhooksExtension::API_KEY)->isRequired()->cannotBeEmpty()->info('Your api-key for mailgun => see https://mailgun.com/cp')->end()
27 3
                ->scalarNode(AzineMailgunWebhooksExtension::PUBLIC_API_KEY)->defaultValue('')->info('Your public-api-key for mailgun => see https://mailgun.com/cp')->end()
28 3
                ->scalarNode(AzineMailgunWebhooksExtension::EMAIL_DOMAIN)->defaultValue('')->info('Your email domain configured on Mailgun')->end()
29 3
                ->scalarNode(AzineMailgunWebhooksExtension::WEB_VIEW_ROUTE)->defaultValue('azine_admin_email_dashboard')->info('Route name to use to generate a WebView link in the Mailgun Event List.')->end()
30 3
                ->scalarNode(AzineMailgunWebhooksExtension::WEB_VIEW_TOKEN)->defaultValue(AzineMailgunWebhooksExtension::WEB_VIEW_TOKEN)->info('The name of the header for webview-token.')->end()
31 3
            ->end();
32
33 3
        $this->addSpamAlertsSection($rootNode);
34 3
        $this->addBlacklistCheckSection($rootNode);
35
36 3
        return $treeBuilder;
37
    }
38
39
    /**
40
     * @param ArrayNodeDefinition $node
41
     */
42 3
    private function addSpamAlertsSection(ArrayNodeDefinition $node)
43
    {
44
        $node
45 3
            ->children()
46 3
                ->arrayNode(AzineMailgunWebhooksExtension::SPAM_ALERTS_PREFIX)
47 3
                    ->addDefaultsIfNotSet()
48 3
                    ->canBeUnset()
49 3
                    ->children()
50 3
                        ->booleanNode(AzineMailgunWebhooksExtension::SEND_ENABLED)->defaultFalse()->info('Whether to send email notifications after receiving spam complaints')->end()
51 3
                        ->scalarNode(AzineMailgunWebhooksExtension::SEND_INTERVAL)->defaultValue('60')->info('Interval in minutes between sending of email notifications after receiving spam complaints')->end()
0 ignored issues
show
Bug introduced by
The method scalarNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
                        ->/** @scrutinizer ignore-call */ scalarNode(AzineMailgunWebhooksExtension::SEND_INTERVAL)->defaultValue('60')->info('Interval in minutes between sending of email notifications after receiving spam complaints')->end()
Loading history...
52 3
                        ->scalarNode(AzineMailgunWebhooksExtension::TICKET_ID)->defaultValue('')->info('Mailgun helpdesk ticket ID to request new IP address in case of spam complains')->end()
53 3
                        ->scalarNode(AzineMailgunWebhooksExtension::TICKET_SUBJECT)->defaultValue('IP on spam-list, please fix.')->info('Mailgun HelpDesk ticket subject')->end()
54 3
                        ->scalarNode(AzineMailgunWebhooksExtension::TICKET_MESSAGE)->defaultValue('It looks like my ip is on a spam-list. Please, assign a clean IP to my domain.')->info('Mailgun HelpDesk ticket subject')->end()
55 3
                        ->scalarNode(AzineMailgunWebhooksExtension::ALERTS_RECIPIENT_EMAIL)->defaultValue('')->info('Admin E-Mail to send notification about spam complaints')->end()
56 3
        ->end();
57 3
    }
58
59
    /**
60
     * @param ArrayNodeDefinition $node
61
     */
62 3
    private function addBlacklistCheckSection(ArrayNodeDefinition $node)
63
    {
64
        $node
65 3
            ->children()
66 3
                ->arrayNode(AzineMailgunWebhooksExtension::HETRIXTOOLS_PREFIX)
67 3
                    ->addDefaultsIfNotSet()
68 3
                    ->canBeUnset()
69 3
                    ->children()
70 3
                        ->scalarNode(AzineMailgunWebhooksExtension::BLACKLIST_CHECK_API_KEY)->defaultValue('')->info('Your public-api-key for hetrixtools => see https://hetrixtools.com/')->end()
71 3
                        ->scalarNode(AzineMailgunWebhooksExtension::BLACKLIST_CHECK_IP_URL)->defaultValue('https://api.hetrixtools.com/v2/<API_TOKEN>/blacklist-check/ipv4/<IP_ADDRESS>/')->info('Url for checking if ip is in blacklist => see https://docs.hetrixtools.com/blacklist-check-api/')->end()
72 3
                        ->integerNode(AzineMailgunWebhooksExtension::BLACKLIST_CHECK_IP_REPEAT_NOTIFICATION_DURATION)->defaultValue(0)->info("Number of days to mute the blacklist-notification if the reported blacklists didn't change.")->end()
73 3
        ->end();
74 3
    }
75
76
    /**
77
     * @param TreeBuilder $treeBuilder
78
     * @param $name
79
     */
80 3
    private function getRootNode(TreeBuilder $treeBuilder, $name)
81
    {
82
        // BC layer for symfony/config 4.1 and older
83 3
        if (!\method_exists($treeBuilder, 'getRootNode')) {
84 3
            return $treeBuilder->root($name);
85
        }
86
87
        return $treeBuilder->getRootNode();
88
    }
89
}
90