Completed
Pull Request — master (#51)
by Dominik
03:53
created

Configuration::getRootNode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 8
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
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);
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
        ->end();
73 3
    }
74
75
    /**
76
     * @param TreeBuilder $treeBuilder
77
     * @param $name
78
     */
79 3
    private function getRootNode(TreeBuilder $treeBuilder, $name)
80
    {
81
        // BC layer for symfony/config 4.1 and older
82 3
        if (!\method_exists($treeBuilder, 'getRootNode')) {
83 3
            return $treeBuilder->root($name);
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Config...der\TreeBuilder::root() has been deprecated: since Symfony 4.3, pass the root name to the constructor instead ( Ignorable by Annotation )

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

83
            return /** @scrutinizer ignore-deprecated */ $treeBuilder->root($name);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
84
        }
85
86
        return $treeBuilder->getRootNode();
87
    }
88
}
89